command_update_linuxgsm.sh 10 KB

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