uninstall-authohosts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # uninstalls autohosts
  3. function green() {
  4. echo -e "\033[32m$1\033[0m"
  5. }
  6. function red() {
  7. echo -e "\033[0;31m$1\033[0m"
  8. }
  9. function brown() {
  10. echo -e "\033[0;33m$1\033[0m"
  11. }
  12. function purple() {
  13. echo -e "\033[0;35m$1\033[0m"
  14. }
  15. # reused code from autohosts; we can't rely on both files always existing (if the user clones to /tmp, for example)
  16. if [[ $EUID -ne 0 ]]; then
  17. red "This script must be ran as root, or with sudo privileges."
  18. exit 1
  19. fi
  20. REGUSER=$(last | grep "logged in" | grep -o '^\S*' | head -1)
  21. # check os type for home directory path
  22. if [[ "$OSTYPE" != "darwin"* ]];
  23. then
  24. HOME_USER="/home/$REGUSER/autohosts/"
  25. AUTOHOSTS_PATH="/usr/bin/autohosts"
  26. else
  27. # macos
  28. HOME_USER="/Users/$REGUSER/autohosts/"
  29. AUTOHOSTS_PATH="/usr/local/bin/autohosts"
  30. fi
  31. if [ -f /etc/autohosts.conf ];
  32. then
  33. rm /etc/autohosts.conf
  34. green "Config removed..."
  35. else
  36. red "Autohosts config not found, skipping..."
  37. fi
  38. if [ -f "$AUTOHOSTS_PATH" ];
  39. then
  40. rm "$AUTOHOSTS_PATH"
  41. green "Executable removed..."
  42. else
  43. red "Autohosts executable not found, skipping (it may have already been removed)..."
  44. fi
  45. if [ -d "$HOME_USER" ];
  46. then
  47. red "Leaving $HOME_USER - feel free to delete if you don't need it anymore."
  48. fi
  49. crontab -l | grep -v "$AUTOHOSTS_PATH" | crontab
  50. green "Autohosts crontab removed"
  51. cp /etc/hosts /tmp/hosts-backup
  52. echo "0.0.0.0 localhost" > /etc/hosts
  53. green "/etc/hosts has been cleared. You will need to re-add any custom entries."
  54. purple "A backup has been temporarily copied to /tmp/hosts-backup if you need to save something from it.\nDone.\n"
  55. exit 0