Skip to content

Commit 3f40a95

Browse files
committed
Whoops, should probably commit more often. Massive overhaul. Cleaned up output, less verbose (will still output errors, but gets rid of anything not needed) Added a spinner so users don't think it has stalled
1 parent 5c25c42 commit 3f40a95

File tree

1 file changed

+98
-50
lines changed

1 file changed

+98
-50
lines changed

automated install/basic-install.sh

Lines changed: 98 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
if [[ $EUID -eq 0 ]];then
2222
echo "You are root."
2323
else
24-
echo "sudo will be used for the install."
24+
echo "::: sudo will be used for the install."
2525
# Check if it is actually installed
2626
# If it isn't, exit because the install cannot complete
2727
if [[ $(dpkg-query -s sudo) ]];then
2828
export SUDO="sudo"
2929
else
30-
echo "Please install sudo or run this as root."
30+
echo "::: Please install sudo or run this as root."
3131
exit 1
3232
fi
3333
fi
@@ -53,6 +53,23 @@ availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -
5353
dhcpcdFile=/etc/dhcpcd.conf
5454

5555
####### FUCNTIONS ##########
56+
###All creddit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html
57+
spinner()
58+
{
59+
local pid=$1
60+
local delay=0.001
61+
local spinstr='|/-\'
62+
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
63+
local temp=${spinstr#?}
64+
printf " [%c] " "$spinstr"
65+
local spinstr=$temp${spinstr%"$temp"}
66+
sleep $delay
67+
printf "\b\b\b\b\b\b"
68+
done
69+
printf " \b\b\b\b"
70+
}
71+
72+
5673
backupLegacyPihole()
5774
{
5875
if [[ -f /etc/dnsmasq.d/adList.conf ]];then
@@ -106,7 +123,7 @@ chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1
106123
for desiredInterface in $chooseInterfaceOptions
107124
do
108125
piholeInterface=$desiredInterface
109-
echo "Using interface: $piholeInterface"
126+
echo "::: Using interface: $piholeInterface"
110127
echo ${piholeInterface} > /tmp/piholeINT
111128
done
112129
}
@@ -121,16 +138,34 @@ choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
121138
for choice in $choices
122139
do
123140
case $choice in
124-
IPv4)
125-
echo "IPv4 selected."
126-
useIPv4=true
127-
;;
128-
IPv6)
129-
echo "IPv6 selected."
130-
useIPv6=true
131-
;;
141+
IPv4)useIPv4=true;;
142+
IPv6)useIPv6=true;;
132143
esac
133-
done
144+
done
145+
if [ $useIPv4 ] && [ ! $useIPv6 ]; then
146+
getStaticIPv4Settings
147+
setStaticIPv4
148+
echo "::: Using IPv4 on $IPv4addr"
149+
echo "::: IPv6 will NOT be used."
150+
fi
151+
if [ ! $useIPv4 ] && [ $useIPv6 ]; then
152+
useIPv6dialog
153+
echo "::: IPv4 will NOT be used."
154+
echo "::: Using IPv6 on $piholeIPv6"
155+
fi
156+
if [ $useIPv4 ] && [ $useIPv6 ]; then
157+
getStaticIPv4Settings
158+
setStaticIPv4
159+
useIPv6dialog
160+
echo "::: Using IPv4 on $IPv4addr"
161+
echo "::: Using IPv6 on $piholeIPv6"
162+
fi
163+
if [ ! $useIPv4 ] && [ ! $useIPv6 ]; then
164+
echo "::: Cannot continue, neither IPv4 or IPv6 selected"
165+
echo "::: Exiting"
166+
exit 1
167+
fi
168+
134169
}
135170

136171
useIPv6dialog()
@@ -220,47 +255,69 @@ fi
220255
}
221256

222257
installScripts(){
258+
$SUDO echo " "
259+
$SUDO echo "::: Installing scripts..."
260+
#$SUDO rm /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh
223261
$SUDO curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh
224262
$SUDO curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh
225263
$SUDO curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh
226264
$SUDO curl -o /usr/local/bin/blacklist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/blacklist.sh
227265
$SUDO curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh
228266
$SUDO curl -o /usr/local/bin/updateDashboard.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/updateDashboard.sh
229267
$SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh
268+
$SUDO echo "::: ...done."
230269
}
231270

232271
installConfigs(){
272+
$SUDO echo " "
273+
$SUDO echo "::: Installing configs..."
233274
$SUDO mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
234275
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
235276
$SUDO curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf
236277
$SUDO curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf
237278
$SUDO sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf
279+
$SUDO echo "::: ...done."
238280
}
239281

240282
stopServices(){
283+
$SUDO echo " "
284+
$SUDO echo "::: Stopping services..."
241285
$SUDO service dnsmasq stop || true
242286
$SUDO service lighttpd stop || true
287+
$SUDO echo "::: ...done."
243288
}
244289

245290
installDependencies(){
246-
$SUDO apt-get update
247-
$SUDO apt-get -y upgrade
248-
$SUDO apt-get -y install dnsutils bc toilet figlet
249-
$SUDO apt-get -y install dnsmasq
250-
$SUDO apt-get -y install lighttpd php5-common php5-cgi php5
251-
$SUDO apt-get -y install git
291+
$SUDO echo " "
292+
$SUDO echo "::: Updating apt-get package list"
293+
$SUDO apt-get -qq update & spinner $!
294+
$SUDO echo "::: Upgrading apt-get packages"
295+
$SUDO apt-get -yqq upgrade & spinner $!
296+
$SUDO echo "::: ...done."
297+
$SUDO echo "::: installing dnsutils, bc, toilet, and figlet..."
298+
$SUDO apt-get -yqq install dnsutils bc toilet figlet & spinner $!
299+
$SUDO echo "::: ...done."
300+
$SUDO echo "::: Installing dnsmasq..."
301+
$SUDO apt-get -yqq install dnsmasq & spinner $!
302+
$SUDO echo "::: ...done."
303+
$SUDO echo "::: Installing lighttpd, php5-common, php5-cgi, and php5..."
304+
$SUDO apt-get -yqq install lighttpd php5-common php5-cgi php5 & spinner $!
305+
$SUDO echo "::: ...done."
306+
$SUDO echo "::: Installing git..."
307+
$SUDO apt-get -yqq install git & spinner $!
308+
$SUDO echo "::: ...done."
252309
}
253310

254311
installWebAdmin(){
255312
$SUDO echo " "
313+
$SUDO echo "::: Downloading and installing latest WebAdmin files..."
256314
if [ -d "/var/www/html/admin" ]; then
257315
$SUDO rm -rf /var/www/html/admin
258316
fi
259317
if [ -d "/var/www/html/AdminLTE-master" ]; then
260318
$SUDO rm -rf /var/www/html/AdminLTE-master
261319
fi
262-
$SUDO echo "::: Downloading and installing latest WebAdmin files..."
263-
$SUDO wget -nv https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip
320+
$SUDO wget -nv https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip & spinner $!
264321
$SUDO unzip -oq /var/www/master.zip -d /var/www/html/
265322
$SUDO mv /var/www/html/AdminLTE-master /var/www/html/admin
266323
$SUDO rm /var/www/master.zip 2>/dev/null
@@ -270,38 +327,48 @@ $SUDO echo "::: Creating log file and changing owner to dnsmasq..."
270327
if [ ! -f /var/log/pihole.log ]; then
271328
$SUDO touch /var/log/pihole.log
272329
$SUDO chmod 644 /var/log/pihole.log
273-
$SUDO chown dnsmasq:root /var/log/pihole.log
274-
$SUDO echo "::: ...Done."
330+
$SUDO chown dnsmasq:root /var/log/pihole.log
275331
else
276332
$SUDO echo "::: No need to create, already exists!"
277333
fi
334+
$SUDO echo "::: ...done."
278335

279336
}
280337

281338
installPiholeWeb(){
282339
$SUDO echo " "
340+
$SUDO echo "::: Downloading and installing pihole custom index page..."
283341
if [ -d "/var/www/html/pihole" ]; then
284-
$SUDO echo "::: Existing pihole custom page detected, not overwriting"
285-
else
342+
$SUDO echo "::: Existing page detected, not overwriting"
343+
else
286344
$SUDO mkdir /var/www/html/pihole
287345
$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
288-
$SUDO curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html
346+
$SUDO curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html
289347
fi
348+
$SUDO echo "::: ...done."
290349
}
291350

292351
installCron(){
352+
$SUDO echo " "
353+
$SUDO echo "::: Downloading latest Cron script..."
293354
$SUDO curl -o /etc/cron.d/pihole https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron
355+
$SUDO echo "::: ...done."
294356
}
295357

296-
tidyEtcPihole()
358+
runGravity()
297359
{
360+
$SUDO echo " "
361+
$SUDO echo "::: Preparing to run gravity.sh to refresh hosts..."
298362
if ls /etc/pihole/list* 1> /dev/null 2>&1; then
299-
echo "Cleaning up previous install"
363+
echo "::: Cleaning up previous install (preserving whitelist/blacklist)"
300364
$SUDO rm /etc/pihole/list.*
301365
fi
302-
366+
#Don't run as SUDO, this was causing issues
367+
/usr/local/bin/gravity.sh
368+
$SUDO echo "::: ...done."
303369
}
304370

371+
305372
installPihole()
306373
{
307374
installDependencies
@@ -315,8 +382,8 @@ installConfigs
315382
installWebAdmin
316383
installPiholeWeb
317384
installCron
318-
tidyEtcPihole
319-
/usr/local/bin/gravity.sh
385+
runGravity
386+
320387
}
321388

322389
displayFinalMessage(){
@@ -343,25 +410,6 @@ chooseInterface
343410
# Let the user decide if they want to block ads over IPv4 and/or IPv6
344411
use4andor6
345412

346-
# Decide is IPv4 will be used
347-
if [[ "$useIPv4" = true ]];then
348-
echo "Using IPv4"
349-
getStaticIPv4Settings
350-
setStaticIPv4
351-
else
352-
useIPv4=false
353-
echo "IPv4 will NOT be used."
354-
fi
355-
356-
# Decide is IPv6 will be used
357-
if [[ "$useIPv6" = true ]];then
358-
useIPv6dialog
359-
echo "Using IPv6."
360-
echo "Your IPv6 address is: $piholeIPv6"
361-
else
362-
useIPv6=false
363-
echo "IPv6 will NOT be used."
364-
fi
365413

366414
# Install and log everything to a file
367415
installPihole | tee $tmpLog
@@ -372,4 +420,4 @@ $SUDO mv $tmpLog $instalLogLoc
372420
displayFinalMessage
373421

374422
$SUDO service dnsmasq start
375-
$SUDO service lighttpd start
423+
$SUDO service lighttpd start

0 commit comments

Comments
 (0)