linuxgsm.sh 20 KB

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