command_update_linuxgsm.sh 11 KB

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