/
dnscrypt-autoinstall
executable file
·283 lines (254 loc) · 6.71 KB
/
dnscrypt-autoinstall
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
###
# Installation and autoconfigure script for debian'ish systems and dnscrypt.
#
# This script will install pre-req's, make & install dnscrypt and finally set it up
# as a daemon service that runs on system startup. It also gives you the option to
# choose which DNSCrypt service to use and easily reconfigure DNSCrypt and uninstall it.
#
# This script should work on new(er) debian'ish releases.
#
# Author: Simon Clausen <kontakt@simonclausen.dk>
# Version: 0.3
#
# Todo: proper init script, download newest version, handle failed download, fix quirks
#
###
# Are you root?
if [ $(id -u) == 0 ]; then
echo "Error!"
echo ""
echo "You should not run this script directly as root."
exit 1
fi
# Vars for stuff
LSODIUMINST=false
DNSCRYPTINST=false
DNSCRYPTCONF=false
LSODIUMVER=0.6.1
DNSCRYPTVER=1.4.0
LSODIUMURL="https://github.com/jedisct1/libsodium/releases/download/0.6.1"
DNSCRYPTURL="http://download.dnscrypt.org/dnscrypt-proxy"
GPGURL_LS="https://download.libsodium.org/libsodium/releases"
GPGURL_DC="http://download.dnscrypt.org/dnscrypt-proxy"
INITURL="https://raw.github.com/simonclausen/dnscrypt-autoinstall/master/init-scripts"
WHICHRESOLVER=dnscrypteu
# /tmp may be mounted noexec
TMPDIR="$(dirname $0)/dnscrypt-autoinstall"
# Check files and set variables
if [ -e /usr/local/sbin/dnscrypt-proxy ]; then
DNSCRYPTINST=true
fi
if [ -e /usr/local/lib/libsodium.so ]; then
LSODIUMINST=true
fi
if [ -e /etc/init.d/dnscrypt-proxy ]; then
DNSCRYPTCONF=true
fi
config_interface() {
echo ""
echo "Which DNSCrypt service would you like to use?"
echo ""
echo "1) DNSCrypt.eu (Europe - no logs, DNSSEC)"
echo "2) OpenDNS (Anycast)"
echo "3) CloudNS (Australia - no logs, DNSSEC)"
echo "4) OpenNIC (Japan - no logs)"
echo "5) OpenNIC (Europe - no logs)"
echo "6) Soltysiak.com (Europe - no logs, DNSSEC)"
echo ""
read -p "Select an option [1-6]: " OPTION
case $OPTION in
1)
WHICHRESOLVER=dnscrypteu
;;
2)
WHICHRESOLVER=opendns
;;
3)
WHICHRESOLVER=cloudns
;;
4)
WHICHRESOLVER=opennicjp
;;
5)
WHICHRESOLVER=openniceu
;;
6)
WHICHRESOLVER=soltysiak
;;
esac
return 0
}
config_do() {
sudo bash <<EOF
curl --retry 5 -Lo initscript-$WHICHRESOLVER.sh $INITURL/initscript-$WHICHRESOLVER.sh
if [ "$DNSCRYPTCONF" == "true" ]; then
/etc/init.d/dnscrypt-proxy stop
update-rc.d -f dnscrypt-proxy remove
fi
mv initscript-$WHICHRESOLVER.sh /etc/init.d/dnscrypt-proxy
chmod +x /etc/init.d/dnscrypt-proxy
update-rc.d dnscrypt-proxy defaults
/etc/init.d/dnscrypt-proxy start
EOF
return 0
}
import_gpgkey() {
echo "Importing key with ID: $1"
gpg --keyserver keys.gnupg.net --recv-keys $1
if [ $? -ne 0 ]; then
echo "Error importing key $1"
exit 1
fi
}
verify_sig() {
echo "Verifying signature of: ${1%%.sig}"
gpg --verify $1
if [ $? -ne 0 ]; then
echo "Error verifying signature"
exit 1
fi
}
config_del() {
sudo bash <<EOF
/etc/init.d/dnscrypt-proxy stop
update-rc.d -f dnscrypt-proxy remove
rm -f /etc/init.d/dnscrypt-proxy
rm -f /usr/local/sbin/dnscrypt-proxy
deluser dnscrypt
rm -rf /etc/dnscrypt
chattr -i /etc/resolv.conf
mv /etc/resolv.conf-dnscryptbak /etc/resolv.conf
EOF
}
# Debug: Remove after failed install
if [ "$1" == "forcedel" ]; then
config_del
exit
fi
if [ "$DNSCRYPTINST" == "true" ]; then
if [ "$DNSCRYPTCONF" == "true" ]; then
echo ""
echo "Welcome to dnscrypt-autoinstall script."
echo ""
echo "It seems like DNSCrypt was installed and configured by this script."
echo ""
echo "What would you like to do?"
echo ""
echo "1) Configure another DNSCrypt service"
echo "2) Uninstall DNSCrypt and remove the auto-startup config"
echo "3) Exit"
echo ""
read -p "Select an option [1-3]: " OPTION
case $OPTION in
1)
config_interface
config_do
echo "Reconfig done. Quitting."
exit
;;
2)
config_del
echo "DNSCrypt has been removed. Quitting."
exit
;;
3)
echo "Bye!"
exit
;;
esac
else
echo ""
echo "Error!"
echo ""
echo "It seems like DNSCrypt is already installed but"
echo "not configured by this script."
echo ""
echo "Remove DNSCrypt and it's configuration completely"
echo "from the system and run this script again."
echo ""
echo "Quitting."
exit 1
fi
else
if nc -z -w1 127.0.0.1 53; then
echo ""
echo "Error!"
echo ""
echo "It looks like there is already a DNS server"
echo "or forwarder installed and listening on 127.0.0.1."
echo ""
echo "To use DNSCypt, you need to either uninstall it"
echo "or make it listen on another IP than 127.0.0.1."
echo ""
echo "Quitting."
exit 1
else
echo ""
echo "Welcome to dnscrypt-autoinstall script."
echo ""
echo "This will install DNSCrypt and autoconfigure it to run as a daemon at start up."
echo ""
read -n1 -r -p "Press any key to continue..."
clear
echo ""
echo "Would you like to see a list of supported providers?"
read -p "(DNSCrypt.eu is default) [y/n]: " -e -i n SHOWLIST
if [ "$SHOWLIST" == "y" ]; then
config_interface
fi
# Install prereqs and make a working dir
sudo bash <<EOF
apt-get update
apt-get install -y automake libtool build-essential ca-certificates curl
EOF
[ ! -d "$TMPDIR" ] && mkdir $TMPDIR
pushd $TMPDIR
# Import GPG key to verify files
import_gpgkey 1CDEA439
# Is libsodium installed?
if [ "$LSODIUMINST" == "false" ]; then
# Nope? Then let's get it set up
curl --retry 5 -Lo libsodium-$LSODIUMVER.tar.gz $LSODIUMURL/libsodium-$LSODIUMVER.tar.gz
curl --retry 5 -Lo libsodium-$LSODIUMVER.tar.gz.sig $GPGURL_LS/libsodium-$LSODIUMVER.tar.gz.sig
# Verify signature
verify_sig libsodium-$LSODIUMVER.tar.gz.sig
tar -zxf libsodium-$LSODIUMVER.tar.gz
pushd libsodium-$LSODIUMVER
./configure && make && make check && \
sudo bash <<EOF
make install
ldconfig
EOF
popd
fi
# Continue with dnscrypt installation
curl --retry 5 -Lo dnscrypt-proxy-$DNSCRYPTVER.tar.gz $DNSCRYPTURL/dnscrypt-proxy-$DNSCRYPTVER.tar.gz
curl --retry 5 -Lo dnscrypt-proxy-$DNSCRYPTVER.tar.gz.sig $GPGURL_DC/dnscrypt-proxy-$DNSCRYPTVER.tar.gz.sig
# Verify signature
verify_sig dnscrypt-proxy-$DNSCRYPTVER.tar.gz.sig
tar -zxf dnscrypt-proxy-$DNSCRYPTVER.tar.gz
pushd dnscrypt-proxy-$DNSCRYPTVER
./configure && make && \
sudo bash <<EOF
make install
# Add dnscrypt user and homedir
adduser --system --home /etc/dnscrypt/run --shell /bin/false --group \
--disabled-password --disabled-login dnscrypt
EOF
popd
# Set up init script
config_do
# Set up resolv.conf to use dnscrypt
sudo bash <<EOF
mv /etc/resolv.conf /etc/resolv.conf-dnscryptbak
echo "nameserver 127.0.0.1" > /etc/resolv.conf
echo "nameserver 127.0.0.2" >> /etc/resolv.conf
# Dirty but dependable
chattr +i /etc/resolv.conf
EOF
# Clean up
popd
rm -rf $TMPDIR
fi
fi