core_dl.sh 21 KB

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