command_update_linuxgsm.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/bin/bash
  2. # LinuxGSM command_update_linuxgsm.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Deletes the modules dir to allow re-downloading of modules from GitHub.
  7. commandname="UPDATE-LGSM"
  8. commandaction="Updating LinuxGSM"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. fn_print_dots ""
  12. check.sh
  13. info_distro.sh
  14. info_game.sh
  15. # Prevent github from using a cached version of the file if dev-debug is enabled.
  16. nocache=()
  17. if [ -f "${rootdir}/.dev-debug" ]; then
  18. nocache=(-H "Cache-Control: no-cache" -H "Pragma: no-cache")
  19. fi
  20. fn_script_log_info "Updating LinuxGSM"
  21. # Keep this module compatible with launchers predating the bootstrap branch check.
  22. if type fn_check_github_branch > /dev/null 2>&1; then
  23. fn_check_github_branch
  24. fi
  25. fn_print_dots "Selecting repo"
  26. fn_script_log_info "Selecting repo"
  27. # Select remotereponame
  28. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1> /dev/null
  29. exitcode=$?
  30. if [ "${exitcode}" -ne "0" ]; then
  31. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1> /dev/null
  32. exitcode=$?
  33. if [ "${exitcode}" -ne "0" ]; then
  34. fn_print_fail_nl "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  35. fn_script_log_fail "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  36. core_exit.sh
  37. else
  38. remotereponame="Bitbucket"
  39. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  40. fi
  41. else
  42. remotereponame="GitHub"
  43. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  44. fi
  45. # Check linuxsm.sh
  46. echo -en "checking ${remotereponame} script [ ${italic}linuxgsm.sh${default} ]\c"
  47. if [ "${remotereponame}" == "GitHub" ]; then
  48. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1> /dev/null
  49. else
  50. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1> /dev/null
  51. fi
  52. exitcode=$?
  53. if [ "${exitcode}" -ne 0 ]; then
  54. fn_print_fail_eol_nl
  55. fn_script_log_fail "Checking ${remotereponame} linuxgsm.sh"
  56. fn_script_log_fail "Curl returned error: ${exitcode}"
  57. core_exit.sh
  58. fi
  59. if [ "${remotereponame}" == "GitHub" ]; then
  60. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  61. else
  62. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh"))
  63. fi
  64. if [ "${tmp_script_diff}" != "" ]; then
  65. fn_print_update_eol_nl
  66. fn_script_log "Checking ${remotereponame} script linuxgsm.sh"
  67. rm -f "${tmpdir:?}/linuxgsm.sh"
  68. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nohash"
  69. else
  70. fn_print_skip_eol_nl
  71. fn_script_log_pass "Checking ${remotereponame} script linuxgsm.sh"
  72. fi
  73. # Check gameserver.sh
  74. # Compare gameserver.sh against linuxgsm.sh in the tmp dir.
  75. # Ignoring server specific vars.
  76. echo -en "checking script [ ${italic}${selfname}${default} ]\c"
  77. fn_script_log_info "Checking ${selfname}"
  78. script_diff=$(diff <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${tmpdir}/linuxgsm.sh") <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${rootdir}/${selfname}"))
  79. if [ "${script_diff}" != "" ]; then
  80. fn_print_update_eol_nl
  81. fn_script_log "Checking script ${selfname}"
  82. echo -en "backup ${selfname}\c"
  83. fn_script_log_info "Backup script ${selfname}"
  84. if [ ! -d "${backupdir}/script" ]; then
  85. mkdir -p "${backupdir}/script"
  86. fi
  87. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  88. exitcode=$?
  89. if [ "${exitcode}" -ne 0 ]; then
  90. fn_print_fail_eol_nl
  91. fn_script_log_fail "Backup ${selfname}"
  92. core_exit.sh
  93. else
  94. fn_print_ok_eol_nl
  95. fn_script_log_pass "Backup script${selfname}"
  96. echo -e "backup location [ ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak ]"
  97. fn_script_log_pass "Backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  98. fi
  99. echo -en "copying ${selfname}"
  100. fn_script_log_info "Copying ${selfname}"
  101. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  102. sed -i "s+shortname=\"core\"+shortname=\"${shortname}\"+g" "${rootdir}/${selfname}"
  103. sed -i "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" "${rootdir}/${selfname}"
  104. sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}"
  105. sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}"
  106. sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}"
  107. sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" "${rootdir}/${selfname}"
  108. exitcode=$?
  109. if [ "${exitcode}" -ne 0 ]; then
  110. fn_print_fail_eol_nl
  111. fn_script_log_fail "copying ${selfname}"
  112. core_exit.sh
  113. else
  114. fn_print_ok_eol_nl
  115. fn_script_log_pass "copying ${selfname}"
  116. fi
  117. else
  118. fn_print_skip_eol_nl
  119. fn_script_log_info "Checking ${selfname}"
  120. fi
  121. # Check _default.cfg.
  122. echo -en "checking ${remotereponame} config [ ${italic}_default.cfg${default} ]\c"
  123. fn_script_log_info "Checking ${remotereponame} config _default.cfg"
  124. if [ "${remotereponame}" == "GitHub" ]; then
  125. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
  126. else
  127. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
  128. fi
  129. exitcode=$?
  130. if [ "${exitcode}" -ne 0 ]; then
  131. fn_print_fail_eol_nl
  132. fn_script_log_fail "Checking ${remotereponame} config _default.cfg"
  133. fn_script_log_fail "Curl returned error: ${exitcode}"
  134. core_exit.sh
  135. fi
  136. if [ "${remotereponame}" == "GitHub" ]; then
  137. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
  138. else
  139. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
  140. fi
  141. if [ "${config_file_diff}" != "" ]; then
  142. fn_print_update_eol_nl
  143. fn_script_log "Checking ${remotereponame} config _default.cfg"
  144. rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
  145. fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nohash"
  146. alert="config"
  147. alert.sh
  148. else
  149. fn_print_skip_eol_nl
  150. fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
  151. fi
  152. # Check distro csv. ${datadir}/${distroid}-${distroversioncsv}.csv
  153. if [ -f "${datadir}/${distroid}-${distroversioncsv}.csv" ]; then
  154. echo -en "checking ${remotereponame} config [ ${italic}${distroid}-${distroversioncsv}.csv${default} ]\c"
  155. fn_script_log_info "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  156. if [ "${remotereponame}" == "GitHub" ]; then
  157. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
  158. else
  159. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
  160. fi
  161. exitcode=$?
  162. if [ "${exitcode}" -ne 0 ]; then
  163. fn_print_fail_eol_nl
  164. fn_script_log_fail "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  165. fn_script_log_fail "Curl returned error: ${exitcode}"
  166. core_exit.sh
  167. fi
  168. if [ "${remotereponame}" == "GitHub" ]; then
  169. config_file_diff=$(diff "${datadir}/${distroid}-${distroversioncsv}.csv" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv"))
  170. else
  171. config_file_diff=$(diff "${datadir}/${distroid}-${distroversioncsv}.csv" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv"))
  172. fi
  173. if [ "${config_file_diff}" != "" ]; then
  174. fn_print_update_eol_nl
  175. fn_script_log "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  176. rm -f "${datadir:?}/${distroid}-${distroversioncsv}.csv"
  177. fn_fetch_file_github "lgsm/data" "${distroid}-${distroversioncsv}.csv" "${datadir}" "nochmodx" "norun" "noforce" "nohash"
  178. else
  179. fn_print_skip_eol_nl
  180. fn_script_log_pass "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  181. fi
  182. fi
  183. # Check and update modules.
  184. if [ -n "${modulesdir}" ]; then
  185. if [ -d "${modulesdir}" ]; then
  186. (
  187. cd "${modulesdir}" || exit
  188. for modulefile in *; do
  189. # check if module exists in the repo and remove if missing.
  190. # commonly used if module names change.
  191. echo -en "checking ${remotereponame} module [ ${italic}${modulefile}${default} ]\c"
  192. github_file_url_dir="lgsm/modules"
  193. if [ "${remotereponame}" == "GitHub" ]; then
  194. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
  195. else
  196. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
  197. fi
  198. exitcode=$?
  199. if [ "${exitcode}" -ne 0 ]; then
  200. fn_print_error_eol_nl
  201. fn_script_log_error "Checking ${remotereponame} module ${modulefile}"
  202. echo -en "removing module ${modulefile}...\c"
  203. if ! rm -f "${modulefile:?}"; then
  204. fn_print_fail_eol_nl
  205. fn_script_log_fail "Removing module ${modulefile}"
  206. core_exit.sh
  207. else
  208. fn_print_ok_eol_nl
  209. fn_script_log_pass "Removing module ${modulefile}"
  210. fi
  211. else
  212. # compare file
  213. if [ "${remotereponame}" == "GitHub" ]; then
  214. module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}"))
  215. else
  216. module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}"))
  217. fi
  218. # results
  219. if [ "${module_file_diff}" != "" ]; then
  220. fn_print_update_eol_nl
  221. fn_script_log "Checking ${remotereponame} module ${modulefile}"
  222. rm -rf "${modulesdir:?}/${modulefile}"
  223. fn_update_module
  224. else
  225. fn_print_skip_eol_nl
  226. fn_script_log_pass "Checking ${remotereponame} module ${modulefile}"
  227. fi
  228. fi
  229. done
  230. )
  231. fi
  232. fi
  233. fn_print_ok_nl "Updating modules"
  234. fn_script_log_pass "Updating modules"
  235. core_exit.sh