4
0

command_update_linuxgsm.sh 11 KB

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