command_update_linuxgsm.sh 11 KB

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