core_dl.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #!/bin/bash
  2. # LinuxGSM core_dl.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: Deals with all downloads for LinuxGSM.
  7. # remote_fileurl: The URL of the file: http://example.com/dl/File.tar.bz2
  8. # local_filedir: location the file is to be saved: /home/server/lgsm/tmp
  9. # local_filename: name of file (this can be different from the url name): file.tar.bz2
  10. # chmodx: Optional, set to "chmodx" to make file executable using chmod +x
  11. # run: Optional, set run to execute the file after download
  12. # forcedl: Optional, force re-download of file even if exists
  13. # md5: Optional, set an md5 sum and will compare it against the file.
  14. #
  15. # Downloads can be defined in code like so:
  16. # fn_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  17. # fn_fetch_file "http://example.com/file.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
  18. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  19. fn_dl_steamcmd(){
  20. fn_print_start_nl "${remotelocation}"
  21. fn_script_log_info "${commandaction} ${selfname}: ${remotelocation}"
  22. if [ -n "${branch}" ]; then
  23. echo -e "Branch: ${branch}"
  24. fn_script_log_info "Branch: ${branch}"
  25. fi
  26. if [ -n "${betapassword}" ]; then
  27. echo -e "Branch password: ${betapassword}"
  28. fn_script_log_info "Branch password: ${betapassword}"
  29. fi
  30. if [ -d "${steamcmddir}" ]; then
  31. cd "${steamcmddir}" || exit
  32. fi
  33. # Unbuffer will allow the output of steamcmd not buffer allowing a smooth output.
  34. # unbuffer us part of the expect package.
  35. if [ "$(command -v unbuffer)" ]; then
  36. unbuffer="unbuffer"
  37. fi
  38. # Validate will be added as a parameter if required.
  39. if [ "${commandname}" == "VALIDATE" ]||[ "${commandname}" == "INSTALL" ]; then
  40. validate="validate"
  41. fi
  42. # To do error checking for SteamCMD the output of steamcmd will be saved to a log.
  43. steamcmdlog="${lgsmlogdir}/${selfname}-steamcmd.log"
  44. # clear previous steamcmd log
  45. if [ -f "${steamcmdlog}" ]; then
  46. rm -f "${steamcmdlog:?}"
  47. fi
  48. counter=0
  49. while [ "${counter}" == "0" ]||[ "${exitcode}" != "0" ]; do
  50. counter=$((counter+1))
  51. # Select SteamCMD parameters
  52. # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands.
  53. if [ "${appid}" == "90" ]; then
  54. # If using a specific branch.
  55. if [ -n "${branch}" ]&&[ -n "${betapassword}" ]; then
  56. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" -beta "${branch}" -betapassword "${betapassword}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  57. elif [ -n "${branch}" ]; then
  58. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  59. else
  60. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  61. fi
  62. # Force Windows Platform type.
  63. elif [ "${shortname}" == "ac" ]||[ "${shortname}" == "jk2" ]; then
  64. if [ -n "${branch}" ]&&[ -n "${betapassword}" ]; then
  65. ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" -betapassword "${betapassword}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  66. elif [ -n "${branch}" ]; then
  67. ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  68. else
  69. ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  70. fi
  71. # All other servers.
  72. else
  73. if [ -n "${branch}" ]&&[ -n "${betapassword}" ]; then
  74. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" -betapassword "${betapassword}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  75. elif [ -n "${branch}" ]; then
  76. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  77. else
  78. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${validate} +quit | uniq | tee -a "${lgsmlog}" "${steamcmdlog}"
  79. fi
  80. fi
  81. # Error checking for SteamCMD. Some errors will loop to try again and some will just exit.
  82. exitcode=$?
  83. if [ -n "$(grep "Error!" "${steamcmdlog}" | tail -1)" ]||[ -n "$(grep "ERROR!" "${steamcmdlog}" | tail -1)" ]; then
  84. # Not enough space.
  85. if [ -n "$(grep "0x202" "${steamcmdlog}" | tail -1)" ]; then
  86. fn_print_failure_nl "${commandaction} ${selfname}: ${remotelocation}: Not enough space to download server files"
  87. fn_script_log_fatal "${commandaction} ${selfname}: ${remotelocation}: Not enough space to download server files"
  88. core_exit.sh
  89. # Need tp purchase game.
  90. elif [ -n "$(grep "No subscription" "${steamcmdlog}" | tail -1)" ]; then
  91. fn_print_failure_nl "${commandaction} ${selfname}: ${remotelocation}: Steam account does not have a license for the required game"
  92. fn_script_log_fatal "${commandaction} ${selfname}: ${remotelocation}: Steam account does not have a license for the required game"
  93. core_exit.sh
  94. # Two-factor authentication failure
  95. elif [ -n "$(grep "Two-factor code mismatch" "${steamcmdlog}" | tail -1)" ]; then
  96. fn_print_failure_nl "${commandaction} ${selfname}: ${remotelocation}: Two-factor authentication failure"
  97. fn_script_log_fatal "${commandaction} ${selfname}: ${remotelocation}: Two-factor authentication failure"
  98. core_exit.sh
  99. # Incorrect Branch password
  100. elif [ -n "$(grep "Password check for AppId" "${steamcmdlog}" | tail -1)" ]; then
  101. fn_print_failure_nl "${commandaction} ${selfname}: ${remotelocation}: betapassword is incorrect"
  102. fn_script_log_fatal "${commandaction} ${selfname}: ${remotelocation}: betapassword is incorrect"
  103. core_exit.sh
  104. # Update did not finish.
  105. elif [ -n "$(grep "0x402" "${steamcmdlog}" | tail -1)" ]||[ -n "$(grep "0x602" "${steamcmdlog}" | tail -1)" ]; then
  106. fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Update required but not completed - check network"
  107. fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Update required but not completed - check network"
  108. else
  109. fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Unknown error occured"
  110. fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Unknown error occured"
  111. fi
  112. elif [ "${exitcode}" != "0" ]; then
  113. fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
  114. fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
  115. else
  116. fn_print_complete_nl "${commandaction} ${selfname}: ${remotelocation}"
  117. fn_script_log_pass "${commandaction} ${selfname}: ${remotelocation}"
  118. fi
  119. if [ "${counter}" -gt "10" ]; then
  120. fn_print_failure_nl "${commandaction} ${selfname}: ${remotelocation}: Did not complete the download, too many retrys"
  121. fn_script_log_fatal "${commandaction} ${selfname}: ${remotelocation}: Did not complete the download, too many retrys"
  122. core_exit.sh
  123. fi
  124. done
  125. }
  126. # Emptys contents of the LinuxGSM tmpdir.
  127. fn_clear_tmp(){
  128. echo -en "clearing LinuxGSM tmp directory..."
  129. if [ -d "${tmpdir}" ]; then
  130. rm -rf "${tmpdir:?}/"*
  131. local exitcode=$?
  132. if [ "${exitcode}" == 0 ]; then
  133. fn_print_ok_eol_nl
  134. fn_script_log_pass "clearing LinuxGSM tmp directory"
  135. else
  136. fn_print_error_eol_nl
  137. fn_script_log_error "clearing LinuxGSM tmp directory"
  138. fi
  139. fi
  140. }
  141. fn_dl_md5(){
  142. # Runs MD5 Check if available.
  143. if [ "${md5}" != "0" ]&&[ "${md5}" != "nomd5" ]; then
  144. echo -en "verifying ${local_filename} with MD5..."
  145. fn_sleep_time
  146. md5sumcmd=$(md5sum "${local_filedir}/${local_filename}"|awk '{print $1;}')
  147. if [ "${md5sumcmd}" != "${md5}" ]; then
  148. fn_print_fail_eol_nl
  149. echo -e "${local_filename} returned MD5 checksum: ${md5sumcmd}"
  150. echo -e "expected MD5 checksum: ${md5}"
  151. fn_script_log_fatal "Verifying ${local_filename} with MD5"
  152. fn_script_log_info "${local_filename} returned MD5 checksum: ${md5sumcmd}"
  153. fn_script_log_info "Expected MD5 checksum: ${md5}"
  154. core_exit.sh
  155. else
  156. fn_print_ok_eol_nl
  157. fn_script_log_pass "Verifying ${local_filename} with MD5"
  158. fn_script_log_info "${local_filename} returned MD5 checksum: ${md5sumcmd}"
  159. fn_script_log_info "Expected MD5 checksum: ${md5}"
  160. fi
  161. fi
  162. }
  163. # Extracts bzip2, gzip or zip files.
  164. # Extracts can be defined in code like so:
  165. # fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdir}"
  166. # fn_dl_extract "/home/gameserver/lgsm/tmp" "file.tar.bz2" "/home/gamserver/serverfiles"
  167. fn_dl_extract(){
  168. local_filedir="${1}"
  169. local_filename="${2}"
  170. extractdir="${3}"
  171. # Extracts archives.
  172. echo -en "extracting ${local_filename}..."
  173. mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
  174. if [ ! -d "${extractdir}" ]; then
  175. mkdir "${extractdir}"
  176. fi
  177. if [ "${mime}" == "application/gzip" ]||[ "${mime}" == "application/x-gzip" ]; then
  178. extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdir}")
  179. elif [ "${mime}" == "application/x-bzip2" ]; then
  180. extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdir}")
  181. elif [ "${mime}" == "application/x-xz" ]; then
  182. extractcmd=$(tar -xf "${local_filedir}/${local_filename}" -C "${extractdir}")
  183. elif [ "${mime}" == "application/zip" ]; then
  184. extractcmd=$(unzip -qo -d "${extractdir}" "${local_filedir}/${local_filename}")
  185. fi
  186. local exitcode=$?
  187. if [ "${exitcode}" != 0 ]; then
  188. fn_print_fail_eol_nl
  189. fn_script_log_fatal "Extracting download"
  190. if [ -f "${lgsmlog}" ]; then
  191. echo -e "${extractcmd}" >> "${lgsmlog}"
  192. fi
  193. echo -e "${extractcmd}"
  194. core_exit.sh
  195. else
  196. fn_print_ok_eol_nl
  197. fn_script_log_pass "Extracting download"
  198. fi
  199. }
  200. # Trap to remove file download if canceled before completed.
  201. fn_fetch_trap(){
  202. echo -e ""
  203. echo -en "downloading ${local_filename}..."
  204. fn_print_canceled_eol_nl
  205. fn_script_log_info "Downloading ${local_filename}...CANCELED"
  206. fn_sleep_time
  207. rm -f "${local_filedir:?}/${local_filename}"
  208. echo -en "downloading ${local_filename}..."
  209. fn_print_removed_eol_nl
  210. fn_script_log_info "Downloading ${local_filename}...REMOVED"
  211. core_exit.sh
  212. }
  213. fn_fetch_file(){
  214. remote_fileurl="${1}"
  215. remote_fileurl_backup="${2}"
  216. remote_fileurl_name="${3}"
  217. remote_fileurl_backup_name="${4}"
  218. local_filedir="${5}"
  219. local_filename="${6}"
  220. chmodx="${7:-0}"
  221. run="${8:-0}"
  222. forcedl="${9:-0}"
  223. md5="${10:-0}"
  224. # Download file if missing or download forced.
  225. if [ ! -f "${local_filedir}/${local_filename}" ]||[ "${forcedl}" == "forcedl" ]; then
  226. # If backup fileurl exists include it.
  227. if [ -n "${remote_fileurl_backup}" ]; then
  228. # counter set to 0 to allow second try
  229. counter=0
  230. remote_fileurls_array=( remote_fileurl remote_fileurl_backup )
  231. else
  232. # counter set to 1 to not allow second try
  233. counter=1
  234. remote_fileurls_array=( remote_fileurl )
  235. fi
  236. for remote_fileurl_array in "${remote_fileurls_array[@]}"; do
  237. if [ "${remote_fileurl_array}" == "remote_fileurl" ]; then
  238. fileurl="${remote_fileurl}"
  239. fileurl_name="${remote_fileurl_name}"
  240. elif [ "${remote_fileurl_array}" == "remote_fileurl_backup" ]; then
  241. fileurl="${remote_fileurl_backup}"
  242. fileurl_name="${remote_fileurl_backup_name}"
  243. fi
  244. counter=$((counter+1))
  245. if [ ! -d "${local_filedir}" ]; then
  246. mkdir -p "${local_filedir}"
  247. fi
  248. # Trap will remove part downloaded files if canceled.
  249. trap fn_fetch_trap INT
  250. # Larger files show a progress bar.
  251. if [ "${local_filename##*.}" == "bz2" ]||[ "${local_filename##*.}" == "gz" ]||[ "${local_filename##*.}" == "zip" ]||[ "${local_filename##*.}" == "jar" ]||[ "${local_filename##*.}" == "xz" ]; then
  252. echo -en "downloading ${local_filename}..."
  253. fn_sleep_time
  254. echo -en "\033[1K"
  255. curlcmd=$(curl --connect-timeout 10 --progress-bar --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
  256. echo -en "downloading ${local_filename}..."
  257. else
  258. echo -en "fetching ${fileurl_name} ${local_filename}...\c"
  259. curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)
  260. fi
  261. local exitcode=$?
  262. # Download will fail if downloads a html file.
  263. if [ -f "${local_filedir}/${local_filename}" ]; then
  264. if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE" )" ]; then
  265. rm "${local_filedir:?}/${local_filename:?}"
  266. local exitcode=2
  267. fi
  268. fi
  269. # On first try will error. On second try will fail.
  270. if [ "${exitcode}" != 0 ]; then
  271. if [ ${counter} -ge 2 ]; then
  272. fn_print_fail_eol_nl
  273. if [ -f "${lgsmlog}" ]; then
  274. fn_script_log_fatal "Downloading ${local_filename}"
  275. fn_script_log_fatal "${fileurl}"
  276. fi
  277. core_exit.sh
  278. else
  279. fn_print_error_eol_nl
  280. if [ -f "${lgsmlog}" ]; then
  281. fn_script_log_error "Downloading ${local_filename}"
  282. fn_script_log_error "${fileurl}"
  283. fi
  284. fi
  285. else
  286. fn_print_ok_eol
  287. sleep 0.3
  288. echo -en "\033[2K\\r"
  289. if [ -f "${lgsmlog}" ]; then
  290. fn_script_log_pass "Downloading ${local_filename}"
  291. fi
  292. # Make file executable if chmodx is set.
  293. if [ "${chmodx}" == "chmodx" ]; then
  294. chmod +x "${local_filedir}/${local_filename}"
  295. fi
  296. # Remove trap.
  297. trap - INT
  298. break
  299. fi
  300. done
  301. fi
  302. if [ -f "${local_filedir}/${local_filename}" ]; then
  303. fn_dl_md5
  304. # Execute file if run is set.
  305. if [ "${run}" == "run" ]; then
  306. # shellcheck source=/dev/null
  307. source "${local_filedir}/${local_filename}"
  308. fi
  309. fi
  310. }
  311. # GitHub file download functions.
  312. # Used to simplify downloading specific files from GitHub.
  313. # github_file_url_dir: the directory of the file in the GitHub: lgsm/functions
  314. # github_file_url_name: the filename of the file to download from GitHub: core_messages.sh
  315. # githuburl: the full GitHub url
  316. # remote_fileurl: The URL of the file: http://example.com/dl/File.tar.bz2
  317. # local_filedir: location the file is to be saved: /home/server/lgsm/tmp
  318. # local_filename: name of file (this can be different from the url name): file.tar.bz2
  319. # chmodx: Optional, set to "chmodx" to make file executable using chmod +x
  320. # run: Optional, set run to execute the file after download
  321. # forcedl: Optional, force re-download of file even if exists
  322. # md5: Optional, set an md5 sum and will compare it against the file.
  323. # Fetches files from the Git repo.
  324. fn_fetch_file_github(){
  325. github_file_url_dir="${1}"
  326. github_file_url_name="${2}"
  327. # For legacy versions - code can be removed at a future date
  328. if [ "${legacymode}" == "1" ]; then
  329. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  330. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  331. # If master branch will currently running LinuxGSM version to prevent "version mixing". This is ignored if a fork.
  332. elif [ "${githubbranch}" == "master" ]&&[ "${githubuser}" == "GameServerManager" ]&&[ "${commandname}" != "UPDATE-LGSM" ]; then
  333. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  334. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  335. else
  336. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  337. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  338. fi
  339. remote_fileurl_name="GitHub"
  340. remote_fileurl_backup_name="Bitbucket"
  341. local_filedir="${3}"
  342. local_filename="${github_file_url_name}"
  343. chmodx="${4:-0}"
  344. run="${5:-0}"
  345. forcedl="${6:-0}"
  346. md5="${7:-0}"
  347. # Passes vars to the file download function.
  348. fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  349. }
  350. # Fetches config files from the Git repo.
  351. fn_fetch_config(){
  352. github_file_url_dir="${1}"
  353. github_file_url_name="${2}"
  354. # If master branch will currently running LinuxGSM version to prevent "version mixing". This is ignored if a fork.
  355. if [ "${githubbranch}" == "master" ]&&[ "${githubuser}" == "GameServerManager" ]&&[ "${commandname}" != "UPDATE-LGSM" ]; then
  356. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  357. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  358. else
  359. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  360. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  361. fi
  362. remote_fileurl_name="GitHub"
  363. remote_fileurl_backup_name="Bitbucket"
  364. local_filedir="${3}"
  365. local_filename="${4}"
  366. chmodx="nochmodx"
  367. run="norun"
  368. forcedl="noforce"
  369. md5="nomd5"
  370. # Passes vars to the file download function.
  371. fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  372. }
  373. # Fetches modules from the Git repo during first download.
  374. fn_fetch_function(){
  375. github_file_url_dir="lgsm/functions"
  376. github_file_url_name="${functionfile}"
  377. # If master branch will currently running LinuxGSM version to prevent "version mixing". This is ignored if a fork.
  378. if [ "${githubbranch}" == "master" ]&&[ "${githubuser}" == "GameServerManager" ]&&[ "${commandname}" != "UPDATE-LGSM" ]; then
  379. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  380. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  381. else
  382. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  383. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  384. fi
  385. remote_fileurl_name="GitHub"
  386. remote_fileurl_backup_name="Bitbucket"
  387. local_filedir="${functionsdir}"
  388. local_filename="${github_file_url_name}"
  389. chmodx="chmodx"
  390. run="run"
  391. forcedl="noforce"
  392. md5="nomd5"
  393. # Passes vars to the file download function.
  394. fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  395. }
  396. # Fetches modules from the Git repo during update-lgsm.
  397. fn_update_function(){
  398. github_file_url_dir="lgsm/functions"
  399. github_file_url_name="${functionfile}"
  400. # If master branch will currently running LinuxGSM version to prevent "version mixing". This is ignored if a fork.
  401. if [ "${githubbranch}" == "master" ]&&[ "${githubuser}" == "GameServerManager" ]&&[ "${commandname}" != "UPDATE-LGSM" ]; then
  402. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  403. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  404. else
  405. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  406. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  407. fi
  408. remote_fileurl_name="GitHub"
  409. remote_fileurl_backup_name="Bitbucket"
  410. local_filedir="${functionsdir}"
  411. local_filename="${github_file_url_name}"
  412. chmodx="chmodx"
  413. run="norun"
  414. forcedl="noforce"
  415. md5="nomd5"
  416. # Passes vars to the file download function.
  417. fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  418. }
  419. # Check that curl is installed
  420. if [ ! "$(command -v curl 2>/dev/null)" ]; then
  421. echo -e "[ FAIL ] Curl is not installed"
  422. exit 1
  423. fi