This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.sh
executable file
·259 lines (229 loc) · 8.22 KB
/
script.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh
err()
{
echo >&2 "$(tput bold; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)"
}
msg()
{
echo "$(tput bold; tput setaf 48)[+] ${*}$(tput sgr0)"
}
info()
{
echo "$(tput bold; tput setaf 220)[*] ${*}$(tput sgr0)"
}
select_server()
{
PS3=$'\e[01;33m[!] Choose which version you want: \e[0m'
options=(Unfiltered Ad-Block Quit)
select menu in "${options[@]}";
do
if [ "$menu" == "Unfiltered" ]; then
configlink="https://zerologdns.com/stubby.yml"
return 0
elif [ "$menu" == "Ad-Block" ]; then
configlink="https://zerologdns.com/clearnet-stubby.yml"
return 0
elif [ "$menu" == "Quit" ]; then
info "Exited" ; exit 1
else
err "Unexpected answer" ; exit 1 ;
fi
done
}
check_priv()
{
if [ "$(id -u)" -ne 0 ]; then
err "You need to run this as root!"
exit 1
fi
}
check_priv
sys_id()
{
ID=$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
echo $ID
}
message()
{
printf "\n"
echo "$(tput bold; tput setaf 207)[♥] Thank you for using ZeroLogDNS! $(tput sgr0)"
}
sys_id_like()
{
IDLIKE=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' /etc/os-release)
echo $IDLIKE
}
ID="$(sys_id)"
ID_LIKE="$(sys_id_like)"
function yes_no {
while true; do
read -p "$(echo -e "\033[1m\033[38;5;11m$* \e[39m[Y/N] ")" yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) err "Aborted" ; exit 1 ;;
esac
done
}
detect_os()
{
base=$(uname | tr "[:upper:]" "[:lower:]")
if [ $base = "linux" ]; then
if [[ $ID_LIKE = "debian" || $ID_LIKE = "ubuntu" || $ID = "debian" ]]; then
msg "Installing Stubby for Debian Based system"
apt install stubby -y && response="found"
elif [[ $ID_LIKE = "rhel fedora" || $ID = "fedora" ]]; then
msg "Installing Stubby for CentOS/Fedora"
dnf install stubby -y && response="found"
elif [[ $ID = "arch" || $ID = "artix" || $ID_LIKE = "arch" ]]; then
pacman -S stubby --noconfirm && response="found"
msg "Installing Stubby for Arch Linux"
elif [ $ID = "void" ]; then
xbps-install -S stubby --yes && response="found"
msg "Installing Stubby for Void"
elif [ $ID = '"solus"' ]; then
msg "Installing Stubby for Solus OS"
eopkg install stubby && response="found"
else
err "Your system is not supported yet. You have to install the Stubby program manually and rerun the script." ; exit 1
fi
else
err "Your system is not supported yet." ; exit 1
fi
}
nmcli_conf()
{
msg "Configuring network manager with nmcli..."
conn=$(nmcli con show --active | awk -F " " 'FNR == 2 {print $1}')
test_ipv4=$(nmcli con mod "$conn" ipv4.dns 127.0.0.1 2>&1)
test_ipv6=$(nmcli con mod "$conn" ipv6.dns ::1 2>&1)
if [[ "$test_ipv4" == *method=disabled* ]]; then
info "IPV4 is not enabled. Skip NMCLI IPV4 setting."
else
nmcli con mod "$conn" ipv4.dns 127.0.0.1 && nmcli con mod "$conn" ipv4.ignore-auto-dns yes && msg "DNS server is set to 127.0.0.1"
fi
if [[ "$test_ipv6" == *method=disabled* ]]; then
info "IPV6 is not enabled. Skip NMCLI IPV6 setting."
else
nmcli con mod "$conn" ipv6.dns ::1 && nmcli con mod "$conn" ipv6.ignore-auto-dns yes && msg "DNS server is set to ::1"
fi
}
check_dns()
{
info "Testing the DNS configuration."
if [[ $(curl https://t.zerologdns.net 2>/dev/null | sed -En 's/.*"Response":"([^"]*).*/\1/p') == yes ]]; then
msg "Success! You are using zerologdns!"
elif [[ $(curl https://t.zerologdns.net 2>/dev/null | sed -En 's/.*"Response":"([^"]*).*/\1/p') == no ]]; then
info "You still seem to be using a different DNS server than zerologdns!"
info "I will try again after sleeping for 5 seconds."
sleep 5
if [[ $(curl https://t.zerologdns.net 2>/dev/null | sed -En 's/.*"Response":"([^"]*).*/\1/p') == yes ]]; then
msg "Success! You are using zerologdns!"
else
err "Something went wrong, the setup failed! Try rebooting."
info "Contact us on discord: https://zerologdns.com/discord" ; exit 1
fi
else
err "Something went wrong, the setup failed! Try rebooting."
err "Contact us on discord: https://zerologdns.com/discord" ; exit 1cat
fi
}
start_servs()
{
if command -v systemctl &> /dev/null; then
if [[ $1 == "stubby" ]]; then
systemctl enable --now stubby && systemctl restart stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
systemctl restart NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
else
err "Invalid argument" ; exit 1
fi
elif command -v dinitctl 2&> /dev/null; then
if [[ $1 == "stubby" ]]; then
dinitctl enable stubby && dinitctl restart stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
dinitctl restart NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
else
err "Invalid argument" ; exit 1
fi
elif command -v rc-update 2&> /dev/null; then
if [[ $1 == "stubby" ]]; then
rc-update add stubby && rc-service stubby restart && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
rc-service NetworkManager restart && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
fi
elif command -v sv 2&> /dev/null; then
if [ $ID == "artix" ]; then
if [[ $1 == "stubby" ]]; then
ln -s /etc/runit/sv/stubby /run/runit/service && sv restart stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
sv restart NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
fi
else
if [[ $1 == "stubby" ]]; then
ln -s /etc/sv/stubby /run/service && sv restart stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
sv restart NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
fi
fi
elif command -v s6-rc-update 2&> /dev/null; then
if [[ $1 == "stubby" ]]; then
s6-rc-bundle-update -c /etc/s6/rc/compiled add default stubby && s6-svc -r /run/service/Stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
s6-svc -r /run/service/NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
fi
elif command -v 66-enable 2&> /dev/null; then
if [[ $1 == "stubby" ]]; then
66-enable -t default stubby && 66-start -t default stubby && msg "Stubby started." || err "Cannot start stubby"
elif [[ $1 == "net" ]]; then
66-start -t default NetworkManager && msg "NetworkManager restarted." || err "Cannot restart NetworkManager"
fi
fi
}
set_config_path()
{
if [ $ID = '"solus"' ]; then
configfile="/usr/share/defaults/stubby/stubby.yml"
backupfile="/usr/share/defaults/stubby/stubby.yml.bak"
else
configfile="/etc/stubby/stubby.yml"
backupfile="/etc/stubby/stubby.yml.bak"
fi
}
check_stubby()
{
if ! command -v stubby &> /dev/null; then
info "Stubby not Found"
yes_no "[*] Do you want to install stubby?" && detect_os
elif command -v stubby &> /dev/null; then
msg "Stubby found!" ; response="found"
fi
}
select_server
check_stubby
download_configs()
{
info "Downloading stubby config file from: [ $configlink ]"
curl $configlink -o $configfile 2>/dev/null && msg "Success! File is downloaded!" || { err "Cannot download file" ; exit 1; }
}
backup_configs()
{
if [ -f "$backupfile" ]; then
msg "Backup File Found! [$backupfile]"
else
mv $configfile $backupfile && msg "Backup file created: [ $backupfile ]"
fi
}
if [ $response = "found" ]; then
set_config_path
backup_configs
download_configs
start_servs "stubby" || exit 1
nmcli_conf
start_servs "net" || exit 1
msg "Waiting for 3 seconds."
sleep 3
check_dns
message
else
err "Unexpected response!" ; exit 1 ;
fi