command_update_linuxgsm.sh 10 KB

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