linuxgsm.sh 19 KB

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