core_getopt.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_functions=( "ul;update-lgsm;uf;update-functions" "command_update_functions.sh" "Update LinuxGSM functions." )
  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 updates." )
  26. cmd_force_update=( "fu;force-update;update-restart;ur" "forceupdate=1; command_update.sh" "Bypass update check and apply any updates." )
  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_fastdl=( "fd;fastdl" "command_fastdl.sh" "Build a FastDL directory." )
  42. # Dev commands
  43. cmd_dev_debug=( "dev;developer" "command_dev_debug.sh" "Enable developer Mode." )
  44. cmd_dev_detect_deps=( "dd;detect-deps" "command_dev_detect_deps.sh" "Detect required dependencies." )
  45. cmd_dev_detect_glibc=( "dg;detect-glibc" "command_dev_detect_glibc.sh" "Detect required glibc." )
  46. cmd_dev_detect_ldd=( "dl;detect-ldd" "command_dev_detect_ldd.sh" "Detect required dynamic dependencies." )
  47. ### Set specific opt here ###
  48. currentopt=( "${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" )
  49. # Exclude noupdate games here
  50. if [ "${gamename}" != "Battlefield: 1942" ]&&[ "${engine}" != "quake" ]&&[ "${engine}" != "idtech2" ]&&[ "${engine}" != "idtech3" ]&&[ "${engine}" != "iw2.0" ]&&[ "${engine}" != "iw3.0" ]; then
  51. currentopt+=( "${cmd_update[@]}" )
  52. # force update for SteamCMD only
  53. if [ -n "${appid}" ]; then
  54. currentopt+=( "${cmd_force_update[@]}" )
  55. fi
  56. fi
  57. # Validate command
  58. if [ -n "${appid}" ]; then
  59. currentopt+=( "${cmd_validate[@]}" )
  60. fi
  61. # Update LGSM
  62. currentopt+=( "${cmd_update_functions[@]}" )
  63. #Backup
  64. currentopt+=( "${cmd_backup[@]}" )
  65. # Exclude games without a console
  66. if [ "${gamename}" != "TeamSpeak 3" ]; then
  67. currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
  68. fi
  69. ## Game server exclusive commands
  70. # FastDL command
  71. if [ "${engine}" == "source" ]; then
  72. currentopt+=( "${cmd_fastdl[@]}" )
  73. fi
  74. # TeamSpeak exclusive
  75. if [ "${gamename}" == "TeamSpeak 3" ]; then
  76. currentopt+=( "${cmd_change_password[@]}" )
  77. fi
  78. # Unreal exclusive
  79. if [ "${gamename}" == "Rust" ]; then
  80. currentopt+=( "${cmd_wipe[@]}" )
  81. fi
  82. if [ "${engine}" == "unreal2" ]; then
  83. if [ "${gamename}" == "Unreal Tournament 2004" ]; then
  84. currentopt+=( "${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}" )
  85. else
  86. currentopt+=( "${cmd_map_compressor_u2[@]}" )
  87. fi
  88. fi
  89. if [ "${engine}" == "unreal" ]; then
  90. currentopt+=( "${cmd_map_compressor_u99[@]}" )
  91. fi
  92. # DST exclusive
  93. if [ "${gamename}" == "Don't Starve Together" ]; then
  94. currentopt+=( "${cmd_install_dst_token[@]}" )
  95. fi
  96. # MTA exclusive
  97. if [ "${gamename}" == "Multi Theft Auto" ]; then
  98. currentopt+=( "${cmd_install_default_resources[@]}" )
  99. fi
  100. ## Mods commands
  101. if [ "${engine}" == "source" ]||[ "${gamename}" == "Rust" ]||[ "${gamename}" == "Hurtworld" ]||[ "${gamename}" == "7 Days To Die" ]; then
  102. currentopt+=( "${cmd_mods_install[@]}" "${cmd_mods_remove[@]}" "${cmd_mods_update[@]}" )
  103. fi
  104. ## Installer
  105. currentopt+=( "${cmd_install[@]}" "${cmd_auto_install[@]}" )
  106. ## Developer commands
  107. currentopt+=( "${cmd_dev_debug[@]}" )
  108. if [ -f ".dev-debug" ]; then
  109. currentopt+=( "${cmd_dev_detect_deps[@]}" "${cmd_dev_detect_glibc[@]}" "${cmd_dev_detect_ldd[@]}" )
  110. fi
  111. ### Build list of available commands
  112. optcommands=()
  113. index="0"
  114. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  115. cmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  116. for ((cmdindex=1; cmdindex <= ${cmdamount}; cmdindex++)); do
  117. optcommands+=( "$(echo "${currentopt[index]}"| awk -F ';' -v x=${cmdindex} '{ print $x }')" )
  118. done
  119. done
  120. # Shows LinuxGSM usage
  121. fn_opt_usage(){
  122. echo "Usage: $0 [option]"
  123. echo -e ""
  124. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  125. echo "https://gameservermanagers.com/${selfname}"
  126. echo -e ""
  127. echo -e "${lightyellow}Commands${default}"
  128. # Display available commands
  129. index="0"
  130. {
  131. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  132. # Hide developer commands
  133. if [ "${currentopt[index+2]}" != "DEVCOMMAND" ]; then
  134. echo -e "${cyan}$(echo "${currentopt[index]}" | awk -F ';' '{ print $2 }')\t${default}$(echo "${currentopt[index]}" | awk -F ';' '{ print $1 }')\t| ${currentopt[index+2]}"
  135. fi
  136. done
  137. } | column -s $'\t' -t
  138. core_exit.sh
  139. }
  140. ### Check if user commands exist and run corresponding scripts, or display script usage
  141. if [ -z "${getopt}" ]; then
  142. fn_opt_usage
  143. fi
  144. # Command exists
  145. for i in "${optcommands[@]}"; do
  146. if [ "${i}" == "${getopt}" ] ; then
  147. # Seek and run command
  148. index="0"
  149. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  150. currcmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  151. for ((currcmdindex=1; currcmdindex <= ${currcmdamount}; currcmdindex++)); do
  152. if [ "$(echo "${currentopt[index]}"| awk -F ';' -v x=${currcmdindex} '{ print $x }')" == "${getopt}" ]; then
  153. # Run command
  154. eval ${currentopt[index+1]}
  155. core_exit.sh
  156. break
  157. fi
  158. done
  159. done
  160. fi
  161. done
  162. # If we're executing this, it means command was not found
  163. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  164. exitcode=2
  165. fn_opt_usage
  166. core_exit.sh