33 lines
1.1 KiB
Bash
33 lines
1.1 KiB
Bash
#!/bin/sh
|
|
|
|
## Script for NH-Opti160 to take a backup of pihole configuration, for nanopineo (or other alternate pihole servers) to pick up over SSH on a scheduled task.
|
|
## Author: iRaven
|
|
|
|
## CONFIGURATION OPTIONS BELOW ##
|
|
|
|
# low-privileged user info
|
|
PHTRANSUSR=phtrans
|
|
PHTRANSPWD=nope!
|
|
|
|
## END configuration options ##
|
|
|
|
if [[ $EUID > 0 ]]; then
|
|
echo "Not running as root, exiting"
|
|
exit
|
|
fi
|
|
|
|
## Make the user if it doesc't exist.
|
|
## We're assuming you have a low-privileged user set up for other pihole systems to retrieve the backup file.
|
|
## This gets configured automatically the first time you run this (below), or you can configure this yourself. Don't give it any permissions.
|
|
if [ ! -d "/home/${PHTRANSUSR}" ]; then
|
|
useradd -m -p ${PHTRANSPWD} ${PHTRANSUSR}
|
|
ssh-keygen -C "piholetransfer" -f /home/${PHTRANSUSR}/.ssh/id_rsa
|
|
chown -R ${PHTRANSUSR} /home/${PHTRANSUSR}/
|
|
fi
|
|
|
|
## Backup pi-hole FTL DB
|
|
pihole -a -t /home/${PHTRANSUSR}/phbackup.tar.gz
|
|
|
|
## Copy any custom shit in dnsmasq's config directory to the user, too.
|
|
cp -v /etc/dnsmasq.d/* /home/${PHTRANSUSR}
|