From 2dbd001d3c4ce55c1b10a6aed08aca69fa828d6a Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Sat, 8 Aug 2020 06:14:17 +0300 Subject: [PATCH] feat: "server_exists" check --- SOURCES/main/cmdgrp/ban/add | 14 ++++---------- SOURCES/main/cmdgrp/ban/delete | 14 ++++---------- SOURCES/main/cmdgrp/ban/list | 14 ++++---------- SOURCES/main/cmdgrp/ban/sync | 14 ++++---------- SOURCES/main/cmdgrp/game/fix-permissions | 14 ++++---------- SOURCES/main/cmdgrp/game/run | 14 ++++---------- SOURCES/main/cmdgrp/game/update | 14 ++++---------- SOURCES/main/cmdgrp/game/validate | 14 ++++---------- SOURCES/main/cmdgrp/instance/add | 14 ++++---------- SOURCES/main/cmdgrp/instance/chat | 14 ++++---------- SOURCES/main/cmdgrp/instance/delete | 14 ++++---------- SOURCES/main/cmdgrp/instance/disable | 14 ++++---------- SOURCES/main/cmdgrp/instance/enable | 14 ++++---------- SOURCES/main/cmdgrp/instance/list | 14 ++++---------- SOURCES/main/cmdgrp/instance/restart | 14 ++++---------- SOURCES/main/cmdgrp/instance/start | 14 ++++---------- SOURCES/main/cmdgrp/instance/stop | 14 ++++---------- SOURCES/main/cmdgrp/maprotate/load | 14 ++++---------- SOURCES/main/cmdgrp/maprotate/save | 14 ++++---------- SOURCES/main/cmdgrp/password/admin | 14 ++++---------- SOURCES/main/cmdgrp/password/game | 14 ++++---------- SOURCES/main/cmdgrp/workshop/add | 14 ++++---------- SOURCES/main/cmdgrp/workshop/delete | 14 ++++---------- SOURCES/main/cmdgrp/workshop/list | 14 ++++---------- SOURCES/main/cmdgrp/workshop/sync | 14 ++++---------- SOURCES/main/kf2-srv | 11 ++++++++++- SOURCES/main/lib/game.lib | 8 +------- SOURCES/main/lib/instance.lib | 4 ---- 28 files changed, 111 insertions(+), 262 deletions(-) diff --git a/SOURCES/main/cmdgrp/ban/add b/SOURCES/main/cmdgrp/ban/add index f77d652..f4e376c 100644 --- a/SOURCES/main/cmdgrp/ban/add +++ b/SOURCES/main/cmdgrp/ban/add @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "..." @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () # $*: ban list { include "$LibDir/ban.lib" diff --git a/SOURCES/main/cmdgrp/ban/delete b/SOURCES/main/cmdgrp/ban/delete index 9028dc9..b064220 100644 --- a/SOURCES/main/cmdgrp/ban/delete +++ b/SOURCES/main/cmdgrp/ban/delete @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "..." @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () # $*: ban list { include "$LibDir/ban.lib" diff --git a/SOURCES/main/cmdgrp/ban/list b/SOURCES/main/cmdgrp/ban/list index f29c6d5..d0b0d9a 100644 --- a/SOURCES/main/cmdgrp/ban/list +++ b/SOURCES/main/cmdgrp/ban/list @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/ban.lib" diff --git a/SOURCES/main/cmdgrp/ban/sync b/SOURCES/main/cmdgrp/ban/sync index db214ec..be66212 100644 --- a/SOURCES/main/cmdgrp/ban/sync +++ b/SOURCES/main/cmdgrp/ban/sync @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/ban.lib" diff --git a/SOURCES/main/cmdgrp/game/fix-permissions b/SOURCES/main/cmdgrp/game/fix-permissions index 2443891..d533942 100644 --- a/SOURCES/main/cmdgrp/game/fix-permissions +++ b/SOURCES/main/cmdgrp/game/fix-permissions @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/game.lib" diff --git a/SOURCES/main/cmdgrp/game/run b/SOURCES/main/cmdgrp/game/run index e6e8ff0..1822386 100644 --- a/SOURCES/main/cmdgrp/game/run +++ b/SOURCES/main/cmdgrp/game/run @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/game.lib" diff --git a/SOURCES/main/cmdgrp/game/update b/SOURCES/main/cmdgrp/game/update index b7f5572..e6afb0a 100644 --- a/SOURCES/main/cmdgrp/game/update +++ b/SOURCES/main/cmdgrp/game/update @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/game.lib" diff --git a/SOURCES/main/cmdgrp/game/validate b/SOURCES/main/cmdgrp/game/validate index eb527d8..b23f147 100644 --- a/SOURCES/main/cmdgrp/game/validate +++ b/SOURCES/main/cmdgrp/game/validate @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/game.lib" diff --git a/SOURCES/main/cmdgrp/instance/add b/SOURCES/main/cmdgrp/instance/add index a36f027..1b6a2f4 100644 --- a/SOURCES/main/cmdgrp/instance/add +++ b/SOURCES/main/cmdgrp/instance/add @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "..." @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/chat b/SOURCES/main/cmdgrp/instance/chat index ccab197..5178e33 100644 --- a/SOURCES/main/cmdgrp/instance/chat +++ b/SOURCES/main/cmdgrp/instance/chat @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo " [...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/delete b/SOURCES/main/cmdgrp/instance/delete index b1d601d..39f8b9e 100644 --- a/SOURCES/main/cmdgrp/instance/delete +++ b/SOURCES/main/cmdgrp/instance/delete @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/disable b/SOURCES/main/cmdgrp/instance/disable index 6f78b1a..6c91814 100644 --- a/SOURCES/main/cmdgrp/instance/disable +++ b/SOURCES/main/cmdgrp/instance/disable @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/enable b/SOURCES/main/cmdgrp/instance/enable index 5b1af74..bd0d96e 100644 --- a/SOURCES/main/cmdgrp/instance/enable +++ b/SOURCES/main/cmdgrp/instance/enable @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/list b/SOURCES/main/cmdgrp/instance/list index 6b92b18..676ede4 100644 --- a/SOURCES/main/cmdgrp/instance/list +++ b/SOURCES/main/cmdgrp/instance/list @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/restart b/SOURCES/main/cmdgrp/instance/restart index 4b3b3ea..fcc39f8 100644 --- a/SOURCES/main/cmdgrp/instance/restart +++ b/SOURCES/main/cmdgrp/instance/restart @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/start b/SOURCES/main/cmdgrp/instance/start index cea9994..6a0ddba 100644 --- a/SOURCES/main/cmdgrp/instance/start +++ b/SOURCES/main/cmdgrp/instance/start @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/instance/stop b/SOURCES/main/cmdgrp/instance/stop index 2daa058..0d04ebf 100644 --- a/SOURCES/main/cmdgrp/instance/stop +++ b/SOURCES/main/cmdgrp/instance/stop @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { true ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - true -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/instance.lib" diff --git a/SOURCES/main/cmdgrp/maprotate/load b/SOURCES/main/cmdgrp/maprotate/load index 797262a..de02e07 100644 --- a/SOURCES/main/cmdgrp/maprotate/load +++ b/SOURCES/main/cmdgrp/maprotate/load @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () # $*: Instance[s] { include "$LibDir/maprotate.lib" diff --git a/SOURCES/main/cmdgrp/maprotate/save b/SOURCES/main/cmdgrp/maprotate/save index 4183735..7902a60 100644 --- a/SOURCES/main/cmdgrp/maprotate/save +++ b/SOURCES/main/cmdgrp/maprotate/save @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () # $*: Instance[s] { include "$LibDir/maprotate.lib" diff --git a/SOURCES/main/cmdgrp/password/admin b/SOURCES/main/cmdgrp/password/admin index 4d8abaa..e1e59dd 100644 --- a/SOURCES/main/cmdgrp/password/admin +++ b/SOURCES/main/cmdgrp/password/admin @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo " [...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/password.lib" diff --git a/SOURCES/main/cmdgrp/password/game b/SOURCES/main/cmdgrp/password/game index 01db80a..36658ad 100644 --- a/SOURCES/main/cmdgrp/password/game +++ b/SOURCES/main/cmdgrp/password/game @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo " [...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/password.lib" diff --git a/SOURCES/main/cmdgrp/workshop/add b/SOURCES/main/cmdgrp/workshop/add index 97e5f7b..08db0df 100644 --- a/SOURCES/main/cmdgrp/workshop/add +++ b/SOURCES/main/cmdgrp/workshop/add @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/workshop.lib" diff --git a/SOURCES/main/cmdgrp/workshop/delete b/SOURCES/main/cmdgrp/workshop/delete index 5e3d6c3..774568e 100644 --- a/SOURCES/main/cmdgrp/workshop/delete +++ b/SOURCES/main/cmdgrp/workshop/delete @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "[...]" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/workshop.lib" diff --git a/SOURCES/main/cmdgrp/workshop/list b/SOURCES/main/cmdgrp/workshop/list index 7c596de..4e82ca3 100644 --- a/SOURCES/main/cmdgrp/workshop/list +++ b/SOURCES/main/cmdgrp/workshop/list @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - false -} - function cmd_main () { include "$LibDir/workshop.lib" diff --git a/SOURCES/main/cmdgrp/workshop/sync b/SOURCES/main/cmdgrp/workshop/sync index d725b67..072cdcc 100644 --- a/SOURCES/main/cmdgrp/workshop/sync +++ b/SOURCES/main/cmdgrp/workshop/sync @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +cmd_need_superuser () { false ;} +cmd_need_steamuser () { true ;} +cmd_need_installed_server () { false ;} + function cmd_usage () { echo "" @@ -34,16 +38,6 @@ function cmd_help () echo "TODO: description" } -function cmd_need_superuser () -{ - false -} - -function cmd_need_steamuser () -{ - true -} - function cmd_main () { include "$LibDir/workshop.lib" diff --git a/SOURCES/main/kf2-srv b/SOURCES/main/kf2-srv index bfee58d..3783c15 100755 --- a/SOURCES/main/kf2-srv +++ b/SOURCES/main/kf2-srv @@ -95,6 +95,11 @@ function is_version () # $1: Arg echo "$1" | grep -Piqo '^(-v|--version|version)$' } +function server_exists () +{ + test -x "$AppBin" +} + function function_exists () # $1: function name { type "$1" &> /dev/null @@ -194,7 +199,11 @@ elif [[ -d "$GroupPathname" ]]; then fi else if function_exists "cmd_main"; then - if function_exists "cmd_need_superuser" && cmd_need_superuser; then + if function_exists "cmd_need_installed_server" && cmd_need_installed_server && ! server_exists; then + echo "You must install server first" + echo "Run \"${ScriptName}${KF2POSTFIX} game update\" to install it" + exit 1 + elif function_exists "cmd_need_superuser" && cmd_need_superuser; then run_as_root "${ScriptFullname}${KF2POSTFIX}" "$Group" "$Command" "$@" elif function_exists "cmd_need_steamuser" && cmd_need_steamuser; then run_as_steamuser "${ScriptFullname}${KF2POSTFIX}" "$Group" "$Command" "$@" diff --git a/SOURCES/main/lib/game.lib b/SOURCES/main/lib/game.lib index c68091d..68fd5bd 100644 --- a/SOURCES/main/lib/game.lib +++ b/SOURCES/main/lib/game.lib @@ -18,7 +18,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - + function game_fix_permissions () # $*: Instance[s] { local InstanceList="$*" @@ -100,12 +100,6 @@ function game_validate () instance_start } -function server_exists () -{ - test -x "$AppBin" - return $? -} - function first_install () { include /etc/steamcmd/steamcmd.conf diff --git a/SOURCES/main/lib/instance.lib b/SOURCES/main/lib/instance.lib index 136e160..f44e3ca 100644 --- a/SOURCES/main/lib/instance.lib +++ b/SOURCES/main/lib/instance.lib @@ -65,10 +65,6 @@ function instance_add () # $*: InstanceName[s] if [[ -z "$*" ]]; then echo "Name of instance[s] must be set" exit 1 - elif ! server_exists; then - echo "You must install server first" - echo "Run \"${ScriptName}${KF2POSTFIX} game update\" to install it" - exit 1 fi local MaxGamePort='7777'