4
0

linuxgsm.sh 22 KB

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