diff --git a/lgsm/functions/command_install_init.sh b/lgsm/functions/command_install_init.sh new file mode 100755 index 000000000..a185b3734 --- /dev/null +++ b/lgsm/functions/command_install_init.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +commandname="INITSYSTEM" +commandaction="systemd service file" +functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" +fn_firstcommand_set + +fn_install_systemd() { + file_c=$'[Unit] +Description=LinuxGSM gamename Server +After=network-online.target +Wants=network-online.target + +[Service] +Type=forking +User=whoami +ExecStart=path start +ExecStop=path stop +Restart=no +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target' + file_c=$(printf "$file_c" | sed s/'gamename'/$gamename/g | sed "s|path|$path|g" | sed s/'whoami'/$(whoami)/g) + fn_print_ok_nl "Generated the file contents" + fn_print_information_nl "Enter the password of root:" + su -c "echo \"$file_c\" > /usr/lib/systemd/system/${selfname}-lgsm.service" || return 1 && return 0 +} + +fn_install_systemd +if [ $? -eq 1 ] +then + fn_print_error_nl "su exited with non 0 exit code.. something went wrong"; + fn_script_log_fatal "su exited with non 0 exit code." +else + fn_print_complete_nl "Placed the file in /usr/lib/systemd/system/ as ${selfname}-lgsm.service" + fn_print_information_nl "run \`systemctl enable ${selfname}-lgsm.service\`, to enable the game on boot" + fn_script_log_pass "sucessfullly installed the systemd service file" +fi +core_exit.sh diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh index b02084256..5766c7136 100755 --- a/lgsm/functions/core_functions.sh +++ b/lgsm/functions/core_functions.sh @@ -742,6 +742,11 @@ functionfile="${FUNCNAME[0]}" fn_fetch_function } +command_install_init.sh () { +functionfile="${FUNCNAME[0]}" +fn_fetch_function +} + # Calls code required for legacy servers core_legacy.sh diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index e20b32b57..f0fc925a6 100755 --- a/lgsm/functions/core_getopt.sh +++ b/lgsm/functions/core_getopt.sh @@ -21,6 +21,7 @@ cmd_update_linuxgsm=( "ul;update-lgsm;uf;update-functions" "command_update_linux cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." ) cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." ) cmd_donate=( "do;donate" "command_donate.sh" "Donation options." ) +cmd_install_init=("ii;install-init" "command_install_init.sh" "Puts the service file in the right place") # Console servers only. cmd_console=( "c;console" "command_console.sh" "Access server console." ) cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." ) @@ -130,7 +131,7 @@ if [ "${engine}" == "source" ]||[ "${shortname}" == "rust" ]||[ "${shortname}" = fi ## Installer. -currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" ) +currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" "${cmd_install_init[@]}") ## Developer commands. currentopt+=( "${cmd_dev_debug[@]}" ) diff --git a/linuxgsm.sh b/linuxgsm.sh index 18cd88326..5ea452ab1 100755 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -368,6 +368,7 @@ if [ "${shortname}" == "core" ]; then # LinuxGSM server mode. else + path="$(dirname $(readlink -f $0))/$(basename $0)" core_functions.sh if [ "${shortname}" != "core-dep" ]; then # Load LinuxGSM configs.