command_update_linuxgsm.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. scriptbackup="${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  84. cp "${rootdir}/${selfname}" "${scriptbackup}"
  85. exitcode=$?
  86. if [ "${exitcode}" -ne 0 ]; then
  87. fn_print_fail_eol_nl
  88. fn_script_log_fail "Backup ${selfname}"
  89. core_exit.sh
  90. else
  91. fn_print_ok_eol_nl
  92. fn_script_log_pass "Backup script ${selfname}"
  93. echo -e "backup location [ ${scriptbackup} ]"
  94. fn_script_log_pass "Backup location ${scriptbackup}"
  95. fi
  96. echo -en "copying ${selfname}"
  97. fn_script_log_info "Copying ${selfname}"
  98. cp "${tmpdir}/linuxgsm.sh" "${tmpdir}/${selfname}.update" \
  99. && sed -i \
  100. -e "s+shortname=\"core\"+shortname=\"${shortname}\"+g" \
  101. -e "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" \
  102. -e "s+gamename=\"core\"+gamename=\"${gamename}\"+g" \
  103. -e "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" \
  104. -e "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" \
  105. -e "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" \
  106. "${tmpdir}/${selfname}.update"
  107. exitcode=$?
  108. if [ "${exitcode}" -ne 0 ]; then
  109. fn_print_fail_eol_nl
  110. fn_script_log_fail "Preparing ${selfname} in ${tmpdir}"
  111. rm -f "${tmpdir:?}/${selfname}.update"
  112. core_exit.sh
  113. fi
  114. cp "${tmpdir}/${selfname}.update" "${rootdir}/${selfname}"
  115. exitcode=$?
  116. rm -f "${tmpdir:?}/${selfname}.update"
  117. if [ "${exitcode}" -ne 0 ]; then
  118. fn_print_fail_eol_nl
  119. fn_script_log_fail "copying ${selfname}"
  120. echo -en "restoring ${selfname} from backup\c"
  121. fn_script_log_info "Restoring ${selfname} from ${scriptbackup}"
  122. if cp "${scriptbackup}" "${rootdir}/${selfname}"; then
  123. fn_print_ok_eol_nl
  124. fn_script_log_pass "Restoring ${selfname} from backup"
  125. else
  126. fn_print_fail_eol_nl
  127. fn_script_log_fail "Restoring ${selfname} from backup ${scriptbackup}"
  128. fi
  129. core_exit.sh
  130. else
  131. fn_print_ok_eol_nl
  132. fn_script_log_pass "copying ${selfname}"
  133. fi
  134. else
  135. fn_print_skip_eol_nl
  136. fn_script_log_info "Checking ${selfname}"
  137. fi
  138. # Check _default.cfg.
  139. echo -en "checking ${remotereponame} config [ ${italic}_default.cfg${default} ]\c"
  140. fn_script_log_info "Checking ${remotereponame} config _default.cfg"
  141. if [ "${remotereponame}" == "GitHub" ]; then
  142. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
  143. else
  144. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
  145. fi
  146. exitcode=$?
  147. if [ "${exitcode}" -ne 0 ]; then
  148. fn_print_fail_eol_nl
  149. fn_script_log_fail "Checking ${remotereponame} config _default.cfg"
  150. fn_script_log_fail "Curl returned error: ${exitcode}"
  151. core_exit.sh
  152. fi
  153. if [ "${remotereponame}" == "GitHub" ]; then
  154. 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"))
  155. else
  156. 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"))
  157. fi
  158. if [ "${config_file_diff}" != "" ]; then
  159. fn_print_update_eol_nl
  160. fn_script_log "Checking ${remotereponame} config _default.cfg"
  161. rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
  162. fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nohash"
  163. alert="config"
  164. alert.sh
  165. else
  166. fn_print_skip_eol_nl
  167. fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
  168. fi
  169. # Check distro csv. ${datadir}/${distroid}-${distroversioncsv}.csv
  170. if [ -f "${datadir}/${distroid}-${distroversioncsv}.csv" ]; then
  171. echo -en "checking ${remotereponame} config [ ${italic}${distroid}-${distroversioncsv}.csv${default} ]\c"
  172. fn_script_log_info "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  173. if [ "${remotereponame}" == "GitHub" ]; then
  174. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
  175. else
  176. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
  177. fi
  178. exitcode=$?
  179. if [ "${exitcode}" -ne 0 ]; then
  180. fn_print_fail_eol_nl
  181. fn_script_log_fail "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  182. fn_script_log_fail "Curl returned error: ${exitcode}"
  183. core_exit.sh
  184. fi
  185. if [ "${remotereponame}" == "GitHub" ]; then
  186. 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"))
  187. else
  188. 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"))
  189. fi
  190. if [ "${config_file_diff}" != "" ]; then
  191. fn_print_update_eol_nl
  192. fn_script_log "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  193. rm -f "${datadir:?}/${distroid}-${distroversioncsv}.csv"
  194. fn_fetch_file_github "lgsm/data" "${distroid}-${distroversioncsv}.csv" "${datadir}" "nochmodx" "norun" "noforce" "nohash"
  195. else
  196. fn_print_skip_eol_nl
  197. fn_script_log_pass "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
  198. fi
  199. fi
  200. # Check and update modules.
  201. if [ -n "${modulesdir}" ]; then
  202. if [ -d "${modulesdir}" ]; then
  203. (
  204. cd "${modulesdir}" || exit
  205. for modulefile in *; do
  206. # check if module exists in the repo and remove if missing.
  207. # commonly used if module names change.
  208. echo -en "checking ${remotereponame} module [ ${italic}${modulefile}${default} ]\c"
  209. github_file_url_dir="lgsm/modules"
  210. if [ "${remotereponame}" == "GitHub" ]; then
  211. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
  212. else
  213. curl "${nocache[@]}" --connect-timeout 3 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
  214. fi
  215. exitcode=$?
  216. if [ "${exitcode}" -ne 0 ]; then
  217. fn_print_error_eol_nl
  218. fn_script_log_error "Checking ${remotereponame} module ${modulefile}"
  219. echo -en "removing module ${modulefile}...\c"
  220. if ! rm -f "${modulefile:?}"; then
  221. fn_print_fail_eol_nl
  222. fn_script_log_fail "Removing module ${modulefile}"
  223. core_exit.sh
  224. else
  225. fn_print_ok_eol_nl
  226. fn_script_log_pass "Removing module ${modulefile}"
  227. fi
  228. else
  229. # compare file
  230. if [ "${remotereponame}" == "GitHub" ]; then
  231. module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}"))
  232. else
  233. module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl "${nocache[@]}" --connect-timeout 3 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}"))
  234. fi
  235. # results
  236. if [ "${module_file_diff}" != "" ]; then
  237. fn_print_update_eol_nl
  238. fn_script_log "Checking ${remotereponame} module ${modulefile}"
  239. rm -rf "${modulesdir:?}/${modulefile}"
  240. fn_update_module
  241. else
  242. fn_print_skip_eol_nl
  243. fn_script_log_pass "Checking ${remotereponame} module ${modulefile}"
  244. fi
  245. fi
  246. done
  247. )
  248. fi
  249. fi
  250. fn_print_ok_nl "Updating modules"
  251. fn_script_log_pass "Updating modules"
  252. core_exit.sh