update.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env bash
  2. # Variables
  3. REMOTE_USER_JS_URL="https://raw.githubusercontent.com/arkenfox/user.js/master/user.js"
  4. REMOTE_CLEANER_URL="https://raw.githubusercontent.com/arkenfox/user.js/master/prefsCleaner.sh"
  5. CACHE_DIR="cache"
  6. TEMP_DIR="${CACHE_DIR}/temp"
  7. PROFILE_DIR="profiles"
  8. GLOBAL_PREF_FILE="global.js"
  9. # Functions
  10. confirm_update() {
  11. echo "You are about do download a new version of arkenfox user.js"
  12. echo "and apply it to all profiles..."
  13. local reply
  14. read -p 'Continue? [y/N] ' reply
  15. if [ "${reply}" != 'y' ] && [ "${reply}" != 'Y' ]; then
  16. exit
  17. fi
  18. }
  19. update_cache() {
  20. echo "Updating cache..."
  21. if [ ! -e "${CACHE_DIR}" ]; then
  22. mkdir -p "${CACHE_DIR}"
  23. fi
  24. if [ ! -e "${TEMP_DIR}" ]; then
  25. mkdir -p "${TEMP_DIR}"
  26. fi
  27. curl -o "${CACHE_DIR}/user.js" "${REMOTE_USER_JS_URL}"
  28. curl -o "${CACHE_DIR}/clean.sh" "${REMOTE_CLEANER_URL}"
  29. chmod 0700 "${CACHE_DIR}/clean.sh"
  30. echo "Cahce updated!"
  31. }
  32. clean_profile() {
  33. echo "Cleaning profile '${1}'..."
  34. real="${HOME}/.mozilla/firefox/${1}"
  35. ln "${real}/user.js" "${real}/prefs.js" "${CACHE_DIR}/clean.sh" "${TEMP_DIR}"
  36. old_dir="${PWD}"
  37. cd "${TEMP_DIR}"
  38. ./clean.sh -s >/dev/null
  39. rm -rf user.js prefs.js clean.sh prefsjs_backups
  40. cd "${old_dir}"
  41. echo "Done cleaning profile!"
  42. }
  43. update_profile() {
  44. echo "Updating profile '${1}'..."
  45. override_file="${PROFILE_DIR}/${1}.js"
  46. user_js_content+="$(cat "${CACHE_DIR}/user.js")"
  47. if [ -e "${GLOBAL_PREF_FILE}" ]; then
  48. echo "Aplying global overrides..."
  49. user_js_content+=$'\n\n'"$(cat "${GLOBAL_PREF_FILE}")"
  50. fi
  51. if [ -e "${override_file}" ] && [ "$(cat "${override_file}" | wc -l)" -ne 0 ]; then
  52. echo "Aplying profile overrides..."
  53. user_js_content+=$'\n\n'"$(cat "${override_file}")"
  54. fi
  55. printf '%s' "${user_js_content}" >"${HOME}/.mozilla/firefox/${1}/user.js"
  56. echo "Done upating profile!"
  57. }
  58. update_profiles() {
  59. echo "Updating profiles..."
  60. if ! find "${PROFILE_DIR}" | read; then
  61. echo "No profiles marked for update!"
  62. echo "Exiting..."
  63. exit 1
  64. fi
  65. for file in "${PROFILE_DIR}/"*; do
  66. if printf "${file}" | grep -E '\.js$' >/dev/null 2>&1; then
  67. profile="$(basename "${file::-3}")"
  68. update_profile "${profile}"
  69. clean_profile "${profile}"
  70. else
  71. echo "Not a profile config file: '${file}'!"
  72. fi
  73. done
  74. echo "Update complete. Have a nice day! ^_^"
  75. }
  76. # Perform update
  77. confirm_update
  78. update_cache
  79. update_profiles