prior-v2-uninstall 1.4 KB

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