command_update_linuxgsm.sh 4.5 KB

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