4
0

core_getopt.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/bash
  2. # LinuxGSM core_getopt.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: getopt arguments.
  6. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. ### Define all commands here ###
  8. ## User commands | Trigger commands | Description
  9. # Standard commands
  10. cmd_install=( "i;install" "command_install.sh" "Install the server." )
  11. cmd_auto_install=( "ai;auto-install" "fn_autoinstall" "Install the server without prompts." )
  12. cmd_start=( "st;start" "command_start.sh" "Start the server." )
  13. cmd_stop=( "sp;stop" "command_stop.sh" "Stop the server." )
  14. cmd_restart=( "r;restart" "command_restart.sh" "Restart the server." )
  15. cmd_details=( "dt;details" "command_details.sh" "Display server information." )
  16. cmd_postdetails=( "pd;postdetails" "command_postdetails.sh" "Post details to hastebin (removing passwords)." )
  17. cmd_backup=( "b;backup" "command_backup.sh" "Create backup archives of the server." )
  18. cmd_update_linuxgsm=( "ul;update-lgsm;uf;update-functions" "command_update_linuxgsm.sh" "Check and apply any LinuxGSM updates." )
  19. cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." )
  20. cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." )
  21. # Console servers only
  22. cmd_console=( "c;console" "command_console.sh" "Access server console." )
  23. cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." )
  24. # Update servers only
  25. cmd_update=( "u;update" "command_update.sh" "Check and apply any server updates." )
  26. cmd_force_update=( "fu;force-update;update-restart;ur" "forceupdate=1; command_update.sh" "Apply server updates bypassing check." )
  27. # SteamCMD servers only
  28. cmd_validate=( "v;validate" "command_validate.sh" "Validate server files with SteamCMD." )
  29. # Server with mods-install
  30. cmd_mods_install=( "mi;mods-install" "command_mods_install.sh" "View and install available mods/addons." )
  31. cmd_mods_remove=( "mr;mods-remove" "command_mods_remove.sh" "View and remove an installed mod/addon." )
  32. cmd_mods_update=( "mu;mods-update" "command_mods_update.sh" "Update installed mods/addons." )
  33. # Server specific
  34. cmd_change_password=( "pw;change-password" "command_ts3_server_pass.sh" "Change TS3 serveradmin password." )
  35. cmd_install_default_resources=( "ir;install-default-resources" "command_install_resources_mta.sh" "Install the MTA default resources." )
  36. cmd_wipe=( "wi;wipe" "command_wipe.sh" "Wipe your server data." )
  37. cmd_map_compressor_u99=( "mc;map-compressor" "compress_ut99_maps.sh" "Compresses all ${gamename} server maps." )
  38. cmd_map_compressor_u2=( "mc;map-compressor" "compress_unreal2_maps.sh" "Compresses all ${gamename} server maps." )
  39. cmd_install_cdkey=( "cd;server-cd-key" "install_ut2k4_key.sh" "Add your server cd key." )
  40. cmd_install_dst_token=( "ct;cluster-token" "install_dst_token.sh" "Configure cluster token." )
  41. cmd_install_squad_license=( "li;license" "install_squad_license.sh" "Add your Squad server license." )
  42. cmd_fastdl=( "fd;fastdl" "command_fastdl.sh" "Build a FastDL directory." )
  43. # Dev commands
  44. cmd_dev_debug=( "dev;developer" "command_dev_debug.sh" "Enable developer Mode." )
  45. cmd_dev_detect_deps=( "dd;detect-deps" "command_dev_detect_deps.sh" "Detect required dependencies." )
  46. cmd_dev_detect_glibc=( "dg;detect-glibc" "command_dev_detect_glibc.sh" "Detect required glibc." )
  47. cmd_dev_detect_ldd=( "dl;detect-ldd" "command_dev_detect_ldd.sh" "Detect required dynamic dependencies." )
  48. ### Set specific opt here ###
  49. currentopt=( "${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" )
  50. # Update LGSM
  51. currentopt+=( "${cmd_update_linuxgsm[@]}" )
  52. # Exclude noupdate games here
  53. if [ "${gamename}" != "Battlefield: 1942" ]&&[ "${engine}" != "quake" ]&&[ "${engine}" != "idtech2" ]&&[ "${engine}" != "idtech3" ]&&[ "${engine}" != "iw2.0" ]&&[ "${engine}" != "iw3.0" ]&&[ "${gamename}" != "San Andreas Multiplayer" ]; then
  54. currentopt+=( "${cmd_update[@]}" )
  55. # force update for SteamCMD only or MTA
  56. if [ -n "${appid}" ] || [ "${gamename}" == "Multi Theft Auto" ]; then
  57. currentopt+=( "${cmd_force_update[@]}" )
  58. fi
  59. fi
  60. # Validate command
  61. if [ -n "${appid}" ]; then
  62. currentopt+=( "${cmd_validate[@]}" )
  63. fi
  64. #Backup
  65. currentopt+=( "${cmd_backup[@]}" )
  66. # Exclude games without a console
  67. if [ "${gamename}" != "TeamSpeak 3" ]; then
  68. currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
  69. fi
  70. ## Game server exclusive commands
  71. # FastDL command
  72. if [ "${engine}" == "source" ]; then
  73. currentopt+=( "${cmd_fastdl[@]}" )
  74. fi
  75. # TeamSpeak exclusive
  76. if [ "${gamename}" == "TeamSpeak 3" ]; then
  77. currentopt+=( "${cmd_change_password[@]}" )
  78. fi
  79. # Unreal exclusive
  80. if [ "${gamename}" == "Rust" ]; then
  81. currentopt+=( "${cmd_wipe[@]}" )
  82. fi
  83. if [ "${engine}" == "unreal2" ]; then
  84. if [ "${gamename}" == "Unreal Tournament 2004" ]; then
  85. currentopt+=( "${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}" )
  86. else
  87. currentopt+=( "${cmd_map_compressor_u2[@]}" )
  88. fi
  89. fi
  90. if [ "${engine}" == "unreal" ]; then
  91. currentopt+=( "${cmd_map_compressor_u99[@]}" )
  92. fi
  93. # DST exclusive
  94. if [ "${gamename}" == "Don't Starve Together" ]; then
  95. currentopt+=( "${cmd_install_dst_token[@]}" )
  96. fi
  97. # MTA exclusive
  98. if [ "${gamename}" == "Multi Theft Auto" ]; then
  99. currentopt+=( "${cmd_install_default_resources[@]}" )
  100. fi
  101. # Squad license exclusive
  102. if [ "${gamename}" == "Squad" ]; then
  103. currentopt+=( "${cmd_install_squad_license[@]}" )
  104. fi
  105. ## Mods commands
  106. if [ "${engine}" == "source" ]||[ "${gamename}" == "Rust" ]||[ "${gamename}" == "Hurtworld" ]||[ "${gamename}" == "7 Days To Die" ]; then
  107. currentopt+=( "${cmd_mods_install[@]}" "${cmd_mods_remove[@]}" "${cmd_mods_update[@]}" )
  108. fi
  109. ## Installer
  110. currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" )
  111. ## Developer commands
  112. currentopt+=( "${cmd_dev_debug[@]}" )
  113. if [ -f ".dev-debug" ]; then
  114. currentopt+=( "${cmd_dev_detect_deps[@]}" "${cmd_dev_detect_glibc[@]}" "${cmd_dev_detect_ldd[@]}" )
  115. fi
  116. ### Build list of available commands
  117. optcommands=()
  118. index="0"
  119. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  120. cmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  121. for ((cmdindex=1; cmdindex <= ${cmdamount}; cmdindex++)); do
  122. optcommands+=( "$(echo "${currentopt[index]}"| awk -F ';' -v x=${cmdindex} '{ print $x }')" )
  123. done
  124. done
  125. # Shows LinuxGSM usage
  126. fn_opt_usage(){
  127. echo "Usage: $0 [option]"
  128. echo -e ""
  129. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  130. echo "https://gameservermanagers.com/${gameservername}"
  131. echo -e ""
  132. echo -e "${lightyellow}Commands${default}"
  133. # Display available commands
  134. index="0"
  135. {
  136. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  137. # Hide developer commands
  138. if [ "${currentopt[index+2]}" != "DEVCOMMAND" ]; then
  139. echo -e "${cyan}$(echo "${currentopt[index]}" | awk -F ';' '{ print $2 }')\t${default}$(echo "${currentopt[index]}" | awk -F ';' '{ print $1 }')\t| ${currentopt[index+2]}"
  140. fi
  141. done
  142. } | column -s $'\t' -t
  143. core_exit.sh
  144. }
  145. ### Check if user commands exist and run corresponding scripts, or display script usage
  146. if [ -z "${getopt}" ]; then
  147. fn_opt_usage
  148. fi
  149. # Command exists
  150. for i in "${optcommands[@]}"; do
  151. if [ "${i}" == "${getopt}" ] ; then
  152. # Seek and run command
  153. index="0"
  154. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  155. currcmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  156. for ((currcmdindex=1; currcmdindex <= ${currcmdamount}; currcmdindex++)); do
  157. if [ "$(echo "${currentopt[index]}"| awk -F ';' -v x=${currcmdindex} '{ print $x }')" == "${getopt}" ]; then
  158. # Run command
  159. eval ${currentopt[index+1]}
  160. core_exit.sh
  161. break
  162. fi
  163. done
  164. done
  165. fi
  166. done
  167. # If we're executing this, it means command was not found
  168. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  169. exitcode=2
  170. fn_opt_usage
  171. core_exit.sh