command_update_linuxgsm.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 commandname="UPDATE LinuxGSM"
  7. local commandaction="Update LinuxGSM"
  8. function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. fn_print_dots "Updating LinuxGSM"
  10. sleep 0.5
  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. alert="config"
  24. alert.sh
  25. else
  26. fn_print_ok_eol_nl
  27. fn_script_log_info "checking config _default.cfg: OK"
  28. fi
  29. echo -ne " checking linuxgsm.sh...\c"
  30. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(${curlpath} -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  31. if [ "${tmp_script_diff}" != "" ]; then
  32. fn_print_update_eol_nl
  33. fn_script_log_info "checking linuxgsm.sh: UPDATE"
  34. rm -f "${tmpdir}/linuxgsm.sh"
  35. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  36. # Compare selfname against linuxgsm.sh in the tmp dir. Ignoring server specific vars.
  37. else
  38. fn_script_log_info "checking linuxgsm.sh: OK"
  39. fn_print_ok_eol_nl
  40. fi
  41. echo -ne " checking ${selfname}...\c"
  42. script_diff=$(diff <(sed '/shortname/d;/gameservername/d;/gamename/d' "${tmpdir}/linuxgsm.sh") <(sed '/shortname/d;/gameservername/d;/gamename/d' "${rootdir}/${selfname}"))
  43. if [ "${script_diff}" != "" ]; then
  44. fn_print_update_eol_nl
  45. echo -ne " backup ${selfname}...\c"
  46. mkdir -p "${backupdir}/script/"
  47. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  48. if [ $? -ne 0 ]; then
  49. fn_print_fail_eol_nl
  50. core_exit.sh
  51. else
  52. fn_print_ok_eol_nl
  53. echo -e " Backup: ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  54. fi
  55. echo -ne " fetching ${selfname}...\c"
  56. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  57. sed -i "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${rootdir}/${selfname}"
  58. sed -i "s/gameservername=\"core\"/gameservername=\"${gameservername}\"/g" "${rootdir}/${selfname}"
  59. sed -i "s/gamename=\"core\"/gamename=\"${gamename}\"/g" "${rootdir}/${selfname}"
  60. if [ $? -ne 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 -ne " checking function ${functionfile}...\c"
  77. github_file_url_dir="lgsm/functions"
  78. get_function_file=$(${curlpath} --fail -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}")
  79. exitcode=$?
  80. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(${curlpath} --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 -ne " removing unknown function ${functionfile}...\c"
  84. fn_script_log_fatal "removing unknown function ${functionfile}"
  85. rm -f "${functionfile}"
  86. if [ $? -ne 0 ]; then
  87. fn_print_fail_eol_nl
  88. core_exit.sh
  89. else
  90. fn_print_ok_eol_nl
  91. fi
  92. elif [ "${function_file_diff}" != "" ]; then
  93. fn_print_update_eol_nl
  94. fn_script_log_info "checking function ${functionfile}: UPDATE"
  95. rm -rf "${functionsdir:?}/${functionfile}"
  96. fn_update_function
  97. else
  98. fn_print_ok_eol_nl
  99. fi
  100. done
  101. fi
  102. fi
  103. if [ "${exitcode}" != "0" ]&&[ -n "${exitcode}" ]; then
  104. fn_print_fail "Updating functions"
  105. fn_script_log_fatal "Updating functions"
  106. else
  107. fn_print_ok "Updating functions"
  108. fn_script_log_pass "Updating functions"
  109. fi
  110. echo -ne "\n"
  111. core_exit.sh