linuxgsm.sh 20 KB

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