updater.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. ### ghacks-user.js updater for Mac/Linux
  3. ## author: @overdodactyl
  4. ## version: 1.2
  5. ghacksjs="https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js"
  6. echo -e "\nThis script should be run from your Firefox profile directory.\n"
  7. currdir=$(pwd)
  8. ## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed)
  9. sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
  10. ## fallback for Macs without coreutils
  11. if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
  12. ## change directory to the Firefox profile directory
  13. cd "$(dirname "${sfp}")"
  14. echo -e "Updating the user.js for Firefox profile:\n$(pwd)\n"
  15. if [ -e user.js ]; then
  16. echo "Your current user.js file for this profile will be backed up and the latest ghacks version from github will take its place."
  17. echo -e "\nIf currently using the ghacks user.js, please compare versions:"
  18. echo " Available online: $(curl -s ${ghacksjs} | sed -n '4p')"
  19. echo " Currently using: $(sed -n '4p' user.js)"
  20. else
  21. echo "A user.js file does not exist in this profile. If you continue, the latest ghacks version from github will be downloaded."
  22. fi
  23. echo -e "\nIf a user-overrides.js file exists in this profile, it will be appended to the user.js.\n"
  24. read -p "Continue Y/N? " -n 1 -r
  25. echo -e "\n\n"
  26. if [[ $REPLY =~ ^[Yy]$ ]]; then
  27. if [ -e user.js ]; then
  28. # backup current user.js
  29. bakfile="user.js.backup.$(date +"%Y-%m-%d_%H%M")"
  30. mv user.js "${bakfile}" && echo "Your previous user.js file was backed up: ${bakfile}"
  31. fi
  32. # download latest ghacks user.js
  33. echo "downloading latest ghacks user.js file"
  34. curl -O ${ghacksjs} && echo "ghacks user.js has been downloaded"
  35. if [ -e user-overrides.js ]; then
  36. echo "user-overrides.js file found"
  37. cat user-overrides.js >> user.js && echo "user-overrides.js has been appended to user.js"
  38. fi
  39. else
  40. echo "Process aborted"
  41. fi
  42. ## change directory back to the original working directory
  43. cd "${currdir}"