-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall.sh
executable file
·85 lines (72 loc) · 2.01 KB
/
install.sh
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
83
84
85
#!/bin/sh
set -euf
# check dependences
checkDep() {
command -v "$1" >/dev/null 2>&1 || {
echo >&2 "hosty requires '$1' but it's not installed."
exit 1
}
}
checkDep curl
echo "======== welcome to hosty installer ========"
echo "======== 4st.li/hosty ========"
echo
echo "checking if user has root access..."
if [ "$(id -u)" != 0 ]; then
echo
if ! prompt=$(sudo -nv 2>&1); then
if ! echo "$prompt" | grep -q '^sudo:'; then
echo "you don't have sudo access, please fix that or run from root."
exit 1
fi
echo "requesting sudo..."
else
echo "using already granted sudo access..."
fi
REQUEST_SUDO=1
else
REQUEST_SUDO=0
echo "OK"
fi
echo
if [ -f /usr/local/bin/hosty ]; then
echo "removing existing hosty..."
if [ "$REQUEST_SUDO" = 1 ]; then
sudo rm /usr/local/bin/hosty
else
rm /usr/local/bin/hosty
fi
echo
fi
echo "installing hosty..."
if [ "$REQUEST_SUDO" = 1 ]; then
sudo curl -L --retry 3 -o /usr/local/bin/hosty https://4st.li/hosty/hosty.sh
else
curl -L --retry 3 -o /usr/local/bin/hosty https://4st.li/hosty/hosty.sh
fi
echo
echo "fixing permissions..."
if [ "$REQUEST_SUDO" = 1 ]; then
sudo chmod 755 /usr/local/bin/hosty
else
chmod 755 /usr/local/bin/hosty
fi
echo
if command -v "crontab" >/dev/null 2>&1; then
echo "do you want to automatically update your hosts file with the latest ads list? (recommended) y/n"
read -r answer </dev/tty
echo
if [ "$answer" = "y" ] || [ "$answer" = "Y" ] || [ "$answer" = "yes" ] || [ "$answer" = "YES" ]; then
if [ "$REQUEST_SUDO" = 1 ]; then
# shellcheck disable=SC2024
sudo /usr/local/bin/hosty -a </dev/tty
else
/usr/local/bin/hosty -a </dev/tty
fi
exit 0
elif [ "$answer" != "n" ] && [ "$answer" != "N" ] && [ "$answer" != "no" ] && [ "$answer" != "NO" ]; then
echo "bad answer, exiting..."
exit 1
fi
fi
echo "done."