-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuninstall-authohosts
executable file
·82 lines (63 loc) · 1.91 KB
/
uninstall-authohosts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# uninstalls autohosts
function green() {
echo -e "\033[32m$1\033[0m"
}
function red() {
echo -e "\033[0;31m$1\033[0m"
}
function brown() {
echo -e "\033[0;33m$1\033[0m"
}
function purple() {
echo -e "\033[0;35m$1\033[0m"
}
# reused code from autohosts; we can't rely on both files always existing (if the user clones to /tmp, for example)
if [[ $EUID -ne 0 ]]; then
red "This script must be ran as root, or with sudo privileges."
exit 1
fi
REGUSER=$(last | grep "logged in" | grep -o '^\S*' | head -1)
# check os type for home directory path
if [[ "$OSTYPE" != "darwin"* ]];
then
HOME_USER="/home/$REGUSER/autohosts/"
AUTOHOSTS_PATH="/usr/bin/autohosts"
else
# macos
HOME_USER="/Users/$REGUSER/autohosts/"
AUTOHOSTS_PATH="/usr/local/bin/autohosts"
fi
if [ -f /etc/autohosts.conf ];
then
rm /etc/autohosts.conf
green "Config removed..."
else
red "Autohosts config not found, skipping..."
fi
if [ -f "$AUTOHOSTS_PATH" ];
then
rm "$AUTOHOSTS_PATH"
green "Executable removed..."
else
red "Autohosts executable not found, skipping (it may have already been removed)..."
fi
if [ -d "$HOME_USER" ];
then
red "Leaving $HOME_USER - feel free to delete if you don't need it anymore."
fi
if [ ! -e /Library/LaunchAgents/com.github.angela-d-autohosts.plist ];
then
crontab -l | grep -v "$AUTOHOSTS_PATH" | crontab
green "Autohosts crontab removed"
elif [ -e /Library/LaunchAgents/com.github.angela-d-autohosts.plist ];
then
launchctl unload /Library/LaunchAgents/com.github.angela-d-autohosts.plist && echo "Autohosts unloaded"
fi
cp /etc/hosts /tmp/hosts-backup
echo "0.0.0.0 localhost" > /etc/hosts
echo "127.0.0.1 local" >> /etc/hosts
echo "255.255.255.255 broadcasthost" >> /etc/hosts
green "/etc/hosts has been cleared. You will need to re-add any custom entries."
purple "A backup has been temporarily copied to /tmp/hosts-backup if you need to save something from it.\nDone.\n"
exit 0