-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
197 lines (163 loc) · 4.52 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
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
#!/usr/bin/env bash
# shellcheck disable=SC1090
# Unbound-hole: A plugin for Pi-hole
# Take Additional control of your DNS
# Please donate to the Pi-hole project at pi-hole.net/donate
#
# Pi-hole can be installed by running:
# curl -sSL https://install.pi-hole.net | bash
# error handling
set -e
######## VARIABLES #########
# URL to download root.hints file from internic
ROOTSURL=https://www.internic.net/domain/named.root
# temporary download location for root.hints
ROOTSTEMP=/tmp/root.hints
# location to implant root.hints file
ROOTSFILE=/var/lib/unbound/root.hints
# Pi-hole installation detection
PIHOLEDIR=/etc/pihole
PIHOLECONF="${PIHOLEDIR}/setupVars.conf"
# unbound config file
UNBOUNDHOLECONF=/etc/unbound/unbound.conf.d/pi-hole.conf
UNBOUNDHOLECONFTEMP=/tmp/pi-hole.conf
UNBOUNDHOLECONFURL=https://raw.githubusercontent.com/deathbybandaid/Unbound-hole/master/pi-hole.conf
whiptail --msgbox --backtitle "Welcome" --title "Unbound-hole automated installer" "\\n\\nThis installer will adjust your Pi-hole device to double as an All-Around DNS Solution!" 10 80
# Prompt user to install Pi-hole if not already
if [[ -d $PIHOLEDIR ]]
then
echo "Pi-hole detected, proceding with the install!"
else
echo "Pi-hole not detected, exitting."
exit 1
fi
# Prompt user to install Pi-hole if not already
if [[ -f $PIHOLECONF ]]
then
echo "Pi-hole config detected, proceding with the install!"
else
echo "Pi-hole config not detected, exitting."
exit 1
fi
# Pull Pi-hole setup vars
source $PIHOLECONF
# Install unbound
if which unbound >/dev/null;
then
echo "Unbound is already installed"
else
echo "Installing Unbound"
apt-get install -y unbound
fi
# Install root.hints file
echo "Installing root.hints file"
if [[ -f $ROOTSFILE ]]
then
echo "Checking existing file"
SOURCEMODIFIEDLAST=$(curl --silent --head $ROOTSURL | awk -F: '/^Last-Modified/ { print $2 }')
SOURCEMODIFIEDTIME=$(date --date="$SOURCEMODIFIEDLAST" +%s)
LOCALFILEMODIFIEDLAST=$(stat -c %z "$ROOTSFILE")
LOCALFILEMODIFIEDTIME=$(date --date="$LOCALFILEMODIFIEDLAST" +%s)
if [[ $LOCALFILEMODIFIEDTIME -lt $SOURCEMODIFIEDTIME ]]
then
DOWNLOADFRESHROOTS=true
echo "File updated online"
else
echo "File not updated online"
fi
else
DOWNLOADFRESHROOTS=true
echo "File Missing"
fi
if [[ $DOWNLOADFRESHROOTS = true ]]
then
echo "Attempting to download file"
wget -O $ROOTSTEMP $ROOTSURL
FETCHFILESIZE=$(stat -c%s $ROOTSTEMP)
if [[ $FETCHFILESIZE -gt 0 ]]
then
mv $ROOTSTEMP $ROOTSFILE
else
echo "File download failed"
fi
else
echo "Not downloading file"
fi
# Install unbound config file
echo "Installing config file"
if [[ -f $UNBOUNDHOLECONF ]]
then
echo "File already exists"
else
DOWNLOADFRESHCONF=true
echo "File Missing"
fi
if [[ $DOWNLOADFRESHCONF = true ]]
then
echo "Attempting to download file"
wget -O $UNBOUNDHOLECONFTEMP $UNBOUNDHOLECONFURL
FETCHFILESIZE=$(stat -c%s $UNBOUNDHOLECONFTEMP)
if [[ $FETCHFILESIZE -gt 0 ]]
then
echo "File download success"
else
echo "File download failed"
exit 1
fi
else
echo "Not downloading file"
fi
if [[ $DOWNLOADFRESHCONF = true ]]
then
# adapt the configuration
echo "adjusting config based on Pi-hole"
if [[ $IPV4_ADDRESS ]]
then
echo "IPv4 is setup"
else
echo "IPv4 is not setup"
sed -i s/do-ip4\:[[:space:]]yes/do-ip4\:[[:space:]]no/ $UNBOUNDHOLECONFTEMP
fi
if [[ $IPV6_ADDRESS ]]
then
echo "IPv6 is setup"
sed -i s/do-ip6\:[[:space:]]no/do-ip6\:[[:space:]]yes/ $UNBOUNDHOLECONFTEMP
else
echo "IPv6 is not setup"
fi
# move config file
mv $UNBOUNDHOLECONFTEMP $UNBOUNDHOLECONF
fi
echo "Starting Unbound with Pi-hole Config"
service unbound stop
service unbound start
# Test Config on IPv4
if [[ $IPV4_ADDRESS ]]
then
echo "Testing IPv4 configuration on pi-hole.net"
IPFOURSTATUS=$(dig -4 A pi-hole.net @127.0.0.1 -p 5353 +short)
if [[ $IPFOURSTATUS ]]
then
echo "IPv4 test success. Reached pi-hole.net at $IPFOURSTATUS"
fi
fi
# Test Config on IPv6
if [[ $IPV6_ADDRESS ]]
then
echo "Testing IPv6 configuration on pi-hole.net"
IPSIXSTATUS=$(dig -6 AAAA pi-hole.net @::1 -p 5353 +short)
if [[ $IPSIXSTATUS ]]
then
echo "IPv6 test success. Reached pi-hole.net at $IPSIXSTATUS"
fi
fi
# instructions for adding to Pi-hole
if [[ $IPV4_ADDRESS ]]
then
echo "Add 127.0.0.1#5353 to your Pi-hole configuration."
fi
if [[ $IPV6_ADDRESS ]]
then
echo "Add ::1#5353 to your Pi-hole configuration."
fi
whiptail --msgbox --backtitle "Welcome" --title "Unbound-hole automated installer" "\\n\\nSetup Complete!" 10 80