A method to update pihole on a remote location


#1

A lot of topics on different forums discuss the danger of automatically updating pihole.
Here’s a way to update only after your approval.

For this to work, you need a public accessible webserver (can be your ISP assigned web space, google drive, onedrive, dropbox, ….)

Here’s the script (like I said before, NOT a Linux expert, always room for improvement…), put the script in /home/pi/updatecheck.sh and make it executable. Edit the URL variable to match the web server you use.

#!/bin/bash

# specify the location to download your approved version info file from
# the filename is NOT included in the URL
# example URL=http://users.telenet.be/userxyz
URL=
file=localversions
piholeversionfile=/etc/pihole
downloadversionfile=/home/pi

# get the local system version info
systemvalue=$(<$piholeversionfile/$file)

# ensure to erase previous downloaded versions
if [ -f "$downloadversionfile/$file" ]; then
	rm $downloadversionfile/$file
fi

# download the approved (by you) version info file from your web location
result=$(sudo wget --timeout=10 --tries=2 $URL/$file -O $downloadversionfile/$file)
if [ $? -ne 0 ]; then
	# exit if wget failed
	exit
else
	# get the version info you approved
	webversion=$(<$downloadversionfile/$file)
fi

if ( ! [ "$systemvalue" == "$webversion" ] ); then
   /usr/local/bin/pihole updatePihole
fi

and make a cron job to execute it ( don’t edit the pihole cron job, It will be overwritten by pihole -up or pihole -r)

sudo nano /etc/cron.d/piholeupdate

content:

 # Pi-hole: Update Pi-hole
30 2    * * 7   root    PATH="$PATH:/home/pi/" /home/pi/updatecheck.sh

Choose a valid time (example = 02h30) and day (example = sunday) or use * for any day

Now all you have to do is put /etc/pihole/localversions from your local system on the web server you use, as soon as you feel safe to allow the upgrade.
Ensure the remote system can get to the file on the web server
done…


Cronjob