feat: "server_exists" check

This commit is contained in:
GenZmeY 2020-08-08 06:14:17 +03:00
parent d7502e7cbe
commit 2dbd001d3c
28 changed files with 111 additions and 262 deletions

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<id>..." echo "<id>..."
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: ban list function cmd_main () # $*: ban list
{ {
include "$LibDir/ban.lib" include "$LibDir/ban.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<id>..." echo "<id>..."
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: ban list function cmd_main () # $*: ban list
{ {
include "$LibDir/ban.lib" include "$LibDir/ban.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/ban.lib" include "$LibDir/ban.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/ban.lib" include "$LibDir/ban.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/game.lib" include "$LibDir/game.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<args>...]" echo "[<args>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/game.lib" include "$LibDir/game.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/game.lib" include "$LibDir/game.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/game.lib" include "$LibDir/game.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<name>..." echo "<name>..."
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<message> [<instance>...]" echo "<message> [<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { true ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { true ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/instance.lib" include "$LibDir/instance.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: Instance[s] function cmd_main () # $*: Instance[s]
{ {
include "$LibDir/maprotate.lib" include "$LibDir/maprotate.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<instance>...]" echo "[<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: Instance[s] function cmd_main () # $*: Instance[s]
{ {
include "$LibDir/maprotate.lib" include "$LibDir/maprotate.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<password> [<instance>...]" echo "<password> [<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/password.lib" include "$LibDir/password.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "<password> [<instance>...]" echo "<password> [<instance>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/password.lib" include "$LibDir/password.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<workshop_id>...]" echo "[<workshop_id>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/workshop.lib" include "$LibDir/workshop.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "[<workshop_id>...]" echo "[<workshop_id>...]"
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/workshop.lib" include "$LibDir/workshop.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { false ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/workshop.lib" include "$LibDir/workshop.lib"

View File

@ -19,6 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
cmd_need_superuser () { false ;}
cmd_need_steamuser () { true ;}
cmd_need_installed_server () { false ;}
function cmd_usage () function cmd_usage ()
{ {
echo "" echo ""
@ -34,16 +38,6 @@ function cmd_help ()
echo "TODO: description" echo "TODO: description"
} }
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () function cmd_main ()
{ {
include "$LibDir/workshop.lib" include "$LibDir/workshop.lib"

View File

@ -95,6 +95,11 @@ function is_version () # $1: Arg
echo "$1" | grep -Piqo '^(-v|--version|version)$' echo "$1" | grep -Piqo '^(-v|--version|version)$'
} }
function server_exists ()
{
test -x "$AppBin"
}
function function_exists () # $1: function name function function_exists () # $1: function name
{ {
type "$1" &> /dev/null type "$1" &> /dev/null
@ -194,7 +199,11 @@ elif [[ -d "$GroupPathname" ]]; then
fi fi
else else
if function_exists "cmd_main"; then 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" "$@" run_as_root "${ScriptFullname}${KF2POSTFIX}" "$Group" "$Command" "$@"
elif function_exists "cmd_need_steamuser" && cmd_need_steamuser; then elif function_exists "cmd_need_steamuser" && cmd_need_steamuser; then
run_as_steamuser "${ScriptFullname}${KF2POSTFIX}" "$Group" "$Command" "$@" run_as_steamuser "${ScriptFullname}${KF2POSTFIX}" "$Group" "$Command" "$@"

View File

@ -100,12 +100,6 @@ function game_validate ()
instance_start instance_start
} }
function server_exists ()
{
test -x "$AppBin"
return $?
}
function first_install () function first_install ()
{ {
include /etc/steamcmd/steamcmd.conf include /etc/steamcmd/steamcmd.conf

View File

@ -65,10 +65,6 @@ function instance_add () # $*: InstanceName[s]
if [[ -z "$*" ]]; then if [[ -z "$*" ]]; then
echo "Name of instance[s] must be set" echo "Name of instance[s] must be set"
exit 1 exit 1
elif ! server_exists; then
echo "You must install server first"
echo "Run \"${ScriptName}${KF2POSTFIX} game update\" to install it"
exit 1
fi fi
local MaxGamePort='7777' local MaxGamePort='7777'