command_update_linuxgsm.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # LinuxGSM command_update_linuxgsm.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Deletes the functions dir to allow re-downloading of functions from GitHub.
  6. local commandname="UPDATE LinuxGSM"
  7. local commandaction="Update LinuxGSM"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_print_dots "Updating LinuxGSM"
  10. sleep 1
  11. check.sh
  12. fn_script_log_info "Updating LinuxGSM"
  13. echo -ne "\n"
  14. # Check and update _default.cfg
  15. echo -ne " checking config _default.cfg...\c"
  16. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${servername}/_default.cfg" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${servername}/_default.cfg"))
  17. if [ "${config_file_diff}" != "" ]; then
  18. fn_print_update_eol_nl
  19. fn_script_log_info "checking config _default.cfg: UPDATE"
  20. rm -f "${configdirdefault}/config-lgsm/${servername}/_default.cfg"
  21. fn_fetch_config "lgsm/config-default/config-lgsm/${servername}" "_default.cfg" "${configdirdefault}/config-lgsm/${servername}" "_default.cfg" "nochmodx" "norun" "noforce" "nomd5"
  22. else
  23. fn_print_ok_eol_nl
  24. fn_script_log_info "checking config _default.cfg: OK"
  25. fi
  26. echo -ne " checking linuxgsm.sh...\c"
  27. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  28. if [ "${tmp_script_diff}" != "" ]; then
  29. fn_print_update_eol_nl
  30. fn_script_log_info "checking linuxgsm.sh: UPDATE"
  31. rm -f "${tmpdir}/linuxgsm.sh"
  32. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  33. # Compare selfname against linuxgsm.sh in the tmp dir. Ignoring server specific vars.
  34. else
  35. fn_script_log_info "checking linuxgsm.sh: OK"
  36. fn_print_ok_eol_nl
  37. fi
  38. echo -ne " checking ${selfname}...\c"
  39. script_diff=$(diff <(sed '/shortname/d;/servername/d;/gamename/d' "${tmpdir}/linuxgsm.sh") <(sed '/shortname/d;/servername/d;/gamename/d' "${rootdir}/${selfname}"))
  40. if [ "${script_diff}" != "" ]; then
  41. fn_print_update_eol_nl
  42. echo -ne " backup ${selfname}...\c"
  43. mkdir -p "${backupdir}/script/"
  44. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  45. if [ $? -ne 0 ]; then
  46. fn_print_fail_eol_nl
  47. core_exit.sh
  48. else
  49. fn_print_ok_eol_nl
  50. echo -e " Backup: ${tmpdir}/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  51. fi
  52. echo -ne " fetching ${selfname}...\c"
  53. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  54. sed -i "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${rootdir}/${selfname}"
  55. sed -i "s/servername=\"core\"/servername=\"${servername}\"/g" "${rootdir}/${selfname}"
  56. sed -i "s/gamename=\"core\"/gamename=\"${gamename}\"/g" "${rootdir}/${selfname}"
  57. if [ $? -ne 0 ]; then
  58. fn_print_fail_eol_nl
  59. core_exit.sh
  60. else
  61. fn_print_ok_eol_nl
  62. fi
  63. else
  64. fn_print_ok_eol_nl
  65. fi
  66. # Check and update functions
  67. if [ -n "${functionsdir}" ]; then
  68. if [ -d "${functionsdir}" ]; then
  69. cd "${functionsdir}"
  70. for functionfile in *
  71. do
  72. echo -ne " checking function ${functionfile}...\c"
  73. get_function_file=$(${curlpath} --fail -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}")
  74. exitcode=$?
  75. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} --fail -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  76. if [ ${exitcode} -ne 0 ]; then
  77. fn_print_fail_eol_nl
  78. echo -ne " removing unknown function ${functionfile}...\c"
  79. fn_script_log_fatal "removing unknown function ${functionfile}"
  80. rm -f "${functionfile}"
  81. if [ $? -ne 0 ]; then
  82. fn_print_fail_eol_nl
  83. core_exit.sh
  84. else
  85. fn_print_ok_eol_nl
  86. fi
  87. elif [ "${function_file_diff}" != "" ]; then
  88. fn_print_update_eol_nl
  89. fn_script_log_info "checking function ${functionfile}: UPDATE"
  90. rm -rf "${functionsdir}/${functionfile}"
  91. fn_update_function
  92. else
  93. fn_print_ok_eol_nl
  94. fi
  95. done
  96. fi
  97. fi
  98. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  99. fn_print_fail "Updating functions"
  100. fn_script_log_fatal "Updating functions"
  101. else
  102. fn_print_ok "Updating functions"
  103. fn_script_log_pass "Updating functions"
  104. fi
  105. echo -ne "\n"
  106. core_exit.sh