-
-
Notifications
You must be signed in to change notification settings - Fork 785
/
core_getopt.sh
executable file
·215 lines (188 loc) · 9.16 KB
/
core_getopt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
# LinuxGSM core_getopt.sh module
# Author: Daniel Gibbs
# Contributors: http://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: getopt arguments.
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
### Define all commands here.
## User commands | Trigger commands | Description
# Standard commands.
cmd_install=( "i;install" "command_install.sh" "Install the server." )
cmd_auto_install=( "ai;auto-install" "fn_autoinstall" "Install the server without prompts." )
cmd_start=( "st;start" "command_start.sh" "Start the server." )
cmd_stop=( "sp;stop" "command_stop.sh" "Stop the server." )
cmd_restart=( "r;restart" "command_restart.sh" "Restart the server." )
cmd_details=( "dt;details" "command_details.sh" "Display server information." )
cmd_postdetails=( "pd;postdetails" "command_postdetails.sh" "Post details to termbin.com (removing passwords)." )
cmd_backup=( "b;backup" "command_backup.sh" "Create backup archives of the server." )
cmd_update_linuxgsm=( "ul;update-lgsm;uf;update-functions" "command_update_linuxgsm.sh" "Check and apply any LinuxGSM updates." )
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_skeleton=( "sk;skeleton" "command_skeleton.sh" "Create a skeleton directory." )
cmd_donate=( "do;donate" "command_donate.sh" "Donation options." )
cmd_send=( "sd;send" "command_send.sh" "Send command to game server console." )
# 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." )
# Update servers only.
cmd_update=( "u;update" "command_update.sh" "Check and apply any server updates." )
cmd_check_update=( "cu;check-update" "command_check_update.sh" "Check if a gameserver update is available" )
cmd_force_update=( "fu;force-update;update-restart;ur" "forceupdate=1; command_update.sh" "Apply server updates bypassing check." )
# SteamCMD servers only.
cmd_validate=( "v;validate" "command_validate.sh" "Validate server files with SteamCMD." )
# Server with mods-install.
cmd_mods_install=( "mi;mods-install" "command_mods_install.sh" "View and install available mods/addons." )
cmd_mods_remove=( "mr;mods-remove" "command_mods_remove.sh" "View and remove an installed mod/addon." )
cmd_mods_update=( "mu;mods-update" "command_mods_update.sh" "Update installed mods/addons." )
# Server specific.
cmd_change_password=( "pw;change-password" "command_ts3_server_pass.sh" "Change TS3 serveradmin password." )
cmd_install_default_resources=( "ir;install-default-resources" "command_install_resources_mta.sh" "Install the MTA default resources." )
cmd_serverwipe=( "fw;full-wipe;wa;wipeall" "serverwipe=1; command_wipe.sh" "Reset the map and remove blueprint data." )
cmd_mapwipe=( "mw;map-wipe;w;wipe;wi" "mapwipe=1; command_wipe.sh" "Reset the map and keep blueprint data." )
cmd_map_compressor_u99=( "mc;map-compressor" "compress_ut99_maps.sh" "Compresses all ${gamename} server maps." )
cmd_map_compressor_u2=( "mc;map-compressor" "compress_unreal2_maps.sh" "Compresses all ${gamename} server maps." )
cmd_install_cdkey=( "cd;server-cd-key" "install_ut2k4_key.sh" "Add your server cd key." )
cmd_install_dst_token=( "ct;cluster-token" "install_dst_token.sh" "Configure cluster token." )
cmd_install_squad_license=( "li;license" "install_squad_license.sh" "Add your Squad server license." )
cmd_fastdl=( "fd;fastdl" "command_fastdl.sh" "Build a FastDL directory." )
# Dev commands.
cmd_dev_debug=( "dev;developer" "command_dev_debug.sh" "Enable developer Mode." )
cmd_dev_detect_deps=( "dd;detect-deps" "command_dev_detect_deps.sh" "Detect required dependencies." )
cmd_dev_detect_glibc=( "dg;detect-glibc" "command_dev_detect_glibc.sh" "Detect required glibc." )
cmd_dev_detect_ldd=( "dl;detect-ldd" "command_dev_detect_ldd.sh" "Detect required dynamic dependencies." )
cmd_dev_query_raw=( "qr;query-raw" "command_dev_query_raw.sh" "The raw output of gamedig and gsquery." )
cmd_dev_clear_functions=( "cf;clear-functions" "command_dev_clear_functions.sh" "Delete the contents of the functions dir." )
### Set specific opt here.
currentopt=( "${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" "${cmd_skeleton[@]}" )
# Update LinuxGSM.
currentopt+=( "${cmd_update_linuxgsm[@]}" )
# Exclude noupdate games here.
if [ "${shortname}" == "jk2" ]||[ "${engine}" != "idtech3" ];then
if [ "${shortname}" != "bf1942" ]&&[ "${shortname}" != "bfv" ]&&[ "${engine}" != "idtech2" ]&&[ "${engine}" != "iw2.0" ]&&[ "${engine}" != "iw3.0" ]&&[ "${engine}" != "quake" ]&&[ "${shortname}" != "samp" ]&&[ "${shortname}" != "ut2k4" ]&&[ "${shortname}" != "ut99" ]; then
currentopt+=( "${cmd_update[@]}" )
# force update for SteamCMD or Multi Theft Auto only.
if [ "${appid}" ]||[ "${shortname}" == "mta" ]; then
currentopt+=( "${cmd_force_update[@]}" )
fi
fi
fi
# Validate and check-update command.
if [ "${appid}" ]; then
currentopt+=( "${cmd_validate[@]}" "${cmd_check_update[@]}" )
fi
# Backup.
currentopt+=( "${cmd_backup[@]}" )
# Console & Debug.
currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
# Console send.
if [ "${consoleinteract}" == "yes" ]; then
currentopt+=( "${cmd_send[@]}" )
fi
## Game server exclusive commands.
# FastDL command.
if [ "${engine}" == "source" ]; then
currentopt+=( "${cmd_fastdl[@]}" )
fi
# TeamSpeak exclusive.
if [ "${shortname}" == "ts3" ]; then
currentopt+=( "${cmd_change_password[@]}" )
fi
# Unreal exclusive.
if [ "${shortname}" == "rust" ]; then
currentopt+=( "${cmd_serverwipe[@]}" "${cmd_mapwipe[@]}" )
fi
if [ "${engine}" == "unreal2" ]; then
if [ "${shortname}" == "ut2k4" ]; then
currentopt+=( "${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}" )
else
currentopt+=( "${cmd_map_compressor_u2[@]}" )
fi
fi
if [ "${engine}" == "unreal" ]; then
currentopt+=( "${cmd_map_compressor_u99[@]}" )
fi
# DST exclusive.
if [ "${shortname}" == "dst" ]; then
currentopt+=( "${cmd_install_dst_token[@]}" )
fi
# MTA exclusive.
if [ "${shortname}" == "mta" ]; then
currentopt+=( "${cmd_install_default_resources[@]}" )
fi
# Squad license exclusive.
if [ "${shortname}" == "squad" ]; then
currentopt+=( "${cmd_install_squad_license[@]}" )
fi
## Mods commands.
if [ "${engine}" == "source" ]||[ "${shortname}" == "rust" ]||[ "${shortname}" == "hq" ]||[ "${shortname}" == "sdtd" ]||[ "${shortname}" == "cs" ]||[ "${shortname}" == "dod" ]||[ "${shortname}" == "tfc" ]||[ "${shortname}" == "ns" ]||[ "${shortname}" == "ts" ]||[ "${shortname}" == "hldm" ]; then
currentopt+=( "${cmd_mods_install[@]}" "${cmd_mods_remove[@]}" "${cmd_mods_update[@]}" )
fi
## Installer.
currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" )
## Developer commands.
currentopt+=( "${cmd_dev_debug[@]}" )
if [ -f ".dev-debug" ]; then
currentopt+=( "${cmd_dev_detect_deps[@]}" "${cmd_dev_detect_glibc[@]}" "${cmd_dev_detect_ldd[@]}" "${cmd_dev_query_raw[@]}" "${cmd_dev_clear_functions[@]}" )
fi
## Donate.
currentopt+=( "${cmd_donate[@]}" )
### Build list of available commands.
optcommands=()
index="0"
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
cmdamount=$(echo -e "${currentopt[index]}" | awk -F ';' '{ print NF }')
for ((cmdindex=1; cmdindex <= cmdamount; cmdindex++)); do
optcommands+=( "$(echo -e "${currentopt[index]}" | awk -F ';' -v x=${cmdindex} '{ print $x }')" )
done
done
# Shows LinuxGSM usage.
fn_opt_usage(){
echo -e "Usage: $0 [option]"
echo -e ""
echo -e "LinuxGSM - ${gamename} - Version ${version}"
echo -e "https://linuxgsm.com/${gameservername}"
echo -e ""
echo -e "${lightyellow}Commands${default}"
# Display available commands.
index="0"
{
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
# Hide developer commands.
if [ "${currentopt[index+2]}" != "DEVCOMMAND" ]; then
echo -e "${cyan}$(echo -e "${currentopt[index]}" | awk -F ';' '{ print $2 }')\t${default}$(echo -e "${currentopt[index]}" | awk -F ';' '{ print $1 }')\t| ${currentopt[index+2]}"
fi
done
} | column -s $'\t' -t
fn_script_log_pass "Display commands"
core_exit.sh
}
# Check if command existw and run corresponding scripts, or display script usage.
if [ -z "${getopt}" ]; then
fn_opt_usage
fi
# If command exists.
for i in "${optcommands[@]}"; do
if [ "${i}" == "${getopt}" ] ; then
# Seek and run command.
index="0"
for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
currcmdamount=$(echo -e "${currentopt[index]}" | awk -F ';' '{ print NF }')
for ((currcmdindex=1; currcmdindex <= currcmdamount; currcmdindex++)); do
if [ "$(echo -e "${currentopt[index]}" | awk -F ';' -v x=${currcmdindex} '{ print $x }')" == "${getopt}" ]; then
# Run command.
eval "${currentopt[index+1]}"
# Exit should occur in modules. Should this not happen print an error
fn_print_error2_nl "Command did not exit correctly: ${getopt}"
fn_script_log_error "Command did not exit correctly: ${getopt}"
core_exit.sh
fi
done
done
fi
done
# If we're executing this, it means command was not found.
fn_print_error2_nl "Unknown command: $0 ${getopt}"
fn_script_log_error "Unknown command: $0 ${getopt}"
fn_opt_usage
core_exit.sh