linuxgsm.sh 20 KB

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