linuxgsm.sh 19 KB

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