core_getopt.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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" "command_autoinstall.sh" "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 relevant server information." )
  16. cmd_postdetails=( "pd;postdetails" "command_postdetails.sh" "Post stripped details to pastebin for support." )
  17. cmd_backup=( "b;backup" "command_backup.sh" "Create archives of the server." )
  18. cmd_update_functions=( "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 it 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 for updates and apply if available." )
  26. cmd_force_update=( "fu;force-update;update-restart;ur" "forceupdate=1; command_update.sh" "Unconditionally update the server." )
  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_ressources=( "ir;install-default-ressources" "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. # Dev commands
  42. cmd_dev_detect_deps=( "dd;detect-depts" "command_dev_detect_deps.sh" "Detect server dependencies." )
  43. cmd_dev_detect_glibc=( "dg;detect-glibc" "command_dev_detect_glibc.sh" "Detect server glibc requirements." )
  44. cmd_dev_detect_ldd=( "dl;detect-ldd" "command_dev_detect_ldd.sh" "Detect server ldd requirements." )
  45. ### Set specific opt here ###
  46. ## Common opt to all servers
  47. currentopt=( "${cmd_install[@]}" "${cmd_auto_install[@]}" "${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_details[@]}" )
  48. currentopt+=( "${cmd_backup[@]}" "${cmd_update_functions[@]}" "${cmd_test_alert[@]}" "${cmd_monitor[@]}" )
  49. ## Servers that do not have a feature
  50. # Exclude games without a console
  51. if [ "${gamename}" != "TeamSpeak 3" ]; then
  52. currentopt+=( "${cmd_console[@]}" )
  53. fi
  54. # Exclude noupdated games here
  55. if [ "${gamename}" != "Battlefield: 1942" ]&&[ "${gamename}" != "Call of Duty" ]&&[ "${gamename}" != "Call of Duty: United Offensive" ]&&[ "${gamename}" != "Call of Duty 2" ]&&[ "${gamename}" != "Call of Duty 4" ]&&[ "${gamename}" != "Call of Duty: World at War" ]&&[ "${gamename}" != "QuakeWorld" ]&&[ "${gamename}" != "Quake 2" ]&&[ "${gamename}" != "Quake 3: Arena" ]&&[ "${gamename}" != "Wolfenstein: Enemy Territory" ]; then
  56. currentopt+=( "${cmd_update[@]}" )
  57. fi
  58. ## Include games that have access to specific commands
  59. # Validate command
  60. if [ -n "${appid}" ]; then
  61. currentopt+=( "${cmd_validate[@]}" )
  62. fi
  63. # FastDL command
  64. if [ "${engine}" == "source" ]; then
  65. currentopt+=( "${cmd_fastdl[@]}" )
  66. fi
  67. # Wipe command
  68. if [ "${gamename}" == "Rust" ]; then
  69. currentopt+=( "${cmd_wipe[@]}" )
  70. fi
  71. # Mods commands
  72. if [ "${engine}" == "source" ]||[ "${gamename}" == "Rust" ]|[ "${gamename}" == "Hurtworld" ]|[ "${gamename}" == "7 Days To Die" ]; then
  73. currentopt+=( "${cmd_mods_install[@]}" "${cmd_mods_remove[@]}" "${cmd_mods_update[@]}" )
  74. fi
  75. ## Game server exclusive commands
  76. # TeamSpeak exclusive
  77. if [ "${gamename}" == "TeamSpeak 3" ]; then
  78. currentopt+=( "${cmd_change_password[@]}" )
  79. fi
  80. # Unreal exclusive
  81. if [ "${engine}" == "unreal2" ]; then
  82. if [ "${gamename}" == "Unreal Tournament 2004" ]; then
  83. currentopt+=( "${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}" )
  84. else
  85. currentopt+=( "${cmd_map_compressor_u2[@]}" )
  86. fi
  87. fi
  88. if [ "${engine}" == "unreal" ]; then
  89. currentopt+=( "${cmd_map_compressor_u99[@]}" )
  90. fi
  91. # DST exclusive
  92. if [ "${gamename}" == "Don't Starve Together" ]; then
  93. currentopt+=( "${cmd_install_dst_token[@]}" )
  94. fi
  95. # MTA exclusive
  96. if [ "${gamename}" == "Multi Theft Auto" ]; then
  97. currentopt+=( "${cmd_install_default_ressources[@]}" )
  98. fi
  99. ### Build list of available commands
  100. optcommands=()
  101. index="0"
  102. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  103. cmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  104. for ((cmdindex=1; cmdindex <= ${cmdamount}; cmdindex++)); do
  105. optcommands+=( "$(echo "${currentopt[index]}"| awk -F ';' -v x=${cmdindex} '{ print $x }')" )
  106. done
  107. done
  108. ### Check if user command exists or run the command
  109. if [[ ! "${optcommands[@]}" =~ "${getopt}" ]]||[ -z "${getopt}" ]; then
  110. if [ -z "${getopt}" ]; then
  111. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  112. exitcode=2
  113. echo "Usage: $0 [option]"
  114. fi
  115. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  116. echo "https://gameservermanagers.com/${selfname}"
  117. echo -e ""
  118. echo -e "${lightyellow}Commands${default}"
  119. # Display available commands
  120. index="0"
  121. {
  122. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  123. echo -e "${blue}$(echo "${currentopt[index]}" | awk -F ';' '{ print $2 }')\t${default}$(echo "${currentopt[index]}" | awk -F ';' '{ print $1 }')\t|${currentopt[index+2]}"
  124. done
  125. } | column -s $'\t' -t
  126. else
  127. # Seek and run command
  128. index="0"
  129. for ((index="0"; index < ${#currentopt[@]}; index+=3)); do
  130. currcmdamount="$(echo "${currentopt[index]}"| awk -F ';' '{ print NF }')"
  131. for ((currcmdindex=1; cmdindex < ${currcmdamount}; currcmdindex++)); do
  132. if [ "$(echo "${currentopt[index]}"| awk -F ';' -v x=${currcmdindex} '{ print $x }')" == "${getopt}" ]; then
  133. # Run command
  134. ${currentopt[index+1]}
  135. break
  136. fi
  137. done
  138. done
  139. fi
  140. core_exit.sh