linuxgsm.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #!/bin/bash
  2. # Project: Linux Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, see LICENSE.md
  5. # Purpose: Linux Game Server Management Script
  6. # Contributors: https://linuxgsm.com/contrib
  7. # Documentation: https://docs.linuxgsm.com
  8. # Website: https://linuxgsm.com
  9. # DO NOT EDIT THIS FILE
  10. # LinuxGSM configuration is no longer edited here
  11. # To update your LinuxGSM config go to:
  12. # lgsm/config-lgsm
  13. # https://docs.linuxgsm.com/configuration/linuxgsm-config
  14. # Debugging
  15. if [ -f ".dev-debug" ]; then
  16. if [ -f /.dockerenv ]; then
  17. exec 5> /data/log/dev-debug.log
  18. else
  19. exec 5> dev-debug.log
  20. fi
  21. BASH_XTRACEFD="5"
  22. set -x
  23. fi
  24. version="v26.3.0"
  25. shortname="core"
  26. gameservername="core"
  27. commandname="CORE"
  28. rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
  29. selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  30. lgsmdir="${rootdir}/lgsm"
  31. [ -n "${LGSM_LOGDIR}" ] && logdir="${LGSM_LOGDIR}" || logdir="${rootdir}/log"
  32. lgsmlogdir="${logdir}/script"
  33. lgsmlog="${lgsmlogdir}/${selfname}-script.log"
  34. steamcmddir="${HOME}/.steam/steamcmd"
  35. [ -n "${LGSM_SERVERFILES}" ] && serverfiles="${LGSM_SERVERFILES}" || serverfiles="${rootdir}/serverfiles"
  36. modulesdir="${lgsmdir}/modules"
  37. tmpdir="${lgsmdir}/tmp"
  38. [ -n "${LGSM_DATADIR}" ] && datadir="${LGSM_DATADIR}" || datadir="${lgsmdir}/data"
  39. lockdir="${lgsmdir}/lock"
  40. sessionname="${selfname}"
  41. [ -f "${datadir}/${selfname}.uid" ] && socketname="${sessionname}-$(cat "${datadir}/${selfname}.uid")"
  42. serverlist="${datadir}/serverlist.csv"
  43. serverlistmenu="${datadir}/serverlistmenu.csv"
  44. [ -n "${LGSM_CONFIG}" ] && configdir="${LGSM_CONFIG}" || configdir="${lgsmdir}/config-lgsm"
  45. configdirserver="${configdir}/${gameservername}"
  46. configdirdefault="${lgsmdir}/config-default"
  47. userinput="${1}"
  48. userinput2="${2}"
  49. ## GitHub Branch Select
  50. # Allows for the use of different function files
  51. # from a different repo and/or branch.
  52. [ -n "${LGSM_GITHUBUSER}" ] && githubuser="${LGSM_GITHUBUSER}" || githubuser="GameServerManagers"
  53. [ -n "${LGSM_GITHUBREPO}" ] && githubrepo="${LGSM_GITHUBREPO}" || githubrepo="LinuxGSM"
  54. [ -n "${LGSM_GITHUBBRANCH}" ] && githubbranch="${LGSM_GITHUBBRANCH}" || githubbranch="master"
  55. # Check that curl is installed before doing anything
  56. if [ ! "$(command -v curl 2> /dev/null)" ]; then
  57. echo -e "[ FAIL ] Curl is not installed"
  58. exit 1
  59. fi
  60. # Core module that is required first.
  61. core_modules.sh() {
  62. modulefile="${FUNCNAME[0]}"
  63. fn_bootstrap_fetch_file_github "lgsm/modules" "core_modules.sh" "${modulesdir}" "chmodx" "run" "noforcedl" "nomd5"
  64. }
  65. # Bootstrap
  66. # Exits during bootstrap. core_exit.sh is only usable once core_modules.sh (which defines it)
  67. # and core_dl.sh (fn_fetch_module, which it uses) are loaded, so fall back to a plain exit.
  68. fn_bootstrap_exit() {
  69. if type core_exit.sh > /dev/null 2>&1 && type fn_fetch_module > /dev/null 2>&1; then
  70. core_exit.sh
  71. else
  72. exit "${1:-1}"
  73. fi
  74. }
  75. # Fetches the core modules required before passed off to core_dl.sh.
  76. fn_bootstrap_fetch_trap() {
  77. echo -e ""
  78. rm -f "${local_filedir:?}/${local_filename}"
  79. # Message and logging functions come from core_messages.sh, which may not be loaded yet.
  80. if type fn_print_canceled_eol_nl > /dev/null 2>&1; then
  81. echo -en "downloading ${local_filename}"
  82. fn_print_canceled_eol_nl
  83. echo -en "downloading ${local_filename}"
  84. fn_print_removed_eol_nl
  85. fn_script_log_info "Downloading ${local_filename}...CANCELED"
  86. fn_script_log_info "Downloading ${local_filename}...REMOVED"
  87. else
  88. echo -e "downloading ${local_filename} ... CANCELED (removed)"
  89. fi
  90. fn_bootstrap_exit 130
  91. }
  92. # Fetches modules from the Git repo during first download.
  93. fn_bootstrap_fetch_module() {
  94. github_file_url_dir="lgsm/modules"
  95. github_file_url_name="${modulefile}"
  96. # If master branch will currently running LinuxGSM version to prevent "version mixing". This is ignored if a fork.
  97. if [ "${githubbranch}" == "master" ] && [ "${githubuser}" == "GameServerManagers" ] && [ "${commandname}" != "UPDATE-LGSM" ]; then
  98. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  99. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  100. else
  101. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  102. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  103. fi
  104. remote_fileurl_name="GitHub"
  105. remote_fileurl_backup_name="Bitbucket"
  106. local_filedir="${modulesdir}"
  107. local_filename="${github_file_url_name}"
  108. chmodx="chmodx"
  109. run="run"
  110. forcedl="noforce"
  111. hash="nohash"
  112. # Passes vars to the file download module.
  113. fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
  114. }
  115. fn_bootstrap_fetch_file() {
  116. remote_fileurl="${1}"
  117. remote_fileurl_backup="${2}"
  118. remote_fileurl_name="${3}"
  119. remote_fileurl_backup_name="${4}"
  120. local_filedir="${5}"
  121. local_filename="${6}"
  122. chmodx="${7:-0}"
  123. run="${8:-0}"
  124. forcedl="${9:-0}"
  125. hash="${10:-0}"
  126. # Download file if missing or download forced.
  127. if [ ! -f "${local_filedir}/${local_filename}" ] || [ "${forcedl}" == "forcedl" ]; then
  128. # If backup fileurl exists include it.
  129. if [ -n "${remote_fileurl_backup}" ]; then
  130. # counter set to 0 to allow second try
  131. counter=0
  132. remote_fileurls_array=(remote_fileurl remote_fileurl_backup)
  133. else
  134. # counter set to 1 to not allow second try
  135. counter=1
  136. remote_fileurls_array=(remote_fileurl)
  137. fi
  138. for remote_fileurl_array in "${remote_fileurls_array[@]}"; do
  139. if [ "${remote_fileurl_array}" == "remote_fileurl" ]; then
  140. fileurl="${remote_fileurl}"
  141. fileurl_name="${remote_fileurl_name}"
  142. elif [ "${remote_fileurl_array}" == "remote_fileurl_backup" ]; then
  143. fileurl="${remote_fileurl_backup}"
  144. fileurl_name="${remote_fileurl_backup_name}"
  145. fi
  146. counter=$((counter + 1))
  147. if [ ! -d "${local_filedir}" ]; then
  148. mkdir -p "${local_filedir}"
  149. fi
  150. # Trap will remove part downloaded files if canceled.
  151. trap fn_bootstrap_fetch_trap INT
  152. curlcmd=(curl --connect-timeout 3 --fail -L -o "${local_filedir}/${local_filename}" --retry 2 -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randomint}.212 Safari/537.36")
  153. # if is large file show progress, else be silent
  154. local exitcode=""
  155. large_files=("bz2" "gz" "zip" "jar" "xz")
  156. if grep -qE "(^|\s)${local_filename##*.}(\s|$)" <<< "${large_files[@]}"; then
  157. echo -e "downloading file [ ${local_filename} ]"
  158. fn_sleep_time
  159. "${curlcmd[@]}" --progress-bar "${fileurl}" 2>&1
  160. exitcode=$?
  161. echo -en "downloading file [ ${local_filename} ]"
  162. else
  163. echo -en "fetching ${fileurl_name} [ ${local_filename} ]\c"
  164. "${curlcmd[@]}" --silent --show-error "${fileurl}" 2>&1
  165. exitcode=$?
  166. fi
  167. # Download will fail if downloads a html file.
  168. if [ -f "${local_filedir}/${local_filename}" ]; then
  169. if head -n 1 "${local_filedir}/${local_filename}" | grep -q "DOCTYPE"; then
  170. rm "${local_filedir:?}/${local_filename:?}"
  171. local exitcode=2
  172. fi
  173. fi
  174. # On first try will error. On second try will fail.
  175. if [ "${exitcode}" -ne 0 ]; then
  176. if [ ${counter} -ge 2 ]; then
  177. echo -e " ... FAIL"
  178. # Logging functions come from core_messages.sh, which may not be loaded yet during bootstrap.
  179. if [ -f "${lgsmlog}" ] && type fn_script_log_fail > /dev/null 2>&1; then
  180. fn_script_log_fail "Downloading ${local_filename}..."
  181. fn_script_log_fail "${fileurl}"
  182. fi
  183. fn_bootstrap_exit 1
  184. else
  185. echo -e " ... ERROR"
  186. if [ -f "${lgsmlog}" ] && type fn_script_log_error > /dev/null 2>&1; then
  187. fn_script_log_error "Downloading ${local_filename}..."
  188. fn_script_log_error "${fileurl}"
  189. fi
  190. fi
  191. else
  192. echo -en " ... OK"
  193. sleep "0.1"
  194. echo -e "\033\\r"
  195. if [ -f "${lgsmlog}" ] && type fn_script_log_pass > /dev/null 2>&1; then
  196. fn_script_log_pass "Downloading ${local_filename}..."
  197. fi
  198. # Make file executable if chmodx is set.
  199. if [ "${chmodx}" == "chmodx" ]; then
  200. chmod +x "${local_filedir}/${local_filename}"
  201. fi
  202. # Remove trap.
  203. trap - INT
  204. break
  205. fi
  206. done
  207. fi
  208. if [ -f "${local_filedir}/${local_filename}" ]; then
  209. # Execute file if run is set.
  210. if [ "${run}" == "run" ]; then
  211. # shellcheck source=/dev/null
  212. source "${local_filedir}/${local_filename}"
  213. fi
  214. fi
  215. }
  216. fn_bootstrap_fetch_file_github() {
  217. github_file_url_dir="${1}"
  218. github_file_url_name="${2}"
  219. # By default modules will be downloaded from the version release to prevent potential version mixing. Only update-lgsm will allow an update.
  220. if [ "${githubbranch}" == "master" ] && [ "${githubuser}" == "GameServerManagers" ] && [ "${commandname}" != "UPDATE-LGSM" ]; then
  221. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  222. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  223. else
  224. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  225. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  226. fi
  227. remote_fileurl_name="GitHub"
  228. remote_fileurl_backup_name="Bitbucket"
  229. local_filedir="${3}"
  230. local_filename="${github_file_url_name}"
  231. chmodx="${4:-0}"
  232. run="${5:-0}"
  233. forcedl="${6:-0}"
  234. md5="${7:-0}"
  235. # Passes vars to the file download module.
  236. fn_bootstrap_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  237. }
  238. # Installer menu.
  239. fn_print_center() {
  240. # Fall back to 80 columns when there is no terminal.
  241. columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
  242. columns="${columns:-80}"
  243. line="$*"
  244. printf "%*s\n" $(((${#line} + columns) / 2)) "${line}"
  245. }
  246. fn_print_horizontal() {
  247. # Fall back to 80 columns when there is no terminal; bash 5.3+ rejects an empty printf width.
  248. local columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
  249. printf '%*s\n' "${columns:-80}" '' | tr ' ' "="
  250. }
  251. # Bash menu.
  252. fn_install_menu_bash() {
  253. local resultvar=$1
  254. title=$2
  255. caption=$3
  256. options=$4
  257. fn_print_horizontal
  258. fn_print_center "${title}"
  259. fn_print_center "${caption}"
  260. fn_print_horizontal
  261. menu_options=()
  262. while read -r line || [[ -n "${line}" ]]; do
  263. var=$(echo -e "${line}" | awk -F "," '{print $2 " - " $3}')
  264. menu_options+=("${var}")
  265. done < "${options}"
  266. menu_options+=("Cancel")
  267. select option in "${menu_options[@]}"; do
  268. if [ "${option}" ] && [ "${option}" != "Cancel" ]; then
  269. eval "$resultvar=\"${option/%\ */}\""
  270. fi
  271. break
  272. done
  273. }
  274. # Whiptail/Dialog menu.
  275. fn_install_menu_whiptail() {
  276. local menucmd=$1
  277. local resultvar=$2
  278. title=$3
  279. caption=$4
  280. options=$5
  281. height=${6:-40}
  282. width=${7:-80}
  283. menuheight=${8:-30}
  284. IFS=","
  285. menu_options=()
  286. while read -r line; do
  287. key=$(echo -e "${line}" | awk -F "," '{print $3}')
  288. val=$(echo -e "${line}" | awk -F "," '{print $2}')
  289. menu_options+=("${val//\"/}" "${key//\"/}")
  290. done < "${options}"
  291. OPTION=$(${menucmd} --title "${title}" --menu "${caption}" "${height}" "${width}" "${menuheight}" "${menu_options[@]}" 3>&1 1>&2 2>&3)
  292. exitcode=$?
  293. if [ "${exitcode}" -eq 0 ]; then
  294. eval "$resultvar=\"${OPTION}\""
  295. else
  296. eval "$resultvar="
  297. fi
  298. }
  299. # Menu selector.
  300. fn_install_menu() {
  301. local resultvar=$1
  302. local selection=""
  303. title=$2
  304. caption=$3
  305. options=$4
  306. # Get menu command.
  307. for menucmd in whiptail dialog bash; do
  308. if [ "$(command -v "${menucmd}")" ]; then
  309. menucmd=$(command -v "${menucmd}")
  310. break
  311. fi
  312. done
  313. case "$(basename "${menucmd}")" in
  314. whiptail | dialog)
  315. fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30
  316. ;;
  317. *)
  318. fn_install_menu_bash selection "${title}" "${caption}" "${options}"
  319. ;;
  320. esac
  321. eval "$resultvar=\"${selection}\""
  322. }
  323. # Gets server info from serverlist.csv and puts in to array.
  324. fn_server_info() {
  325. IFS=","
  326. server_info_line="$(grep -aw "${userinput}" "${serverlist}" | head -n 1)"
  327. read -r -a server_info_array <<< "${server_info_line}"
  328. shortname="${server_info_array[0]}" # csgo
  329. gameservername="${server_info_array[1]}" # csgoserver
  330. gamename="${server_info_array[2]}" # Counter Strike: Global Offensive
  331. }
  332. fn_install_getopt() {
  333. userinput="empty"
  334. echo -e "Usage: $0 [option]"
  335. echo -e ""
  336. echo -e "Installer - Linux Game Server Managers - Version ${version}"
  337. echo -e "https://linuxgsm.com"
  338. echo -e ""
  339. echo -e "Commands"
  340. echo -e "install\t\t| Select server to install."
  341. echo -e "servername\t| Enter name of game server to install. e.g $0 csgoserver."
  342. echo -e "list\t\t| List all servers available for install."
  343. exit
  344. }
  345. fn_install_file() {
  346. local_filename="${gameservername}"
  347. if [ -e "${local_filename}" ]; then
  348. i=2
  349. while [ -e "${local_filename}-${i}" ]; do
  350. ((i++))
  351. done
  352. local_filename="${local_filename}-${i}"
  353. fi
  354. cp -R "${selfname}" "${local_filename}"
  355. sed -i -e "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${local_filename}"
  356. sed -i -e "s/gameservername=\"core\"/gameservername=\"${gameservername}\"/g" "${local_filename}"
  357. echo -e "Installed ${gamename} server as ${local_filename}"
  358. echo -e ""
  359. if [ ! -d "${serverfiles}" ]; then
  360. echo -e "./${local_filename} install"
  361. else
  362. echo -e "Remember to check server ports"
  363. echo -e "./${local_filename} details"
  364. fi
  365. echo -e ""
  366. exit
  367. }
  368. # Prevent LinuxGSM from running as root. Except if doing a dependency install.
  369. if [ "$(whoami)" == "root" ]; then
  370. if [ -f "${modulesdir}/core_modules.sh" ] || [ -f "${modulesdir}/check_root.sh" ] || [ -f "${modulesdir}/core_messages.sh" ]; then
  371. if [ "${userinput}" != "install" ] && [ "${userinput}" != "auto-install" ] && [ "${userinput}" != "i" ] && [ "${userinput}" != "ai" ]; then
  372. core_modules.sh
  373. core_messages.sh
  374. fn_ansi_loader
  375. check_root.sh
  376. fi
  377. else
  378. if [ "${userinput}" != "install" ] && [ "${userinput}" != "auto-install" ] && [ "${userinput}" != "i" ] && [ "${userinput}" != "ai" ]; then
  379. echo -e "[ FAIL ] Do NOT run as root!"
  380. exit 1
  381. fi
  382. fi
  383. fi
  384. # LinuxGSM installer mode.
  385. if [ "${shortname}" == "core" ]; then
  386. # Download the latest serverlist. This is the complete list of all supported servers.
  387. fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
  388. if [ ! -f "${serverlist}" ]; then
  389. echo -e "[ FAIL ] serverlist.csv could not be loaded."
  390. exit 1
  391. fi
  392. if [ "${userinput}" == "list" ] || [ "${userinput}" == "l" ]; then
  393. {
  394. tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
  395. } | column -s $'\t' -t | more
  396. exit
  397. elif [ "${userinput}" == "install" ] || [ "${userinput}" == "i" ]; then
  398. tail -n +2 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}"
  399. fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}"
  400. userinput="${result}"
  401. fn_server_info
  402. if [ "${result}" == "${gameservername}" ]; then
  403. fn_install_file
  404. elif [ "${result}" == "" ]; then
  405. echo -e "Install canceled"
  406. else
  407. echo -e "[ FAIL ] menu result does not match gameservername"
  408. echo -e "result: ${result}"
  409. echo -e "gameservername: ${gameservername}"
  410. fi
  411. elif [ "${userinput}" ]; then
  412. fn_server_info
  413. if [ "${userinput}" == "${gameservername}" ] || [ "${userinput}" == "${gamename}" ] || [ "${userinput}" == "${shortname}" ]; then
  414. fn_install_file
  415. else
  416. echo -e "[ FAIL ] Unknown game server"
  417. exit 1
  418. fi
  419. else
  420. fn_install_getopt
  421. fi
  422. # LinuxGSM server mode.
  423. else
  424. core_modules.sh
  425. if [ "${shortname}" != "core-dep" ]; then
  426. # Load LinuxGSM configs.
  427. # These are required to get all the default variables for the specific server.
  428. # Load the default config. If missing download it. If changed reload it.
  429. if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then
  430. mkdir -p "${configdirdefault}/config-lgsm/${gameservername}"
  431. fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  432. fi
  433. if [ ! -f "${configdirserver}/_default.cfg" ]; then
  434. mkdir -p "${configdirserver}"
  435. echo -en "copying _default.cfg\c"
  436. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  437. exitcode=$?
  438. if [ "${exitcode}" -ne 0 ]; then
  439. echo -e " ... FAIL"
  440. exit 1
  441. else
  442. echo -e " ... OK"
  443. fi
  444. else
  445. config_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg")
  446. if [ "${config_file_diff}" != "" ]; then
  447. fn_print_warn_nl "_default.cfg has altered. reloading config."
  448. echo -en "copying _default.cfg...\c"
  449. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  450. exitcode=$?
  451. if [ "${exitcode}" -ne 0 ]; then
  452. echo -e "FAIL"
  453. exit 1
  454. else
  455. echo -e " ... OK"
  456. fi
  457. fi
  458. fi
  459. fi
  460. # Load the IP details before the first config is loaded.
  461. check_ip.sh
  462. # Configs have to be loaded twice to allow start startparameters to pick up all vars
  463. # shellcheck source=/dev/null
  464. source "${configdirserver}/_default.cfg"
  465. # Load the common.cfg config. If missing download it.
  466. if [ ! -f "${configdirserver}/common.cfg" ]; then
  467. fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  468. # shellcheck source=/dev/null
  469. source "${configdirserver}/common.cfg"
  470. else
  471. # shellcheck source=/dev/null
  472. source "${configdirserver}/common.cfg"
  473. fi
  474. # Load the secrets-common.cfg config. If missing download it.
  475. if [ ! -f "${configdirserver}/secrets-common.cfg" ]; then
  476. fn_fetch_config "lgsm/config-default/config-lgsm" "secrets-common-template.cfg" "${configdirserver}" "secrets-common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  477. # shellcheck source=/dev/null
  478. source "${configdirserver}/secrets-common.cfg"
  479. else
  480. # shellcheck source=/dev/null
  481. source "${configdirserver}/secrets-common.cfg"
  482. fi
  483. # Load the instance.cfg config. If missing download it.
  484. if [ ! -f "${configdirserver}/${selfname}.cfg" ]; then
  485. fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  486. # shellcheck source=/dev/null
  487. source "${configdirserver}/${selfname}.cfg"
  488. else
  489. # shellcheck source=/dev/null
  490. source "${configdirserver}/${selfname}.cfg"
  491. fi
  492. # Load the secrets-instance.cfg config. If missing download it.
  493. if [ ! -f "${configdirserver}/secrets-${selfname}.cfg" ]; then
  494. fn_fetch_config "lgsm/config-default/config-lgsm" "secrets-instance-template.cfg" "${configdirserver}" "secrets-${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  495. # shellcheck source=/dev/null
  496. source "${configdirserver}/secrets-${selfname}.cfg"
  497. else
  498. # shellcheck source=/dev/null
  499. source "${configdirserver}/secrets-${selfname}.cfg"
  500. fi
  501. # Reloads start parameter to ensure all vars in startparameters are set.
  502. # Will reload the last defined startparameter.
  503. fn_reload_startparameters() {
  504. # reload Wurm config.
  505. if [ "${shortname}" == "wurm" ]; then
  506. # shellcheck source=/dev/null
  507. source "${servercfgfullpath}"
  508. fi
  509. # reload startparameters.
  510. if grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/secrets-${selfname}.cfg"; then
  511. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/secrets-${selfname}.cfg")"
  512. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/${selfname}.cfg"; then
  513. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/${selfname}.cfg")"
  514. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/secrets-common.cfg"; then
  515. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/secrets-common.cfg")"
  516. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/common.cfg"; then
  517. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/common.cfg")"
  518. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/_default.cfg"; then
  519. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/_default.cfg")"
  520. fi
  521. # reload preexecutable.
  522. if grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/secrets-${selfname}.cfg"; then
  523. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/secrets-${selfname}.cfg")"
  524. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/${selfname}.cfg"; then
  525. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/${selfname}.cfg")"
  526. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/secrets-common.cfg"; then
  527. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/secrets-common.cfg")"
  528. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/common.cfg"; then
  529. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/common.cfg")"
  530. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/_default.cfg"; then
  531. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/_default.cfg")"
  532. fi
  533. }
  534. # Load the linuxgsm.sh in to tmpdir. If missing download it.
  535. if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
  536. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
  537. fi
  538. # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
  539. fn_ansi_loader
  540. getopt=$1
  541. core_getopt.sh
  542. fi