Skip to content

Commit 5da8985

Browse files
feat: adds a command to place the systemd service file in the right location
1 parent 22a76ce commit 5da8985

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
commandname="INITSYSTEM"
3+
commandaction="systemd service file"
4+
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
5+
fn_firstcommand_set
6+
7+
fn_install_systemd() {
8+
file_c=$'[Unit]
9+
Description=LinuxGSM gamename Server
10+
After=network-online.target
11+
Wants=network-online.target
12+
13+
[Service]
14+
Type=forking
15+
User=whoami
16+
ExecStart=path start
17+
ExecStop=path stop
18+
Restart=no
19+
RemainAfterExit=yes
20+
21+
[Install]
22+
WantedBy=multi-user.target'
23+
file_c=$(printf "$file_c" | sed s/'gamename'/$gamename/g | sed "s|path|$path|g" | sed s/'whoami'/$(whoami)/g)
24+
fn_print_ok_nl "Generated the file contents"
25+
fn_print_information_nl "Enter the password of root:"
26+
su -c "echo \"$file_c\" > /usr/lib/systemd/system/${selfname}-lgsm.service" || return 1 && return 0
27+
}
28+
29+
fn_install_systemd
30+
if [ $? -eq 1 ]
31+
then
32+
fn_print_error_nl "su exited with non 0 exit code.. something went wrong";
33+
fn_script_log_fatal "su exited with non 0 exit code."
34+
else
35+
fn_print_complete_nl "Placed the file in /usr/lib/systemd/system/ as ${selfname}-lgsm.service"
36+
fn_print_information_nl "run \`systemctl enable ${selfname}-lgsm.service\`, to enable the game on boot"
37+
fn_script_log_pass "sucessfullly installed the systemd service file"
38+
fi
39+
core_exit.sh

lgsm/functions/core_functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ functionfile="${FUNCNAME[0]}"
742742
fn_fetch_function
743743
}
744744

745+
command_install_init.sh () {
746+
functionfile="${FUNCNAME[0]}"
747+
fn_fetch_function
748+
}
749+
745750
# Calls code required for legacy servers
746751
core_legacy.sh
747752

lgsm/functions/core_getopt.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cmd_update_linuxgsm=( "ul;update-lgsm;uf;update-functions" "command_update_linux
2121
cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." )
2222
cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." )
2323
cmd_donate=( "do;donate" "command_donate.sh" "Donation options." )
24+
cmd_install_init=("ii;install-init" "command_install_init.sh" "Puts the service file in the right place")
2425
# Console servers only.
2526
cmd_console=( "c;console" "command_console.sh" "Access server console." )
2627
cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." )
@@ -130,7 +131,7 @@ if [ "${engine}" == "source" ]||[ "${shortname}" == "rust" ]||[ "${shortname}" =
130131
fi
131132

132133
## Installer.
133-
currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" )
134+
currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" "${cmd_install_init[@]}")
134135

135136
## Developer commands.
136137
currentopt+=( "${cmd_dev_debug[@]}" )

linuxgsm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ if [ "${shortname}" == "core" ]; then
368368

369369
# LinuxGSM server mode.
370370
else
371+
path="$(dirname $(readlink -f $0))/$(basename $0)"
371372
core_functions.sh
372373
if [ "${shortname}" != "core-dep" ]; then
373374
# Load LinuxGSM configs.

0 commit comments

Comments
 (0)