linuxgsm.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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.2.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. # 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. # Fall back to 80 columns when there is no terminal.
  226. columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
  227. columns="${columns:-80}"
  228. line="$*"
  229. printf "%*s\n" $(((${#line} + columns) / 2)) "${line}"
  230. }
  231. fn_print_horizontal() {
  232. # Fall back to 80 columns when there is no terminal; bash 5.3+ rejects an empty printf width.
  233. local columns="${COLUMNS:-$(tput cols 2> /dev/null)}"
  234. printf '%*s\n' "${columns:-80}" '' | tr ' ' "="
  235. }
  236. # Bash menu.
  237. fn_install_menu_bash() {
  238. local resultvar=$1
  239. title=$2
  240. caption=$3
  241. options=$4
  242. fn_print_horizontal
  243. fn_print_center "${title}"
  244. fn_print_center "${caption}"
  245. fn_print_horizontal
  246. menu_options=()
  247. while read -r line || [[ -n "${line}" ]]; do
  248. var=$(echo -e "${line}" | awk -F "," '{print $2 " - " $3}')
  249. menu_options+=("${var}")
  250. done < "${options}"
  251. menu_options+=("Cancel")
  252. select option in "${menu_options[@]}"; do
  253. if [ "${option}" ] && [ "${option}" != "Cancel" ]; then
  254. eval "$resultvar=\"${option/%\ */}\""
  255. fi
  256. break
  257. done
  258. }
  259. # Whiptail/Dialog menu.
  260. fn_install_menu_whiptail() {
  261. local menucmd=$1
  262. local resultvar=$2
  263. title=$3
  264. caption=$4
  265. options=$5
  266. height=${6:-40}
  267. width=${7:-80}
  268. menuheight=${8:-30}
  269. IFS=","
  270. menu_options=()
  271. while read -r line; do
  272. key=$(echo -e "${line}" | awk -F "," '{print $3}')
  273. val=$(echo -e "${line}" | awk -F "," '{print $2}')
  274. menu_options+=("${val//\"/}" "${key//\"/}")
  275. done < "${options}"
  276. OPTION=$(${menucmd} --title "${title}" --menu "${caption}" "${height}" "${width}" "${menuheight}" "${menu_options[@]}" 3>&1 1>&2 2>&3)
  277. exitcode=$?
  278. if [ "${exitcode}" -eq 0 ]; then
  279. eval "$resultvar=\"${OPTION}\""
  280. else
  281. eval "$resultvar="
  282. fi
  283. }
  284. # Menu selector.
  285. fn_install_menu() {
  286. local resultvar=$1
  287. local selection=""
  288. title=$2
  289. caption=$3
  290. options=$4
  291. # Get menu command.
  292. for menucmd in whiptail dialog bash; do
  293. if [ "$(command -v "${menucmd}")" ]; then
  294. menucmd=$(command -v "${menucmd}")
  295. break
  296. fi
  297. done
  298. case "$(basename "${menucmd}")" in
  299. whiptail | dialog)
  300. fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30
  301. ;;
  302. *)
  303. fn_install_menu_bash selection "${title}" "${caption}" "${options}"
  304. ;;
  305. esac
  306. eval "$resultvar=\"${selection}\""
  307. }
  308. # Gets server info from serverlist.csv and puts in to array.
  309. fn_server_info() {
  310. IFS=","
  311. server_info_line="$(grep -aw "${userinput}" "${serverlist}" | head -n 1)"
  312. read -r -a server_info_array <<< "${server_info_line}"
  313. shortname="${server_info_array[0]}" # csgo
  314. gameservername="${server_info_array[1]}" # csgoserver
  315. gamename="${server_info_array[2]}" # Counter Strike: Global Offensive
  316. }
  317. fn_install_getopt() {
  318. userinput="empty"
  319. echo -e "Usage: $0 [option]"
  320. echo -e ""
  321. echo -e "Installer - Linux Game Server Managers - Version ${version}"
  322. echo -e "https://linuxgsm.com"
  323. echo -e ""
  324. echo -e "Commands"
  325. echo -e "install\t\t| Select server to install."
  326. echo -e "servername\t| Enter name of game server to install. e.g $0 csgoserver."
  327. echo -e "list\t\t| List all servers available for install."
  328. exit
  329. }
  330. fn_install_file() {
  331. local_filename="${gameservername}"
  332. if [ -e "${local_filename}" ]; then
  333. i=2
  334. while [ -e "${local_filename}-${i}" ]; do
  335. ((i++))
  336. done
  337. local_filename="${local_filename}-${i}"
  338. fi
  339. cp -R "${selfname}" "${local_filename}"
  340. sed -i -e "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${local_filename}"
  341. sed -i -e "s/gameservername=\"core\"/gameservername=\"${gameservername}\"/g" "${local_filename}"
  342. echo -e "Installed ${gamename} server as ${local_filename}"
  343. echo -e ""
  344. if [ ! -d "${serverfiles}" ]; then
  345. echo -e "./${local_filename} install"
  346. else
  347. echo -e "Remember to check server ports"
  348. echo -e "./${local_filename} details"
  349. fi
  350. echo -e ""
  351. exit
  352. }
  353. # Prevent LinuxGSM from running as root. Except if doing a dependency install.
  354. if [ "$(whoami)" == "root" ]; then
  355. if [ -f "${modulesdir}/core_modules.sh" ] || [ -f "${modulesdir}/check_root.sh" ] || [ -f "${modulesdir}/core_messages.sh" ]; then
  356. if [ "${userinput}" != "install" ] && [ "${userinput}" != "auto-install" ] && [ "${userinput}" != "i" ] && [ "${userinput}" != "ai" ]; then
  357. core_modules.sh
  358. core_messages.sh
  359. fn_ansi_loader
  360. check_root.sh
  361. fi
  362. else
  363. if [ "${userinput}" != "install" ] && [ "${userinput}" != "auto-install" ] && [ "${userinput}" != "i" ] && [ "${userinput}" != "ai" ]; then
  364. echo -e "[ FAIL ] Do NOT run as root!"
  365. exit 1
  366. fi
  367. fi
  368. fi
  369. # LinuxGSM installer mode.
  370. if [ "${shortname}" == "core" ]; then
  371. # Download the latest serverlist. This is the complete list of all supported servers.
  372. fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
  373. if [ ! -f "${serverlist}" ]; then
  374. echo -e "[ FAIL ] serverlist.csv could not be loaded."
  375. exit 1
  376. fi
  377. if [ "${userinput}" == "list" ] || [ "${userinput}" == "l" ]; then
  378. {
  379. tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
  380. } | column -s $'\t' -t | more
  381. exit
  382. elif [ "${userinput}" == "install" ] || [ "${userinput}" == "i" ]; then
  383. tail -n +2 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}"
  384. fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}"
  385. userinput="${result}"
  386. fn_server_info
  387. if [ "${result}" == "${gameservername}" ]; then
  388. fn_install_file
  389. elif [ "${result}" == "" ]; then
  390. echo -e "Install canceled"
  391. else
  392. echo -e "[ FAIL ] menu result does not match gameservername"
  393. echo -e "result: ${result}"
  394. echo -e "gameservername: ${gameservername}"
  395. fi
  396. elif [ "${userinput}" ]; then
  397. fn_server_info
  398. if [ "${userinput}" == "${gameservername}" ] || [ "${userinput}" == "${gamename}" ] || [ "${userinput}" == "${shortname}" ]; then
  399. fn_install_file
  400. else
  401. echo -e "[ FAIL ] Unknown game server"
  402. exit 1
  403. fi
  404. else
  405. fn_install_getopt
  406. fi
  407. # LinuxGSM server mode.
  408. else
  409. core_modules.sh
  410. if [ "${shortname}" != "core-dep" ]; then
  411. # Load LinuxGSM configs.
  412. # These are required to get all the default variables for the specific server.
  413. # Load the default config. If missing download it. If changed reload it.
  414. if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then
  415. mkdir -p "${configdirdefault}/config-lgsm/${gameservername}"
  416. fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  417. fi
  418. if [ ! -f "${configdirserver}/_default.cfg" ]; then
  419. mkdir -p "${configdirserver}"
  420. echo -en "copying _default.cfg\c"
  421. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  422. exitcode=$?
  423. if [ "${exitcode}" -ne 0 ]; then
  424. echo -e " ... FAIL"
  425. exit 1
  426. else
  427. echo -e " ... OK"
  428. fi
  429. else
  430. config_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg")
  431. if [ "${config_file_diff}" != "" ]; then
  432. fn_print_warn_nl "_default.cfg has altered. reloading config."
  433. echo -en "copying _default.cfg...\c"
  434. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  435. exitcode=$?
  436. if [ "${exitcode}" -ne 0 ]; then
  437. echo -e "FAIL"
  438. exit 1
  439. else
  440. echo -e " ... OK"
  441. fi
  442. fi
  443. fi
  444. fi
  445. # Load the IP details before the first config is loaded.
  446. check_ip.sh
  447. # Configs have to be loaded twice to allow start startparameters to pick up all vars
  448. # shellcheck source=/dev/null
  449. source "${configdirserver}/_default.cfg"
  450. # Load the common.cfg config. If missing download it.
  451. if [ ! -f "${configdirserver}/common.cfg" ]; then
  452. fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  453. # shellcheck source=/dev/null
  454. source "${configdirserver}/common.cfg"
  455. else
  456. # shellcheck source=/dev/null
  457. source "${configdirserver}/common.cfg"
  458. fi
  459. # Load the secrets-common.cfg config. If missing download it.
  460. if [ ! -f "${configdirserver}/secrets-common.cfg" ]; then
  461. fn_fetch_config "lgsm/config-default/config-lgsm" "secrets-common-template.cfg" "${configdirserver}" "secrets-common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  462. # shellcheck source=/dev/null
  463. source "${configdirserver}/secrets-common.cfg"
  464. else
  465. # shellcheck source=/dev/null
  466. source "${configdirserver}/secrets-common.cfg"
  467. fi
  468. # Load the instance.cfg config. If missing download it.
  469. if [ ! -f "${configdirserver}/${selfname}.cfg" ]; then
  470. fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  471. # shellcheck source=/dev/null
  472. source "${configdirserver}/${selfname}.cfg"
  473. else
  474. # shellcheck source=/dev/null
  475. source "${configdirserver}/${selfname}.cfg"
  476. fi
  477. # Load the secrets-instance.cfg config. If missing download it.
  478. if [ ! -f "${configdirserver}/secrets-${selfname}.cfg" ]; then
  479. fn_fetch_config "lgsm/config-default/config-lgsm" "secrets-instance-template.cfg" "${configdirserver}" "secrets-${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  480. # shellcheck source=/dev/null
  481. source "${configdirserver}/secrets-${selfname}.cfg"
  482. else
  483. # shellcheck source=/dev/null
  484. source "${configdirserver}/secrets-${selfname}.cfg"
  485. fi
  486. # Reloads start parameter to ensure all vars in startparameters are set.
  487. # Will reload the last defined startparameter.
  488. fn_reload_startparameters() {
  489. # reload Wurm config.
  490. if [ "${shortname}" == "wurm" ]; then
  491. # shellcheck source=/dev/null
  492. source "${servercfgfullpath}"
  493. fi
  494. # reload startparameters.
  495. if grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/secrets-${selfname}.cfg"; then
  496. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/secrets-${selfname}.cfg")"
  497. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/${selfname}.cfg"; then
  498. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/${selfname}.cfg")"
  499. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/secrets-common.cfg"; then
  500. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/secrets-common.cfg")"
  501. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/common.cfg"; then
  502. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/common.cfg")"
  503. elif grep -qE "^[[:blank:]]*startparameters=" "${configdirserver}/_default.cfg"; then
  504. eval startparameters="$(sed -nr 's/^ *startparameters=(.*)$/\1/p' "${configdirserver}/_default.cfg")"
  505. fi
  506. # reload preexecutable.
  507. if grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/secrets-${selfname}.cfg"; then
  508. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/secrets-${selfname}.cfg")"
  509. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/${selfname}.cfg"; then
  510. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/${selfname}.cfg")"
  511. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/secrets-common.cfg"; then
  512. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/secrets-common.cfg")"
  513. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/common.cfg"; then
  514. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/common.cfg")"
  515. elif grep -qE "^[[:blank:]]*preexecutable=" "${configdirserver}/_default.cfg"; then
  516. eval preexecutable="$(sed -nr 's/^ *preexecutable=(.*)$/\1/p' "${configdirserver}/_default.cfg")"
  517. fi
  518. }
  519. # Load the linuxgsm.sh in to tmpdir. If missing download it.
  520. if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
  521. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
  522. fi
  523. # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
  524. fn_ansi_loader
  525. getopt=$1
  526. core_getopt.sh
  527. fi