4
0

linuxgsm.sh 20 KB

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