command_update_linuxgsm.sh 4.4 KB

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