mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Merge pull request #625 from pi-hole/UpdateMethod
Forget all existing attempts at an update method... this is the one.
This commit is contained in:
commit
fdb0e31a78
10 changed files with 662 additions and 597 deletions
|
@ -47,9 +47,9 @@ fi
|
|||
|
||||
#globals
|
||||
basename=pihole
|
||||
piholeDir=/etc/$basename
|
||||
adList=$piholeDir/gravity.list
|
||||
blacklist=$piholeDir/blacklist.txt
|
||||
piholeDir=/etc/${basename}
|
||||
adList=${piholeDir}/gravity.list
|
||||
blacklist=${piholeDir}/blacklist.txt
|
||||
reload=true
|
||||
addmode=true
|
||||
force=false
|
||||
|
@ -61,9 +61,9 @@ domToRemoveList=()
|
|||
piholeIPfile=/etc/pihole/piholeIP
|
||||
piholeIPv6file=/etc/pihole/.useIPv6
|
||||
|
||||
if [[ -f $piholeIPfile ]];then
|
||||
if [[ -f ${piholeIPfile} ]];then
|
||||
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
|
||||
piholeIP=$(cat $piholeIPfile)
|
||||
piholeIP=$(cat ${piholeIPfile})
|
||||
#rm $piholeIPfile
|
||||
else
|
||||
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
|
||||
|
@ -75,13 +75,13 @@ fi
|
|||
modifyHost=false
|
||||
|
||||
# After setting defaults, check if there's local overrides
|
||||
if [[ -r $piholeDir/pihole.conf ]];then
|
||||
if [[ -r ${piholeDir}/pihole.conf ]];then
|
||||
echo "::: Local calibration requested..."
|
||||
. $piholeDir/pihole.conf
|
||||
. ${piholeDir}/pihole.conf
|
||||
fi
|
||||
|
||||
|
||||
if [[ -f $piholeIPv6file ]];then
|
||||
if [[ -f ${piholeIPv6file} ]];then
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
|
@ -92,14 +92,14 @@ function HandleOther(){
|
|||
if [ -z "$validDomain" ]; then
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
domList=("${domList[@]}" $validDomain)
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
fi
|
||||
}
|
||||
|
||||
function PopBlacklistFile(){
|
||||
#check blacklist file exists, and if not, create it
|
||||
if [[ ! -f $blacklist ]];then
|
||||
touch $blacklist
|
||||
if [[ ! -f ${blacklist} ]];then
|
||||
touch ${blacklist}
|
||||
fi
|
||||
for dom in "${domList[@]}"; do
|
||||
if "$addmode"; then
|
||||
|
@ -113,17 +113,17 @@ function PopBlacklistFile(){
|
|||
function AddDomain(){
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
grep -Ex -q "$1" $blacklist || bool=true
|
||||
if $bool; then
|
||||
grep -Ex -q "$1" ${blacklist} || bool=true
|
||||
if ${bool}; then
|
||||
#domain not found in the blacklist file, add it!
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo "$1" >> $blacklist
|
||||
echo "$1" >> ${blacklist}
|
||||
modifyHost=true
|
||||
echo " done!"
|
||||
else
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: $1 already exists in $blacklist! No need to add"
|
||||
fi
|
||||
fi
|
||||
|
@ -132,15 +132,15 @@ function AddDomain(){
|
|||
function RemoveDomain(){
|
||||
|
||||
bool=false
|
||||
grep -Ex -q "$1" $blacklist || bool=true
|
||||
if $bool; then
|
||||
grep -Ex -q "$1" ${blacklist} || bool=true
|
||||
if ${bool}; then
|
||||
#Domain is not in the blacklist file, no need to Remove
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: $1 is NOT blacklisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the blacklist file, add to a temporary array
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: Un-blacklisting $dom..."
|
||||
fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
|
@ -149,17 +149,17 @@ function RemoveDomain(){
|
|||
}
|
||||
|
||||
function ModifyHostFile(){
|
||||
if $addmode; then
|
||||
if ${addmode}; then
|
||||
#add domains to the hosts file
|
||||
if [[ -r $blacklist ]];then
|
||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||
if [[ -r ${blacklist} ]];then
|
||||
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||
if [[ -n ${piholeIPv6} ]];then
|
||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
|
||||
else
|
||||
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
@ -169,10 +169,10 @@ function ModifyHostFile(){
|
|||
#we need to remove the domains from the blacklist file and the host file
|
||||
echo "::: $dom"
|
||||
echo -n "::: removing from HOSTS file..."
|
||||
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
||||
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList}
|
||||
echo " done!"
|
||||
echo -n "::: removing from blackist.txt..."
|
||||
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
|
||||
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
|
@ -185,12 +185,12 @@ function Reload() {
|
|||
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
if [[ ${dnsmasqPid} ]]; then
|
||||
# service already running - reload config
|
||||
$SUDO killall -s HUP dnsmasq
|
||||
${SUDO} killall -s HUP dnsmasq
|
||||
else
|
||||
# service not running, start it up
|
||||
$SUDO service dnsmasq start
|
||||
${SUDO} service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -223,15 +223,15 @@ done
|
|||
|
||||
PopBlacklistFile
|
||||
|
||||
if $modifyHost || $force; then
|
||||
if ${modifyHost} || ${force}; then
|
||||
ModifyHostFile
|
||||
else
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: No changes need to be made"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $reload; then
|
||||
if ${reload}; then
|
||||
Reload
|
||||
fi
|
||||
|
|
|
@ -21,7 +21,7 @@ function CalcBlockedDomains(){
|
|||
CheckIPv6
|
||||
if [ -e "$gravity" ]; then
|
||||
#Are we IPV6 or IPV4?
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
if [[ -n ${piholeIPv6} ]];then
|
||||
#We are IPV6
|
||||
blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}')
|
||||
else
|
||||
|
@ -43,7 +43,7 @@ function CalcQueriesToday(){
|
|||
|
||||
function CalcblockedToday(){
|
||||
if [ -e "$piLog" ] && [ -e "$gravity" ];then
|
||||
blockedToday=$(cat $piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
else
|
||||
blockedToday="Err."
|
||||
fi
|
||||
|
@ -63,7 +63,7 @@ function CalcPercentBlockedToday(){
|
|||
|
||||
function CheckIPv6(){
|
||||
piholeIPv6file="/etc/pihole/.useIPv6"
|
||||
if [[ -f $piholeIPv6file ]];then
|
||||
if [[ -f ${piholeIPv6file} ]];then
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
|
|
|
@ -43,75 +43,75 @@ fi
|
|||
|
||||
# Ensure the file exists, create if not, clear if exists.
|
||||
if [ ! -f "$DEBUG_LOG" ]; then
|
||||
$SUDO touch $DEBUG_LOG
|
||||
$SUDO chmod 644 $DEBUG_LOG
|
||||
$SUDO chown "$USER":root $DEBUG_LOG
|
||||
${SUDO} touch ${DEBUG_LOG}
|
||||
${SUDO} chmod 644 ${DEBUG_LOG}
|
||||
${SUDO} chown "$USER":root ${DEBUG_LOG}
|
||||
else
|
||||
truncate -s 0 $DEBUG_LOG
|
||||
truncate -s 0 ${DEBUG_LOG}
|
||||
fi
|
||||
|
||||
### Private functions exist here ###
|
||||
function versionCheck {
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "########## Versions Section ###########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "########## Versions Section ###########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
|
||||
TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||
echo "Pi-hole Version: $TMP" >> $DEBUG_LOG
|
||||
echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG}
|
||||
|
||||
TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0)
|
||||
echo "WebUI Version: $TMP" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
echo "WebUI Version: $TMP" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
function distroCheck {
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "######## Distribution Section #########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "######## Distribution Section #########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
|
||||
TMP=$(cat /etc/*release || echo "Failed to find release")
|
||||
echo "Distribution Version: $TMP" >> $DEBUG_LOG
|
||||
echo "Distribution Version: $TMP" >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
function compareWhitelist {
|
||||
if [ ! -f "$WHITELISTMATCHES" ]; then
|
||||
$SUDO touch $WHITELISTMATCHES
|
||||
$SUDO chmod 644 $WHITELISTMATCHES
|
||||
$SUDO chown "$USER":root $WHITELISTMATCHES
|
||||
${SUDO} touch ${WHITELISTMATCHES}
|
||||
${SUDO} chmod 644 ${WHITELISTMATCHES}
|
||||
${SUDO} chown "$USER":root ${WHITELISTMATCHES}
|
||||
else
|
||||
truncate -s 0 $WHITELISTMATCHES
|
||||
truncate -s 0 ${WHITELISTMATCHES}
|
||||
fi
|
||||
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "######## Whitelist Comparison #########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
while read -r line; do
|
||||
TMP=$(grep -w ".* $line$" "$GRAVITYFILE")
|
||||
if [ ! -z "$TMP" ]; then
|
||||
echo "$TMP" >> $DEBUG_LOG
|
||||
echo "$TMP" >> $WHITELISTMATCHES
|
||||
echo "$TMP" >> ${DEBUG_LOG}
|
||||
echo "$TMP" >> ${WHITELISTMATCHES}
|
||||
fi
|
||||
done < "$WHITELISTFILE"
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
function compareBlacklist {
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "######## Blacklist Comparison #########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG
|
||||
grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$BLACKLISTFILE"
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
function testNslookup {
|
||||
TESTURL="doubleclick.com"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############ NSLookup Test ############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ NSLookup Test ############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
# Find a blocked url that has not been whitelisted.
|
||||
if [ -s "$WHITELISTMATCHES" ]; then
|
||||
while read -r line; do
|
||||
|
@ -128,77 +128,77 @@ function testNslookup {
|
|||
done < "$GRAVITYFILE"
|
||||
fi
|
||||
|
||||
echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG
|
||||
nslookup "$TESTURL" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG
|
||||
nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG}
|
||||
nslookup "$TESTURL" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG}
|
||||
nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
function checkProcesses {
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "########### Processes Check ###########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "########### Processes Check ###########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo ":::"
|
||||
echo "::: Logging status of lighttpd and dnsmasq..."
|
||||
PROCESSES=( lighttpd dnsmasq )
|
||||
for i in "${PROCESSES[@]}"
|
||||
do
|
||||
echo "" >> $DEBUG_LOG
|
||||
echo "" >> ${DEBUG_LOG}
|
||||
echo -n "$i" >> "$DEBUG_LOG"
|
||||
echo " processes status:" >> $DEBUG_LOG
|
||||
$SUDO systemctl -l status "$i" >> "$DEBUG_LOG"
|
||||
echo " processes status:" >> ${DEBUG_LOG}
|
||||
${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG"
|
||||
done
|
||||
}
|
||||
|
||||
function debugLighttpd {
|
||||
echo "::: Writing lighttpd to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############ lighttpd.conf ############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ lighttpd.conf ############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$LIGHTTPDFILE" ]
|
||||
then
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> $DEBUG_LOG
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$LIGHTTPDFILE"
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No lighttpd.conf file found!" >> $DEBUG_LOG
|
||||
echo "No lighttpd.conf file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo lighttpd.conf file found\n"
|
||||
fi
|
||||
|
||||
if [ -e "$LIGHTTPDERRFILE" ]
|
||||
then
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "######### lighttpd error.log ##########" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
cat "$LIGHTTPDERRFILE" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No lighttpd error.log file found!" >> $DEBUG_LOG
|
||||
echo "No lighttpd error.log file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo lighttpd error.log file found\n"
|
||||
fi
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
### END FUNCTIONS ###
|
||||
|
||||
### Check Pi internet connections ###
|
||||
# Log the IP addresses of this Pi
|
||||
IPADDR=$($SUDO ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
|
||||
IPADDR=$(${SUDO} ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
|
||||
echo "::: Writing local IPs to debug log"
|
||||
echo "IP Addresses of this Pi:" >> $DEBUG_LOG
|
||||
echo "$IPADDR" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
echo "IP Addresses of this Pi:" >> ${DEBUG_LOG}
|
||||
echo "$IPADDR" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
# Check if we can connect to the local gateway
|
||||
GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error)
|
||||
echo "Gateway check:" >> $DEBUG_LOG
|
||||
echo "$GATEWAY_CHECK" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
echo "Gateway check:" >> ${DEBUG_LOG}
|
||||
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
versionCheck
|
||||
distroCheck
|
||||
|
@ -209,109 +209,109 @@ checkProcesses
|
|||
debugLighttpd
|
||||
|
||||
echo "::: Writing dnsmasq.conf to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############### Dnsmasq ###############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$DNSMASQFILE" ]
|
||||
then
|
||||
#cat $DNSMASQFILE >> $DEBUG_LOG
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> $DEBUG_LOG
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$DNSMASQFILE"
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No dnsmasq.conf file found!" >> $DEBUG_LOG
|
||||
echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo dnsmasq.conf file found!\n"
|
||||
fi
|
||||
|
||||
echo "::: Writing 01-pihole.conf to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "########### 01-pihole.conf ############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$PIHOLECONFFILE" ]
|
||||
then
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> $DEBUG_LOG
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$PIHOLECONFFILE"
|
||||
echo >> $DEBUG_LOG
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No 01-pihole.conf file found!" >> $DEBUG_LOG
|
||||
echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo 01-pihole.conf file found\n"
|
||||
fi
|
||||
|
||||
echo "::: Writing size of gravity.list to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############ gravity.list #############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ gravity.list #############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$GRAVITYFILE" ]
|
||||
then
|
||||
wc -l "$GRAVITYFILE" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
wc -l "$GRAVITYFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No gravity.list file found!" >> $DEBUG_LOG
|
||||
echo "No gravity.list file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo gravity.list file found\n"
|
||||
fi
|
||||
|
||||
# Write the hostname output to compare against entries in /etc/hosts, which is logged next
|
||||
echo "Hostname of this pihole is: " >> $DEBUG_LOG
|
||||
hostname >> $DEBUG_LOG
|
||||
echo "Hostname of this pihole is: " >> ${DEBUG_LOG}
|
||||
hostname >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Writing hosts file to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "################ Hosts ################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "################ Hosts ################" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$HOSTSFILE" ]
|
||||
then
|
||||
cat "$HOSTSFILE" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
cat "$HOSTSFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No hosts file found!" >> $DEBUG_LOG
|
||||
echo "No hosts file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo hosts file found!\n"
|
||||
fi
|
||||
|
||||
### PiHole application specific logging ###
|
||||
echo "::: Writing whitelist to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############## Whitelist ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############## Whitelist ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$WHITELISTFILE" ]
|
||||
then
|
||||
cat "$WHITELISTFILE" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
cat "$WHITELISTFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No whitelist.txt file found!" >> $DEBUG_LOG
|
||||
echo "No whitelist.txt file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo whitelist.txt file found!\n"
|
||||
fi
|
||||
|
||||
echo "::: Writing blacklist to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############## Blacklist ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############## Blacklist ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$BLACKLISTFILE" ]
|
||||
then
|
||||
cat "$BLACKLISTFILE" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
cat "$BLACKLISTFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No blacklist.txt file found!" >> $DEBUG_LOG
|
||||
echo "No blacklist.txt file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo blacklist.txt file found!\n"
|
||||
fi
|
||||
|
||||
echo "::: Writing adlists.list to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############ adlists.list #############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ adlists.list #############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$ADLISTSFILE" ]
|
||||
then
|
||||
cat "$ADLISTSFILE" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
cat "$ADLISTSFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No adlists.list file found... using adlists.default!" >> $DEBUG_LOG
|
||||
echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo adlists.list file found... using adlists.default!\n"
|
||||
fi
|
||||
|
||||
|
@ -320,17 +320,17 @@ fi
|
|||
function dumpPiHoleLog {
|
||||
trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
|
||||
echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############# pihole.log ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############# pihole.log ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$PIHOLELOG" ]
|
||||
then
|
||||
while true; do
|
||||
tail -f "$PIHOLELOG" >> $DEBUG_LOG
|
||||
echo >> $DEBUG_LOG
|
||||
tail -f "$PIHOLELOG" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
done
|
||||
else
|
||||
echo "No pihole.log file found!" >> $DEBUG_LOG
|
||||
echo "No pihole.log file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo pihole.log file found!\n"
|
||||
fi
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ function finalWork {
|
|||
echo "::: Finshed debugging!"
|
||||
echo "::: The degug log can be uploaded to Termbin.com for easier sharing."
|
||||
read -r -p "::: Would you like to upload the log? [y/N] " response
|
||||
case $response in
|
||||
case ${response} in
|
||||
[yY][eE][sS]|[yY])
|
||||
TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999)
|
||||
;;
|
||||
|
|
|
@ -44,12 +44,12 @@ getInitSys() {
|
|||
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285
|
||||
autoLoginPiToConsole() {
|
||||
if [ -e /etc/init.d/lightdm ]; then
|
||||
if [ $SYSTEMD -eq 1 ]; then
|
||||
$SUDO systemctl set-default multi-user.target
|
||||
$SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
|
||||
if [ ${SYSTEMD} -eq 1 ]; then
|
||||
${SUDO} systemctl set-default multi-user.target
|
||||
${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
|
||||
else
|
||||
$SUDO update-rc.d lightdm disable 2
|
||||
$SUDO sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
|
||||
${SUDO} update-rc.d lightdm disable 2
|
||||
${SUDO} sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -66,23 +66,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc
|
|||
|
||||
# Set up the LCD screen based on Adafruits instuctions:
|
||||
# https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install
|
||||
curl -SLs https://apt.adafruit.com/add-pin | $SUDO bash
|
||||
$SUDO apt-get -y install raspberrypi-bootloader
|
||||
$SUDO apt-get -y install adafruit-pitft-helper
|
||||
$SUDO adafruit-pitft-helper -t 28r
|
||||
curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash
|
||||
${SUDO} apt-get -y install raspberrypi-bootloader
|
||||
${SUDO} apt-get -y install adafruit-pitft-helper
|
||||
${SUDO} adafruit-pitft-helper -t 28r
|
||||
|
||||
# Download the cmdline.txt file that prevents the screen from going blank after a period of time
|
||||
$SUDO mv /boot/cmdline.txt /boot/cmdline.orig
|
||||
$SUDO curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt
|
||||
${SUDO} mv /boot/cmdline.txt /boot/cmdline.orig
|
||||
${SUDO} curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt
|
||||
|
||||
# Back up the original file and download the new one
|
||||
$SUDO mv /etc/default/console-setup /etc/default/console-setup.orig
|
||||
$SUDO curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup
|
||||
${SUDO} mv /etc/default/console-setup /etc/default/console-setup.orig
|
||||
${SUDO} curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup
|
||||
|
||||
# Instantly apply the font change to the LCD screen
|
||||
$SUDO setupcon
|
||||
${SUDO} setupcon
|
||||
|
||||
$SUDO reboot
|
||||
${SUDO} reboot
|
||||
|
||||
# Start showing the stats on the screen by running the command on another tty:
|
||||
# http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty
|
||||
|
|
|
@ -55,7 +55,7 @@ is_repo() {
|
|||
# replaces it with the current master branch from github
|
||||
make_repo() {
|
||||
# remove the non-repod interface and clone the interface
|
||||
rm -rf $WEB_INTERFACE_DIR
|
||||
rm -rf ${WEB_INTERFACE_DIR}
|
||||
git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR"
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ fi
|
|||
|
||||
#globals
|
||||
basename=pihole
|
||||
piholeDir=/etc/$basename
|
||||
adList=$piholeDir/gravity.list
|
||||
whitelist=$piholeDir/whitelist.txt
|
||||
piholeDir=/etc/${basename}
|
||||
adList=${piholeDir}/gravity.list
|
||||
whitelist=${piholeDir}/whitelist.txt
|
||||
reload=true
|
||||
addmode=true
|
||||
force=false
|
||||
|
@ -61,9 +61,9 @@ domToRemoveList=()
|
|||
piholeIPfile=/etc/pihole/piholeIP
|
||||
piholeIPv6file=/etc/pihole/.useIPv6
|
||||
|
||||
if [[ -f $piholeIPfile ]];then
|
||||
if [[ -f ${piholeIPfile} ]];then
|
||||
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
|
||||
piholeIP=$(cat $piholeIPfile)
|
||||
piholeIP=$(cat ${piholeIPfile})
|
||||
#rm $piholeIPfile
|
||||
else
|
||||
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
|
||||
|
@ -75,12 +75,12 @@ fi
|
|||
modifyHost=false
|
||||
|
||||
# After setting defaults, check if there's local overrides
|
||||
if [[ -r $piholeDir/pihole.conf ]];then
|
||||
if [[ -r ${piholeDir}/pihole.conf ]];then
|
||||
echo "::: Local calibration requested..."
|
||||
. $piholeDir/pihole.conf
|
||||
. ${piholeDir}/pihole.conf
|
||||
fi
|
||||
|
||||
if [[ -f $piholeIPv6file ]];then
|
||||
if [[ -f ${piholeIPv6file} ]];then
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
|
@ -91,18 +91,18 @@ function HandleOther(){
|
|||
if [ -z "$validDomain" ]; then
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
domList=("${domList[@]}" $validDomain)
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
fi
|
||||
}
|
||||
|
||||
function PopWhitelistFile(){
|
||||
#check whitelist file exists, and if not, create it
|
||||
if [[ ! -f $whitelist ]];then
|
||||
touch $whitelist
|
||||
if [[ ! -f ${whitelist} ]];then
|
||||
touch ${whitelist}
|
||||
fi
|
||||
for dom in "${domList[@]}"
|
||||
do
|
||||
if $addmode; then
|
||||
if ${addmode}; then
|
||||
AddDomain "$dom"
|
||||
else
|
||||
RemoveDomain "$dom"
|
||||
|
@ -114,19 +114,19 @@ function AddDomain(){
|
|||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
|
||||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
grep -Ex -q "$1" ${whitelist} || bool=true
|
||||
if ${bool}; then
|
||||
#domain not found in the whitelist file, add it!
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo -n "::: Adding $1 to $whitelist..."
|
||||
fi
|
||||
echo "$1" >> $whitelist
|
||||
echo "$1" >> ${whitelist}
|
||||
modifyHost=true
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo " done!"
|
||||
fi
|
||||
else
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: $1 already exists in $whitelist, no need to add!"
|
||||
fi
|
||||
fi
|
||||
|
@ -135,10 +135,10 @@ function AddDomain(){
|
|||
function RemoveDomain(){
|
||||
|
||||
bool=false
|
||||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
grep -Ex -q "$1" ${whitelist} || bool=true
|
||||
if ${bool}; then
|
||||
#Domain is not in the whitelist file, no need to Remove
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo "::: $1 is NOT whitelisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
|
@ -152,21 +152,21 @@ function RemoveDomain(){
|
|||
}
|
||||
|
||||
function ModifyHostFile(){
|
||||
if $addmode; then
|
||||
if ${addmode}; then
|
||||
#remove domains in from hosts file
|
||||
if [[ -r $whitelist ]];then
|
||||
if [[ -r ${whitelist} ]];then
|
||||
# Remove whitelist entries
|
||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||
numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
||||
awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
|
||||
awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
|
||||
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
|
||||
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
|
||||
echo "l" >> /etc/pihole/whitelist.tmp
|
||||
grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp
|
||||
rm $adList
|
||||
mv $piholeDir/gravity.tmp $adList
|
||||
rm $piholeDir/whitelist.tmp
|
||||
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
|
||||
rm ${adList}
|
||||
mv ${piholeDir}/gravity.tmp ${adList}
|
||||
rm ${piholeDir}/whitelist.tmp
|
||||
echo " done!"
|
||||
|
||||
fi
|
||||
|
@ -178,18 +178,18 @@ function ModifyHostFile(){
|
|||
do
|
||||
if grep -q "$rdom" /etc/pihole/*.domains; then
|
||||
echo "::: AdLists contain $rdom, re-adding block"
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
if [[ -n ${piholeIPv6} ]];then
|
||||
echo -n "::: Restoring block for $rdom on IPv4 and IPv6..."
|
||||
echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||
echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
|
||||
echo " done!"
|
||||
else
|
||||
echo -n "::: Restoring block for $rdom on IPv4..."
|
||||
echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||
echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
|
||||
echo " done!"
|
||||
fi
|
||||
fi
|
||||
echo -n "::: Removing $rdom from $whitelist..."
|
||||
echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist
|
||||
echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist}
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
|
@ -201,12 +201,12 @@ function Reload() {
|
|||
echo -n "::: Refresh lists in dnsmasq..."
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
if [[ ${dnsmasqPid} ]]; then
|
||||
# service already running - reload config
|
||||
$SUDO killall -s HUP dnsmasq
|
||||
${SUDO} killall -s HUP dnsmasq
|
||||
else
|
||||
# service not running, start it up
|
||||
$SUDO service dnsmasq start
|
||||
${SUDO} service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -239,16 +239,16 @@ done
|
|||
|
||||
PopWhitelistFile
|
||||
|
||||
if $modifyHost || $force; then
|
||||
if ${modifyHost} || ${force}; then
|
||||
ModifyHostFile
|
||||
else
|
||||
if $verbose; then
|
||||
if ${verbose}; then
|
||||
echo ":::"
|
||||
echo "::: No changes need to be made"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $reload; then
|
||||
if ${reload}; then
|
||||
Reload
|
||||
fi
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
|
||||
######## VARIABLES #########
|
||||
|
||||
|
||||
tmpLog=/tmp/pihole-install.log
|
||||
instalLogLoc=/etc/pihole/install.log
|
||||
setupVars=/etc/pihole/setupVars.conf
|
||||
|
||||
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
|
||||
webInterfaceDir="/var/www/html/admin"
|
||||
piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
|
||||
piholeFilesDir="/etc/.pihole"
|
||||
|
||||
useUpdateVars=false
|
||||
|
||||
# Find the rows and columns
|
||||
rows=$(tput lines)
|
||||
|
@ -53,7 +56,7 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
# Compatability
|
||||
# Compatibility
|
||||
if [ -x "$(command -v rpm)" ];then
|
||||
# Fedora Family
|
||||
if [ -x "$(command -v dnf)" ];then
|
||||
|
@ -104,8 +107,8 @@ spinner()
|
|||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
local spinstr=${temp}${spinstr%"$temp"}
|
||||
sleep ${delay}
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
|
@ -119,38 +122,18 @@ findIPRoute() {
|
|||
availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1)
|
||||
}
|
||||
|
||||
backupLegacyPihole() {
|
||||
# This function detects and backups the pi-hole v1 files. It will not do anything to the current version files.
|
||||
if [[ -f /etc/dnsmasq.d/adList.conf ]];then
|
||||
echo "::: Original Pi-hole detected. Initiating sub space transport"
|
||||
$SUDO mkdir -p /etc/pihole/original/
|
||||
$SUDO mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf."$(date "+%Y-%m-%d")"
|
||||
$SUDO mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf."$(date "+%Y-%m-%d")"
|
||||
$SUDO mv /etc/resolv.conf /etc/pihole/original/resolv.conf."$(date "+%Y-%m-%d")"
|
||||
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf."$(date "+%Y-%m-%d")"
|
||||
$SUDO mv /var/www/pihole/index.html /etc/pihole/original/index.html."$(date "+%Y-%m-%d")"
|
||||
if [ ! -d /opt/pihole ]; then
|
||||
$SUDO mkdir /opt/pihole
|
||||
$SUDO chown "$USER":root /opt/pihole
|
||||
$SUDO chmod u+srwx /opt/pihole
|
||||
fi
|
||||
$SUDO mv /opt/pihole/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")"
|
||||
else
|
||||
:
|
||||
fi
|
||||
}
|
||||
|
||||
welcomeDialogs() {
|
||||
# Display the welcome dialog
|
||||
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" $r $c
|
||||
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" ${r} ${c}
|
||||
|
||||
# Support for a part-time dev
|
||||
whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" $r $c
|
||||
whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" ${r} ${c}
|
||||
|
||||
# Explain the need for a static address
|
||||
whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
|
||||
whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
|
||||
|
||||
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." $r $c
|
||||
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." ${r} ${c}
|
||||
}
|
||||
|
||||
|
||||
|
@ -164,7 +147,7 @@ verifyFreeDiskSpace() {
|
|||
# - Unknown free disk space , not a integer
|
||||
if ! [[ "$existing_free_kilobytes" =~ ^([0-9])+$ ]]; then
|
||||
|
||||
whiptail --title "Unknown free disk space" --yesno "We were unable to determine available free disk space on this system.\n\nYou may override this check and force the installation, however, it is not recommended.\n\nWould you like to continue with the installation?" --defaultno --backtitle "Pi-hole" $r $c
|
||||
whiptail --title "Unknown free disk space" --yesno "We were unable to determine available free disk space on this system.\n\nYou may override this check and force the installation, however, it is not recommended.\n\nWould you like to continue with the installation?" --defaultno --backtitle "Pi-hole" ${r} ${c}
|
||||
local choice=$?
|
||||
if (( $choice != 0 )); then
|
||||
|
||||
|
@ -190,13 +173,13 @@ verifyFreeDiskSpace() {
|
|||
chooseInterface() {
|
||||
# Turn the available interfaces into an array so it can be used with a whiptail dialog
|
||||
interfacesArray=()
|
||||
firstloop=1
|
||||
firstLoop=1
|
||||
|
||||
while read -r line
|
||||
do
|
||||
mode="OFF"
|
||||
if [[ $firstloop -eq 1 ]]; then
|
||||
firstloop=0
|
||||
if [[ ${firstLoop} -eq 1 ]]; then
|
||||
firstLoop=0
|
||||
mode="ON"
|
||||
fi
|
||||
interfacesArray+=("$line" "available" "$mode")
|
||||
|
@ -204,12 +187,12 @@ chooseInterface() {
|
|||
|
||||
# Find out how many interfaces are available to choose from
|
||||
interfaceCount=$(echo "$availableInterfaces" | wc -l)
|
||||
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" $r $c $interfaceCount)
|
||||
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" ${r} ${c} ${interfaceCount})
|
||||
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
|
||||
if [[ $? = 0 ]]; then
|
||||
for desiredInterface in $chooseInterfaceOptions
|
||||
for desiredInterface in ${chooseInterfaceOptions}
|
||||
do
|
||||
piholeInterface=$desiredInterface
|
||||
piholeInterface=${desiredInterface}
|
||||
echo "::: Using interface: $piholeInterface"
|
||||
echo "${piholeInterface}" > /tmp/piholeINT
|
||||
done
|
||||
|
@ -229,38 +212,38 @@ cleanupIPv6() {
|
|||
|
||||
use4andor6() {
|
||||
# Let use select IPv4 and/or IPv6
|
||||
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" $r $c 2)
|
||||
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2)
|
||||
options=(IPv4 "Block ads over IPv4" on
|
||||
IPv6 "Block ads over IPv6" off)
|
||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||
if [[ $? = 0 ]];then
|
||||
for choice in $choices
|
||||
for choice in ${choices}
|
||||
do
|
||||
case $choice in
|
||||
case ${choice} in
|
||||
IPv4 ) useIPv4=true;;
|
||||
IPv6 ) useIPv6=true;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $useIPv4 ] && [ ! $useIPv6 ]; then
|
||||
if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then
|
||||
getStaticIPv4Settings
|
||||
setStaticIPv4
|
||||
echo "::: Using IPv4 on $IPv4addr"
|
||||
echo "::: IPv6 will NOT be used."
|
||||
fi
|
||||
if [ ! $useIPv4 ] && [ $useIPv6 ]; then
|
||||
if [ ! ${useIPv4} ] && [ ${useIPv6} ]; then
|
||||
useIPv6dialog
|
||||
echo "::: IPv4 will NOT be used."
|
||||
echo "::: Using IPv6 on $piholeIPv6"
|
||||
fi
|
||||
if [ $useIPv4 ] && [ $useIPv6 ]; then
|
||||
if [ ${useIPv4} ] && [ ${useIPv6} ]; then
|
||||
getStaticIPv4Settings
|
||||
setStaticIPv4
|
||||
useIPv6dialog
|
||||
echo "::: Using IPv4 on $IPv4addr"
|
||||
echo "::: Using IPv6 on $piholeIPv6"
|
||||
fi
|
||||
if [ ! $useIPv4 ] && [ ! $useIPv6 ]; then
|
||||
if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
|
||||
echo "::: Cannot continue, neither IPv4 or IPv6 selected"
|
||||
echo "::: Exiting"
|
||||
exit 1
|
||||
|
@ -275,41 +258,41 @@ use4andor6() {
|
|||
useIPv6dialog() {
|
||||
# Show the IPv6 address used for blocking
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." $r $c
|
||||
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c}
|
||||
|
||||
$SUDO touch /etc/pihole/.useIPv6
|
||||
${SUDO} touch /etc/pihole/.useIPv6
|
||||
}
|
||||
|
||||
getStaticIPv4Settings() {
|
||||
# Ask if the user wants to use DHCP settings as their static IP
|
||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
|
||||
IP address: $IPv4addr
|
||||
Gateway: $IPv4gw" $r $c) then
|
||||
Gateway: $IPv4gw" ${r} ${c}); then
|
||||
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
|
||||
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
|
||||
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
|
||||
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." $r $c
|
||||
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." ${r} ${c}
|
||||
#piholeIP is saved to a permanent file so gravity.sh can use it when updating
|
||||
$SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP
|
||||
${SUDO} echo "${IPv4addr%/*}" > /etc/pihole/piholeIP
|
||||
# Nothing else to do since the variables are already set above
|
||||
else
|
||||
# Otherwise, we need to ask the user to input their desired settings.
|
||||
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
|
||||
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
|
||||
until [[ $ipSettingsCorrect = True ]]
|
||||
until [[ ${ipSettingsCorrect} = True ]]
|
||||
do
|
||||
# Ask for the IPv4 address
|
||||
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c "$IPv4addr" 3>&1 1>&2 2>&3)
|
||||
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "$IPv4addr" 3>&1 1>&2 2>&3)
|
||||
if [[ $? = 0 ]];then
|
||||
echo "::: Your static IPv4 address: $IPv4addr"
|
||||
# Ask for the gateway
|
||||
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c "$IPv4gw" 3>&1 1>&2 2>&3)
|
||||
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "$IPv4gw" 3>&1 1>&2 2>&3)
|
||||
if [[ $? = 0 ]];then
|
||||
echo "::: Your static IPv4 gateway: $IPv4gw"
|
||||
# Give the user a chance to review their settings before moving on
|
||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
||||
IP address: $IPv4addr
|
||||
Gateway: $IPv4gw" $r $c)then
|
||||
Gateway: $IPv4gw" ${r} ${c}); then
|
||||
# If the settings are correct, then we need to set the piholeIP
|
||||
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script. piholeIP is saved to a permanent file so gravity.sh can use it when updating
|
||||
$SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP
|
||||
|
@ -342,7 +325,7 @@ setDHCPCD() {
|
|||
echo "## interface $piholeInterface
|
||||
static ip_address=$IPv4addr
|
||||
static routers=$IPv4gw
|
||||
static domain_name_servers=$IPv4gw" | $SUDO tee -a /etc/dhcpcd.conf >/dev/null
|
||||
static domain_name_servers=$IPv4gw" | ${SUDO} tee -a /etc/dhcpcd.conf >/dev/null
|
||||
}
|
||||
|
||||
setStaticIPv4() {
|
||||
|
@ -352,33 +335,33 @@ setStaticIPv4() {
|
|||
echo "::: Static IP already configured"
|
||||
else
|
||||
setDHCPCD
|
||||
$SUDO ip addr replace dev "$piholeInterface" "$IPv4addr"
|
||||
${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr"
|
||||
echo ":::"
|
||||
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
|
||||
echo ":::"
|
||||
fi
|
||||
elif [[ -f /etc/sysconfig/network-scripts/ifcfg-$piholeInterface ]];then
|
||||
elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then
|
||||
# Fedora Family
|
||||
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-$piholeInterface
|
||||
if grep -q "$IPv4addr" $IFCFG_FILE; then
|
||||
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface}
|
||||
if grep -q "$IPv4addr" ${IFCFG_FILE}; then
|
||||
echo "::: Static IP already configured"
|
||||
else
|
||||
IPADDR=$(echo $IPv4addr | cut -f1 -d/)
|
||||
CIDR=$(echo $IPv4addr | cut -f2 -d/)
|
||||
IPADDR=$(echo ${IPv4addr} | cut -f1 -d/)
|
||||
CIDR=$(echo ${IPv4addr} | cut -f2 -d/)
|
||||
# Backup existing interface configuration:
|
||||
cp $IFCFG_FILE $IFCFG_FILE.backup-$(date +%Y-%m-%d-%H%M%S)
|
||||
cp ${IFCFG_FILE} ${IFCFG_FILE}.backup-$(date +%Y-%m-%d-%H%M%S)
|
||||
# Build Interface configuration file:
|
||||
$SUDO echo "# Configured via Pi-Hole installer" > $IFCFG_FILE
|
||||
$SUDO echo "DEVICE=$piholeInterface" >> $IFCFG_FILE
|
||||
$SUDO echo "BOOTPROTO=none" >> $IFCFG_FILE
|
||||
$SUDO echo "ONBOOT=yes" >> $IFCFG_FILE
|
||||
$SUDO echo "IPADDR=$IPADDR" >> $IFCFG_FILE
|
||||
$SUDO echo "PREFIX=$CIDR" >> $IFCFG_FILE
|
||||
$SUDO echo "USERCTL=no" >> $IFCFG_FILE
|
||||
$SUDO ip addr replace dev "$piholeInterface" "$IPv4addr"
|
||||
${SUDO} echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE}
|
||||
${SUDO} echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE}
|
||||
${SUDO} echo "BOOTPROTO=none" >> ${IFCFG_FILE}
|
||||
${SUDO} echo "ONBOOT=yes" >> ${IFCFG_FILE}
|
||||
${SUDO} echo "IPADDR=$IPADDR" >> ${IFCFG_FILE}
|
||||
${SUDO} echo "PREFIX=$CIDR" >> ${IFCFG_FILE}
|
||||
${SUDO} echo "USERCTL=no" >> ${IFCFG_FILE}
|
||||
${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr"
|
||||
if [ -x "$(command -v nmcli)" ];then
|
||||
# Tell NetworkManager to read our new sysconfig file
|
||||
$SUDO nmcli con load $IFCFG_FILE > /dev/null
|
||||
${SUDO} nmcli con load ${IFCFG_FILE} > /dev/null
|
||||
fi
|
||||
echo ":::"
|
||||
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
|
||||
|
@ -396,20 +379,20 @@ function valid_ip()
|
|||
local ip=$1
|
||||
local stat=1
|
||||
|
||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
OIFS=$IFS
|
||||
IFS='.'
|
||||
ip=($ip)
|
||||
IFS=$OIFS
|
||||
ip=(${ip})
|
||||
IFS=${OIFS}
|
||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||
stat=$?
|
||||
fi
|
||||
return $stat
|
||||
return ${stat}
|
||||
}
|
||||
|
||||
setDNS(){
|
||||
DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." $r $c 6)
|
||||
DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6)
|
||||
DNSChooseOptions=(Google "" on
|
||||
OpenDNS "" off
|
||||
Level3 "" off
|
||||
|
@ -418,7 +401,7 @@ setDNS(){
|
|||
Custom "" off)
|
||||
DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty)
|
||||
if [[ $? = 0 ]];then
|
||||
case $DNSchoices in
|
||||
case ${DNSchoices} in
|
||||
Google)
|
||||
echo "::: Using Google DNS servers."
|
||||
piholeDNS1="8.8.8.8"
|
||||
|
@ -445,45 +428,45 @@ setDNS(){
|
|||
piholeDNS2="8.20.247.20"
|
||||
;;
|
||||
Custom)
|
||||
until [[ $DNSSettingsCorrect = True ]]
|
||||
until [[ ${DNSSettingsCorrect} = True ]]
|
||||
do
|
||||
strInvalid="Invalid"
|
||||
if [ ! $piholeDNS1 ]; then
|
||||
if [ ! $piholeDNS2 ]; then
|
||||
if [ ! ${piholeDNS1} ]; then
|
||||
if [ ! ${piholeDNS2} ]; then
|
||||
prePopulate=""
|
||||
else
|
||||
prePopulate=", $piholeDNS2"
|
||||
fi
|
||||
elif [ $piholeDNS1 ] && [ ! $piholeDNS2 ]; then
|
||||
elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then
|
||||
prePopulate="$piholeDNS1"
|
||||
elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then
|
||||
elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then
|
||||
prePopulate="$piholeDNS1, $piholeDNS2"
|
||||
fi
|
||||
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3)
|
||||
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "$prePopulate" 3>&1 1>&2 2>&3)
|
||||
if [[ $? = 0 ]];then
|
||||
piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
||||
piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
||||
if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then
|
||||
piholeDNS1=$strInvalid
|
||||
piholeDNS1=${strInvalid}
|
||||
fi
|
||||
if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then
|
||||
piholeDNS2=$strInvalid
|
||||
piholeDNS2=${strInvalid}
|
||||
fi
|
||||
else
|
||||
echo "::: Cancel selected, exiting...."
|
||||
exit 1
|
||||
fi
|
||||
if [[ $piholeDNS1 == "$strInvalid" ]] || [[ $piholeDNS2 == "$strInvalid" ]]; then
|
||||
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c
|
||||
if [[ $piholeDNS1 == "$strInvalid" ]]; then
|
||||
if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then
|
||||
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c}
|
||||
if [[ ${piholeDNS1} == "$strInvalid" ]]; then
|
||||
piholeDNS1=""
|
||||
fi
|
||||
if [[ $piholeDNS2 == "$strInvalid" ]]; then
|
||||
if [[ ${piholeDNS2} == "$strInvalid" ]]; then
|
||||
piholeDNS2=""
|
||||
fi
|
||||
DNSSettingsCorrect=False
|
||||
else
|
||||
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then
|
||||
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c}); then
|
||||
DNSSettingsCorrect=True
|
||||
else
|
||||
# If the settings are wrong, the loop continues
|
||||
|
@ -508,106 +491,106 @@ versionCheckDNSmasq(){
|
|||
newFileToInstall="/etc/.pihole/advanced/01-pihole.conf"
|
||||
newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf"
|
||||
|
||||
if [ -f $dnsFile1 ]; then
|
||||
if [ -f ${dnsFile1} ]; then
|
||||
echo -n "::: Existing dnsmasq.conf found..."
|
||||
if grep -q $dnsSearch $dnsFile1; then
|
||||
if grep -q ${dnsSearch} ${dnsFile1}; then
|
||||
echo " it is from a previous pi-hole install."
|
||||
echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
|
||||
$SUDO mv -f $dnsFile1 $dnsFile2
|
||||
${SUDO} mv -f ${dnsFile1} ${dnsFile2}
|
||||
echo " done."
|
||||
echo -n "::: Restoring default dnsmasq.conf..."
|
||||
$SUDO cp $defaultFile $dnsFile1
|
||||
${SUDO} cp ${defaultFile} ${dnsFile1}
|
||||
echo " done."
|
||||
else
|
||||
echo " it is not a pi-hole file, leaving alone!"
|
||||
fi
|
||||
else
|
||||
echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..."
|
||||
$SUDO cp $defaultFile $dnsFile1
|
||||
${SUDO} cp ${defaultFile} ${dnsFile1}
|
||||
echo " done."
|
||||
fi
|
||||
|
||||
echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..."
|
||||
$SUDO cp $newFileToInstall $newFileFinalLocation
|
||||
${SUDO} cp ${newFileToInstall} ${newFileFinalLocation}
|
||||
echo " done."
|
||||
$SUDO sed -i "s/@INT@/$piholeInterface/" $newFileFinalLocation
|
||||
${SUDO} sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation}
|
||||
if [[ "$piholeDNS1" != "" ]]; then
|
||||
$SUDO sed -i "s/@DNS1@/$piholeDNS1/" $newFileFinalLocation
|
||||
${SUDO} sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation}
|
||||
else
|
||||
$SUDO sed -i '/^server=@DNS1@/d' $newFileFinalLocation
|
||||
${SUDO} sed -i '/^server=@DNS1@/d' ${newFileFinalLocation}
|
||||
fi
|
||||
if [[ "$piholeDNS2" != "" ]]; then
|
||||
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" $newFileFinalLocation
|
||||
${SUDO} sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation}
|
||||
else
|
||||
$SUDO sed -i '/^server=@DNS2@/d' $newFileFinalLocation
|
||||
${SUDO} sed -i '/^server=@DNS2@/d' ${newFileFinalLocation}
|
||||
fi
|
||||
$SUDO sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' $dnsFile1
|
||||
${SUDO} sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1}
|
||||
}
|
||||
|
||||
installScripts() {
|
||||
# Install the scripts from /etc/.pihole to their various locations
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo -n "::: Installing scripts to /opt/pihole..."
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo -n "::: Installing scripts to /opt/pihole..."
|
||||
if [ ! -d /opt/pihole ]; then
|
||||
$SUDO mkdir /opt/pihole
|
||||
$SUDO chown "$USER":root /opt/pihole
|
||||
$SUDO chmod u+srwx /opt/pihole
|
||||
${SUDO} mkdir /opt/pihole
|
||||
${SUDO} chown "$USER":root /opt/pihole
|
||||
${SUDO} chmod u+srwx /opt/pihole
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh
|
||||
$SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh
|
||||
$SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD,version}.sh
|
||||
$SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole
|
||||
$SUDO chmod 755 /usr/local/bin/pihole
|
||||
$SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole
|
||||
${SUDO} cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh
|
||||
${SUDO} cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh
|
||||
${SUDO} cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh
|
||||
${SUDO} chmod 755 /opt/pihole/gravity.sh /opt/pihole/chronometer.sh /opt/pihole/whitelist.sh /opt/pihole/blacklist.sh /opt/pihole/piholeLogFlush.sh /opt/pihole/updateDashboard.sh /opt/pihole/uninstall.sh /opt/pihole/setupLCD.sh /opt/pihole/version.sh
|
||||
${SUDO} cp /etc/.pihole/pihole /usr/local/bin/pihole
|
||||
${SUDO} chmod 755 /usr/local/bin/pihole
|
||||
${SUDO} cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole
|
||||
. /etc/bash_completion.d/pihole
|
||||
|
||||
#Tidy up /usr/local/bin directory if installing over previous install.
|
||||
oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug)
|
||||
for i in "${oldFiles[@]}"; do
|
||||
if [ -f "/usr/local/bin/$i.sh" ]; then
|
||||
$SUDO rm /usr/local/bin/"$i".sh
|
||||
${SUDO} rm /usr/local/bin/"$i".sh
|
||||
fi
|
||||
done
|
||||
|
||||
$SUDO echo " done."
|
||||
${SUDO} echo " done."
|
||||
}
|
||||
|
||||
installConfigs() {
|
||||
# Install the configs from /etc/.pihole to their various locations
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo "::: Installing configs..."
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo "::: Installing configs..."
|
||||
versionCheckDNSmasq
|
||||
if [ ! -d "/etc/lighttpd" ]; then
|
||||
$SUDO mkdir /etc/lighttpd
|
||||
$SUDO chown "$USER":root /etc/lighttpd
|
||||
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
|
||||
${SUDO} mkdir /etc/lighttpd
|
||||
${SUDO} chown "$USER":root /etc/lighttpd
|
||||
${SUDO} mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/advanced/$LIGHTTPD_CFG /etc/lighttpd/lighttpd.conf
|
||||
$SUDO mkdir -p /var/run/lighttpd
|
||||
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/run/lighttpd
|
||||
$SUDO mkdir -p /var/cache/lighttpd/compress
|
||||
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/cache/lighttpd/compress
|
||||
${SUDO} cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf
|
||||
${SUDO} mkdir -p /var/run/lighttpd
|
||||
${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd
|
||||
${SUDO} mkdir -p /var/cache/lighttpd/compress
|
||||
${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress
|
||||
}
|
||||
|
||||
stopServices() {
|
||||
# Stop dnsmasq and lighttpd
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo -n "::: Stopping services..."
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo -n "::: Stopping services..."
|
||||
#$SUDO service dnsmasq stop & spinner $! || true
|
||||
if [ -x "$(command -v systemctl)" ]; then
|
||||
$SUDO systemctl stop lighttpd & spinner $! || true
|
||||
${SUDO} systemctl stop lighttpd & spinner $! || true
|
||||
else
|
||||
$SUDO service lighttpd stop & spinner $! || true
|
||||
${SUDO} service lighttpd stop & spinner $! || true
|
||||
fi
|
||||
$SUDO echo " done."
|
||||
${SUDO} echo " done."
|
||||
}
|
||||
|
||||
installerDependencies() {
|
||||
|
@ -617,7 +600,7 @@ installerDependencies() {
|
|||
# if so, advise the user to run apt-get update/upgrade at their own discretion
|
||||
#Check to see if apt-get update has already been run today
|
||||
# it needs to have been run at least once on new installs!
|
||||
timestamp=$(stat -c %Y $PKG_CACHE)
|
||||
timestamp=$(stat -c %Y ${PKG_CACHE})
|
||||
timestampAsDate=$(date -d @"$timestamp" "+%b %e")
|
||||
today=$(date "+%b %e")
|
||||
|
||||
|
@ -625,15 +608,15 @@ installerDependencies() {
|
|||
#update package lists
|
||||
echo ":::"
|
||||
echo -n "::: $PKG_MANAGER update has not been run today. Running now..."
|
||||
$SUDO $UPDATE_PKG_CACHE > /dev/null 2>&1
|
||||
${SUDO} ${UPDATE_PKG_CACHE} > /dev/null 2>&1
|
||||
echo " done!"
|
||||
fi
|
||||
echo ":::"
|
||||
echo -n "::: Checking $PKG_MANAGER for upgraded packages...."
|
||||
updatesToInstall=$(eval "$SUDO $PKG_COUNT")
|
||||
updatesToInstall=$(eval "${SUDO} ${PKG_COUNT}")
|
||||
echo " done!"
|
||||
echo ":::"
|
||||
if [[ $updatesToInstall -eq "0" ]]; then
|
||||
if [[ ${updatesToInstall} -eq "0" ]]; then
|
||||
echo "::: Your pi is up to date! Continuing with pi-hole installation..."
|
||||
else
|
||||
echo "::: There are $updatesToInstall updates availible for your pi!"
|
||||
|
@ -644,10 +627,10 @@ installerDependencies() {
|
|||
echo "::: Checking installer dependencies..."
|
||||
for i in "${INSTALLER_DEPS[@]}"; do
|
||||
echo -n "::: Checking for $i..."
|
||||
package_check $i > /dev/null
|
||||
package_check ${i} > /dev/null
|
||||
if ! [ $? -eq 0 ]; then
|
||||
echo -n " Not found! Installing...."
|
||||
$SUDO $PKG_INSTALL "$i" > /dev/null 2>&1
|
||||
${SUDO} ${PKG_INSTALL} "$i" > /dev/null 2>&1
|
||||
echo " done!"
|
||||
else
|
||||
echo " already installed!"
|
||||
|
@ -661,10 +644,10 @@ checkForDependencies() {
|
|||
|
||||
for i in "${PIHOLE_DEPS[@]}"; do
|
||||
echo -n "::: Checking for $i..."
|
||||
package_check $i > /dev/null
|
||||
package_check ${i} > /dev/null
|
||||
if ! [ $? -eq 0 ]; then
|
||||
echo -n " Not found! Installing...."
|
||||
$SUDO $PKG_INSTALL "$i" > /dev/null & spinner $!
|
||||
${SUDO} ${PKG_INSTALL} "$i" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
else
|
||||
echo " already installed!"
|
||||
|
@ -676,18 +659,18 @@ getGitFiles() {
|
|||
# Setup git repos for base files and web admin
|
||||
echo ":::"
|
||||
echo "::: Checking for existing base files..."
|
||||
if is_repo $piholeFilesDir; then
|
||||
make_repo $piholeFilesDir $piholeGitUrl
|
||||
if is_repo ${piholeFilesDir}; then
|
||||
make_repo ${piholeFilesDir} ${piholeGitUrl}
|
||||
else
|
||||
update_repo $piholeFilesDir
|
||||
update_repo ${piholeFilesDir}
|
||||
fi
|
||||
|
||||
echo ":::"
|
||||
echo "::: Checking for existing web interface..."
|
||||
if is_repo $webInterfaceDir; then
|
||||
make_repo $webInterfaceDir $webInterfaceGitUrl
|
||||
if is_repo ${webInterfaceDir}; then
|
||||
make_repo ${webInterfaceDir} ${webInterfaceGitUrl}
|
||||
else
|
||||
update_repo $webInterfaceDir
|
||||
update_repo ${webInterfaceDir}
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -705,8 +688,8 @@ is_repo() {
|
|||
make_repo() {
|
||||
# Remove the non-repod interface and clone the interface
|
||||
echo -n "::: Cloning $2 into $1..."
|
||||
$SUDO rm -rf "$1"
|
||||
$SUDO git clone -q "$2" "$1" > /dev/null & spinner $!
|
||||
${SUDO} rm -rf "$1"
|
||||
${SUDO} git clone -q "$2" "$1" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
|
@ -714,7 +697,7 @@ update_repo() {
|
|||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
cd "$1" || exit
|
||||
$SUDO git pull -q > /dev/null & spinner $!
|
||||
${SUDO} git pull -q > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
|
@ -722,59 +705,59 @@ update_repo() {
|
|||
CreateLogFile() {
|
||||
# Create logfiles if necessary
|
||||
echo ":::"
|
||||
$SUDO echo -n "::: Creating log file and changing owner to dnsmasq..."
|
||||
${SUDO} echo -n "::: Creating log file and changing owner to dnsmasq..."
|
||||
if [ ! -f /var/log/pihole.log ]; then
|
||||
$SUDO touch /var/log/pihole.log
|
||||
$SUDO chmod 644 /var/log/pihole.log
|
||||
$SUDO chown dnsmasq:root /var/log/pihole.log
|
||||
$SUDO echo " done!"
|
||||
${SUDO} touch /var/log/pihole.log
|
||||
${SUDO} chmod 644 /var/log/pihole.log
|
||||
${SUDO} chown dnsmasq:root /var/log/pihole.log
|
||||
${SUDO} echo " done!"
|
||||
else
|
||||
$SUDO echo " already exists!"
|
||||
${SUDO} echo " already exists!"
|
||||
fi
|
||||
}
|
||||
|
||||
installPiholeWeb() {
|
||||
# Install the web interface
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo -n "::: Installing pihole custom index page..."
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo -n "::: Installing pihole custom index page..."
|
||||
if [ -d "/var/www/html/pihole" ]; then
|
||||
$SUDO echo " Existing page detected, not overwriting"
|
||||
${SUDO} echo " Existing page detected, not overwriting"
|
||||
else
|
||||
$SUDO mkdir /var/www/html/pihole
|
||||
${SUDO} mkdir /var/www/html/pihole
|
||||
if [ -f /var/www/html/index.lighttpd.html ]; then
|
||||
$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
|
||||
${SUDO} mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
|
||||
else
|
||||
printf "\n:::\tNo default index.lighttpd.html file found... not backing up"
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/advanced/index.* /var/www/html/pihole/.
|
||||
$SUDO echo " done!"
|
||||
${SUDO} cp /etc/.pihole/advanced/index.* /var/www/html/pihole/.
|
||||
${SUDO} echo " done!"
|
||||
fi
|
||||
# Install Sudoer file
|
||||
echo -n "::: Installing sudoer file..."
|
||||
$SUDO mkdir -p /etc/sudoers.d/
|
||||
$SUDO cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole
|
||||
$SUDO chmod 0440 /etc/sudoers.d/pihole
|
||||
${SUDO} mkdir -p /etc/sudoers.d/
|
||||
${SUDO} cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole
|
||||
${SUDO} chmod 0440 /etc/sudoers.d/pihole
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
installCron() {
|
||||
# Install the cron job
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo -n "::: Installing latest Cron script..."
|
||||
$SUDO cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole
|
||||
$SUDO echo " done!"
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo -n "::: Installing latest Cron script..."
|
||||
${SUDO} cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole
|
||||
${SUDO} echo " done!"
|
||||
}
|
||||
|
||||
runGravity() {
|
||||
# Rub gravity.sh to build blacklists
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo "::: Preparing to run gravity.sh to refresh hosts..."
|
||||
${SUDO} echo ":::"
|
||||
${SUDO} echo "::: Preparing to run gravity.sh to refresh hosts..."
|
||||
if ls /etc/pihole/list* 1> /dev/null 2>&1; then
|
||||
echo "::: Cleaning up previous install (preserving whitelist/blacklist)"
|
||||
$SUDO rm /etc/pihole/list.*
|
||||
${SUDO} rm /etc/pihole/list.*
|
||||
fi
|
||||
echo "::: Running gravity.sh"
|
||||
$SUDO /opt/pihole/gravity.sh
|
||||
${SUDO} /opt/pihole/gravity.sh
|
||||
}
|
||||
|
||||
setUser(){
|
||||
|
@ -784,45 +767,58 @@ setUser(){
|
|||
echo "::: User 'pihole' already exists"
|
||||
else
|
||||
echo "::: User 'pihole' doesn't exist. Creating..."
|
||||
$SUDO useradd -r -s /usr/sbin/nologin pihole
|
||||
${SUDO} useradd -r -s /usr/sbin/nologin pihole
|
||||
fi
|
||||
}
|
||||
|
||||
configureFirewall() {
|
||||
# Allow HTTP and DNS traffic
|
||||
if [ -x "$(command -v firewall-cmd)" ]; then
|
||||
$SUDO firewall-cmd --state > /dev/null
|
||||
${SUDO} firewall-cmd --state > /dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
$SUDO echo "::: Configuring firewalld for httpd and dnsmasq.."
|
||||
$SUDO firewall-cmd --permanent --add-port=80/tcp
|
||||
$SUDO firewall-cmd --permanent --add-port=53/tcp
|
||||
$SUDO firewall-cmd --permanent --add-port=53/udp
|
||||
$SUDO firewall-cmd --reload
|
||||
${SUDO} echo "::: Configuring firewalld for httpd and dnsmasq.."
|
||||
${SUDO} firewall-cmd --permanent --add-port=80/tcp
|
||||
${SUDO} firewall-cmd --permanent --add-port=53/tcp
|
||||
${SUDO} firewall-cmd --permanent --add-port=53/udp
|
||||
${SUDO} firewall-cmd --reload
|
||||
fi
|
||||
elif [ -x "$(command -v iptables)" ]; then
|
||||
$SUDO echo "::: Configuring iptables for httpd and dnsmasq.."
|
||||
$SUDO iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
|
||||
$SUDO iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
|
||||
$SUDO iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
|
||||
${SUDO} echo "::: Configuring iptables for httpd and dnsmasq.."
|
||||
${SUDO} iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
|
||||
${SUDO} iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
|
||||
${SUDO} iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
|
||||
else
|
||||
$SUDO echo "::: No firewall detected.. skipping firewall configuration."
|
||||
${SUDO} echo "::: No firewall detected.. skipping firewall configuration."
|
||||
fi
|
||||
}
|
||||
|
||||
finalExports() {
|
||||
#If it already exists, lets overwrite it with the new values.
|
||||
if [[ -f ${setupVars} ]];then
|
||||
${SUDO} rm ${setupVars}
|
||||
fi
|
||||
${SUDO} echo "piholeInterface=${piholeInterface}" >> ${setupVars}
|
||||
${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars}
|
||||
${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars}
|
||||
${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars}
|
||||
${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars}
|
||||
}
|
||||
|
||||
|
||||
installPihole() {
|
||||
# Install base files and web interface
|
||||
checkForDependencies # done
|
||||
stopServices
|
||||
setUser
|
||||
$SUDO mkdir -p /etc/pihole/
|
||||
${SUDO} mkdir -p /etc/pihole/
|
||||
if [ ! -d "/var/www/html" ]; then
|
||||
$SUDO mkdir -p /var/www/html
|
||||
${SUDO} mkdir -p /var/www/html
|
||||
fi
|
||||
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/www/html
|
||||
$SUDO chmod 775 /var/www/html
|
||||
$SUDO usermod -a -G $LIGHTTPD_GROUP pihole
|
||||
${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html
|
||||
${SUDO} chmod 775 /var/www/html
|
||||
${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole
|
||||
if [ -x "$(command -v lighty-enable-mod)" ]; then
|
||||
$SUDO lighty-enable-mod fastcgi fastcgi-php > /dev/null
|
||||
${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null
|
||||
else
|
||||
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
|
||||
fi
|
||||
|
@ -830,6 +826,24 @@ installPihole() {
|
|||
getGitFiles
|
||||
installScripts
|
||||
installConfigs
|
||||
installConfigs
|
||||
CreateLogFile
|
||||
configureSelinux
|
||||
installPiholeWeb
|
||||
installCron
|
||||
runGravity
|
||||
configureFirewall
|
||||
finalExports
|
||||
}
|
||||
|
||||
updatePihole() {
|
||||
# Install base files and web interface
|
||||
checkForDependencies # done
|
||||
stopServices
|
||||
getGitFiles
|
||||
installScripts
|
||||
installConfigs
|
||||
installConfigs
|
||||
CreateLogFile
|
||||
configureSelinux
|
||||
installPiholeWeb
|
||||
|
@ -845,22 +859,22 @@ configureSelinux() {
|
|||
package_check "selinux-policy-devel" > /dev/null
|
||||
if ! [ $? -eq 0 ]; then
|
||||
echo -n " Not found! Installing...."
|
||||
$SUDO $PKG_INSTALL "selinux-policy-devel" > /dev/null & spinner $!
|
||||
${SUDO} ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
else
|
||||
echo " already installed!"
|
||||
fi
|
||||
printf "::: Enabling httpd server side includes (SSI).. "
|
||||
$SUDO setsebool -P httpd_ssi_exec on
|
||||
${SUDO} setsebool -P httpd_ssi_exec on
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -n "Success\n"
|
||||
fi
|
||||
printf ":::\tCompiling Pi-Hole SELinux policy..\n"
|
||||
$SUDO checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te
|
||||
$SUDO semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod
|
||||
$SUDO semodule -i /etc/pihole/pihole.pp
|
||||
$SUDO rm -f /etc/pihole/pihole.mod
|
||||
$SUDO semodule -l | grep pihole > /dev/null
|
||||
${SUDO} checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te
|
||||
${SUDO} semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod
|
||||
${SUDO} semodule -i /etc/pihole/pihole.pp
|
||||
${SUDO} rm -f /etc/pihole/pihole.mod
|
||||
${SUDO} semodule -l | grep pihole > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
printf "::: Successfully installed Pi-Hole SELinux policy\n"
|
||||
else
|
||||
|
@ -879,61 +893,102 @@ IPv6: $piholeIPv6
|
|||
If you set a new IP address, you should restart the Pi.
|
||||
|
||||
The install log is in /etc/pihole.
|
||||
View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $r $c
|
||||
View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" ${r} ${c}
|
||||
}
|
||||
|
||||
updateDialogs(){
|
||||
|
||||
UpdateCmd=(whiptail --separate-output --radiolist "We have detected an existing install.\n\n Selecting Update will retain settings from the existing install.\n\n Selecting Install will allow you to enter new settings.\n\n(Highlight desired option, and press space to select!)" ${r} ${c} 2)
|
||||
UpdateChoices=(Update "" on
|
||||
Install "" off)
|
||||
UpdateChoice=$("${UpdateCmd[@]}" "${UpdateChoices[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
if [[ $? = 0 ]];then
|
||||
case ${UpdateChoice} in
|
||||
Update)
|
||||
echo "::: Updating existing install"
|
||||
useUpdateVars=true
|
||||
;;
|
||||
Install)
|
||||
echo "::: Running complete install script"
|
||||
useUpdateVars=false
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "::: Cancel selected. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
######## SCRIPT ############
|
||||
# Start the installer
|
||||
$SUDO mkdir -p /etc/pihole/
|
||||
if [[ -f ${setupVars} ]];then
|
||||
. ${setupVars}
|
||||
|
||||
if [ "$1" == "pihole" ]; then
|
||||
useUpdateVars=true
|
||||
else
|
||||
updateDialogs
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Start the installer
|
||||
# Install packages used by this installation script
|
||||
installerDependencies
|
||||
|
||||
welcomeDialogs
|
||||
if [[ ${useUpdateVars} == false ]]; then
|
||||
welcomeDialogs
|
||||
# Verify there is enough disk space for the install
|
||||
verifyFreeDiskSpace
|
||||
${SUDO} mkdir -p /etc/pihole/
|
||||
|
||||
# Verify there is enough disk space for the install
|
||||
verifyFreeDiskSpace
|
||||
|
||||
# Just back up the original Pi-hole right away since it won't take long and it gets it out of the way
|
||||
backupLegacyPihole
|
||||
# Find IP used to route to outside world
|
||||
findIPRoute
|
||||
# Find interfaces and let the user choose one
|
||||
chooseInterface
|
||||
# Let the user decide if they want to block ads over IPv4 and/or IPv6
|
||||
use4andor6
|
||||
|
||||
# Decide what upstream DNS Servers to use
|
||||
setDNS
|
||||
|
||||
# Install and log everything to a file
|
||||
installPihole | tee $tmpLog
|
||||
# Find IP used to route to outside world
|
||||
findIPRoute
|
||||
# Find interfaces and let the user choose one
|
||||
chooseInterface
|
||||
# Let the user decide if they want to block ads over IPv4 and/or IPv6
|
||||
use4andor6
|
||||
# Decide what upstream DNS Servers to use
|
||||
setDNS
|
||||
# Install and log everything to a file
|
||||
installPihole | tee ${tmpLog}
|
||||
else
|
||||
updatePihole | tee ${tmpLog}
|
||||
fi
|
||||
|
||||
# Move the log file into /etc/pihole for storage
|
||||
$SUDO mv $tmpLog $instalLogLoc
|
||||
${SUDO} mv ${tmpLog} ${instalLogLoc}
|
||||
|
||||
displayFinalMessage
|
||||
if [[ ${useUpdateVars} == false ]]; then
|
||||
displayFinalMessage
|
||||
fi
|
||||
|
||||
echo -n "::: Restarting services..."
|
||||
# Start services
|
||||
if [ -x "$(command -v systemctl)" ]; then
|
||||
$SUDO systemctl enable dnsmasq
|
||||
$SUDO systemctl restart dnsmasq
|
||||
$SUDO systemctl enable lighttpd
|
||||
$SUDO systemctl start lighttpd
|
||||
${SUDO} systemctl enable dnsmasq
|
||||
${SUDO} systemctl restart dnsmasq
|
||||
${SUDO} systemctl enable lighttpd
|
||||
${SUDO} systemctl start lighttpd
|
||||
else
|
||||
$SUDO service dnsmasq restart
|
||||
$SUDO service lighttpd start
|
||||
${SUDO} service dnsmasq restart
|
||||
${SUDO} service lighttpd start
|
||||
fi
|
||||
|
||||
echo " done."
|
||||
|
||||
echo ":::"
|
||||
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
|
||||
echo "::: ${IPv4addr%/*}"
|
||||
echo "::: $piholeIPv6"
|
||||
echo ":::"
|
||||
echo "::: If you set a new IP address, you should restart the Pi."
|
||||
if [[ ${useUpdateVars} == false ]]; then
|
||||
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
|
||||
echo "::: ${IPv4addr%/*}"
|
||||
echo "::: $piholeIPv6"
|
||||
echo ":::"
|
||||
echo "::: If you set a new IP address, you should restart the Pi."
|
||||
else
|
||||
echo "::: Update complete!"
|
||||
fi
|
||||
|
||||
echo ":::"
|
||||
echo "::: The install log is located at: /etc/pihole/install.log"
|
||||
echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"
|
||||
|
|
|
@ -39,7 +39,7 @@ if [ -x "$(command -v rpm)" ];then
|
|||
rpm -qa | grep ^$1- > /dev/null
|
||||
}
|
||||
package_cleanup() {
|
||||
$SUDO $PKG_MANAGER -y autoremove
|
||||
${SUDO} ${PKG_MANAGER} -y autoremove
|
||||
}
|
||||
elif [ -x "$(command -v apt-get)" ];then
|
||||
# Debian Family
|
||||
|
@ -50,8 +50,8 @@ elif [ -x "$(command -v apt-get)" ];then
|
|||
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
|
||||
}
|
||||
package_cleanup() {
|
||||
$SUDO $PKG_MANAGER -y autoremove
|
||||
$SUDO $PKG_MANAGER -y autoclean
|
||||
${SUDO} ${PKG_MANAGER} -y autoremove
|
||||
${SUDO} ${PKG_MANAGER} -y autoclean
|
||||
}
|
||||
else
|
||||
echo "OS distribution not supported"
|
||||
|
@ -66,8 +66,8 @@ spinner()
|
|||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
local spinstr=${temp}${spinstr%"$temp"}
|
||||
sleep ${delay}
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
|
@ -77,12 +77,12 @@ function removeAndPurge {
|
|||
# Purge dependencies
|
||||
echo ":::"
|
||||
for i in "${PIHOLE_DEPS[@]}"; do
|
||||
package_check $i > /dev/null
|
||||
package_check ${i} > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
while true; do
|
||||
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO $PKG_REMOVE "$i" &> /dev/null & spinner $!; printf "done!\n"; break;;
|
||||
case ${yn} in
|
||||
[Yy]* ) printf ":::\tRemoving %s..." "$i"; ${SUDO} ${PKG_REMOVE} "$i" &> /dev/null & spinner $!; printf "done!\n"; break;;
|
||||
[Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;;
|
||||
* ) printf "::: You must answer yes or no!\n";;
|
||||
esac
|
||||
|
@ -94,7 +94,7 @@ echo ":::"
|
|||
|
||||
# Remove dependency config files
|
||||
echo "::: Removing dnsmasq config files..."
|
||||
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
||||
${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
||||
|
||||
# Take care of any additional package cleaning
|
||||
printf "::: Auto removing & cleaning remaining dependencies..."
|
||||
|
@ -108,14 +108,14 @@ function removeNoPurge {
|
|||
echo ":::"
|
||||
# Only web directories/files that are created by pihole should be removed.
|
||||
echo "::: Removing the Pi-hole Web server files..."
|
||||
$SUDO rm -rf /var/www/html/admin &> /dev/null
|
||||
$SUDO rm -rf /var/www/html/pihole &> /dev/null
|
||||
$SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null
|
||||
${SUDO} rm -rf /var/www/html/admin &> /dev/null
|
||||
${SUDO} rm -rf /var/www/html/pihole &> /dev/null
|
||||
${SUDO} rm /var/www/html/index.lighttpd.orig &> /dev/null
|
||||
|
||||
# If the web directory is empty after removing these files, then the parent html folder can be removed.
|
||||
if [ -d "/var/www/html" ]; then
|
||||
if [[ ! "$(ls -A /var/www/html)" ]]; then
|
||||
$SUDO rm -rf /var/www/html &> /dev/null
|
||||
${SUDO} rm -rf /var/www/html &> /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -125,36 +125,36 @@ function removeNoPurge {
|
|||
# preserved.
|
||||
if [[ -f /etc/crontab.orig ]]; then
|
||||
echo "::: Initial Pi-hole cron detected. Restoring the default system cron..."
|
||||
$SUDO mv /etc/crontab /etc/crontab.pihole
|
||||
$SUDO mv /etc/crontab.orig /etc/crontab
|
||||
$SUDO service cron restart
|
||||
${SUDO} mv /etc/crontab /etc/crontab.pihole
|
||||
${SUDO} mv /etc/crontab.orig /etc/crontab
|
||||
${SUDO} service cron restart
|
||||
fi
|
||||
|
||||
# Attempt to preserve backwards compatibility with older versions
|
||||
if [[ -f /etc/cron.d/pihole ]];then
|
||||
echo "::: Removing cron.d/pihole..."
|
||||
$SUDO rm /etc/cron.d/pihole &> /dev/null
|
||||
${SUDO} rm /etc/cron.d/pihole &> /dev/null
|
||||
fi
|
||||
|
||||
echo "::: Removing config files and scripts..."
|
||||
package_check $i > /dev/null
|
||||
package_check ${i} > /dev/null
|
||||
if [ $? -eq 1 ]; then
|
||||
$SUDO rm -rf /etc/lighttpd/ &> /dev/null
|
||||
${SUDO} rm -rf /etc/lighttpd/ &> /dev/null
|
||||
else
|
||||
if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then
|
||||
$SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
|
||||
${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
$SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null
|
||||
$SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
||||
$SUDO rm -rf /var/log/*pihole* &> /dev/null
|
||||
$SUDO rm -rf /etc/pihole/ &> /dev/null
|
||||
$SUDO rm -rf /etc/.pihole/ &> /dev/null
|
||||
$SUDO rm -rf /opt/pihole/ &> /dev/null
|
||||
$SUDO rm /usr/local/bin/pihole &> /dev/null
|
||||
$SUDO rm /etc/bash_completion.d/pihole &> /dev/null
|
||||
$SUDO rm /etc/sudoers.d/pihole &> /dev/null
|
||||
${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null
|
||||
${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
||||
${SUDO} rm -rf /var/log/*pihole* &> /dev/null
|
||||
${SUDO} rm -rf /etc/pihole/ &> /dev/null
|
||||
${SUDO} rm -rf /etc/.pihole/ &> /dev/null
|
||||
${SUDO} rm -rf /opt/pihole/ &> /dev/null
|
||||
${SUDO} rm /usr/local/bin/pihole &> /dev/null
|
||||
${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null
|
||||
${SUDO} rm /etc/sudoers.d/pihole &> /dev/null
|
||||
|
||||
echo ":::"
|
||||
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n"
|
||||
|
@ -168,7 +168,7 @@ echo "::: Preparing to remove packages, be sure that each may be safely removed
|
|||
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)"
|
||||
while true; do
|
||||
read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn
|
||||
case $yn in
|
||||
case ${yn} in
|
||||
[Yy]* ) removeAndPurge; break;;
|
||||
|
||||
[Nn]* ) removeNoPurge; break;;
|
||||
|
|
104
gravity.sh
104
gravity.sh
|
@ -47,9 +47,9 @@ adListDefault=/etc/pihole/adlists.default
|
|||
whitelistScript=/opt/pihole/whitelist.sh
|
||||
blacklistScript=/opt/pihole/blacklist.sh
|
||||
|
||||
if [[ -f $piholeIPfile ]];then
|
||||
if [[ -f ${piholeIPfile} ]];then
|
||||
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
|
||||
piholeIP=$(cat $piholeIPfile)
|
||||
piholeIP=$(cat ${piholeIPfile})
|
||||
#rm $piholeIPfile
|
||||
else
|
||||
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
|
||||
|
@ -58,7 +58,7 @@ else
|
|||
piholeIP=${piholeIPCIDR%/*}
|
||||
fi
|
||||
|
||||
if [[ -f $piholeIPv6file ]];then
|
||||
if [[ -f ${piholeIPv6file} ]];then
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
|
@ -66,22 +66,22 @@ fi
|
|||
# Variables for various stages of downloading and formatting the list
|
||||
## Nate 3/26/2016 - Commented unused variables
|
||||
basename=pihole
|
||||
piholeDir=/etc/$basename
|
||||
adList=$piholeDir/gravity.list
|
||||
piholeDir=/etc/${basename}
|
||||
adList=${piholeDir}/gravity.list
|
||||
#blacklist=$piholeDir/blacklist.txt
|
||||
#whitelist=$piholeDir/whitelist.txt
|
||||
#latentWhitelist=$piholeDir/latentWhitelist.txt
|
||||
justDomainsExtension=domains
|
||||
matterandlight=$basename.0.matterandlight.txt
|
||||
supernova=$basename.1.supernova.txt
|
||||
eventHorizon=$basename.2.eventHorizon.txt
|
||||
accretionDisc=$basename.3.accretionDisc.txt
|
||||
matterandlight=${basename}.0.matterandlight.txt
|
||||
supernova=${basename}.1.supernova.txt
|
||||
eventHorizon=${basename}.2.eventHorizon.txt
|
||||
accretionDisc=${basename}.3.accretionDisc.txt
|
||||
#eyeOfTheNeedle=$basename.4.wormhole.txt
|
||||
|
||||
# After setting defaults, check if there's local overrides
|
||||
if [[ -r $piholeDir/pihole.conf ]];then
|
||||
if [[ -r ${piholeDir}/pihole.conf ]];then
|
||||
echo "::: Local calibration requested..."
|
||||
. $piholeDir/pihole.conf
|
||||
. ${piholeDir}/pihole.conf
|
||||
fi
|
||||
|
||||
###########################
|
||||
|
@ -90,18 +90,18 @@ function gravity_collapse() {
|
|||
echo "::: Neutrino emissions detected..."
|
||||
echo ":::"
|
||||
#Decide if we're using a custom ad block list, or defaults.
|
||||
if [ -f $adListFile ]; then
|
||||
if [ -f ${adListFile} ]; then
|
||||
#custom file found, use this instead of default
|
||||
echo -n "::: Custom adList file detected. Reading..."
|
||||
sources=()
|
||||
while read -r line; do
|
||||
#Do not read commented out or blank lines
|
||||
if [[ $line = \#* ]] || [[ ! $line ]]; then
|
||||
if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
|
||||
echo "" > /dev/null
|
||||
else
|
||||
sources+=($line)
|
||||
sources+=(${line})
|
||||
fi
|
||||
done < $adListFile
|
||||
done < ${adListFile}
|
||||
echo " done!"
|
||||
else
|
||||
#no custom file found, use defaults!
|
||||
|
@ -109,27 +109,27 @@ function gravity_collapse() {
|
|||
sources=()
|
||||
while read -r line; do
|
||||
#Do not read commented out or blank lines
|
||||
if [[ $line = \#* ]] || [[ ! $line ]]; then
|
||||
if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
|
||||
echo "" > /dev/null
|
||||
else
|
||||
sources+=($line)
|
||||
sources+=(${line})
|
||||
fi
|
||||
done < $adListDefault
|
||||
done < ${adListDefault}
|
||||
echo " done!"
|
||||
fi
|
||||
|
||||
# Create the pihole resource directory if it doesn't exist. Future files will be stored here
|
||||
if [[ -d $piholeDir ]];then
|
||||
if [[ -d ${piholeDir} ]];then
|
||||
# Temporary hack to allow non-root access to pihole directory
|
||||
# Will update later, needed for existing installs, new installs should
|
||||
# create this directory as non-root
|
||||
$SUDO chmod 777 $piholeDir
|
||||
${SUDO} chmod 777 ${piholeDir}
|
||||
echo ":::"
|
||||
echo "::: Existing pihole directory found"
|
||||
else
|
||||
echo "::: Creating pihole directory..."
|
||||
mkdir $piholeDir
|
||||
$SUDO chmod 777 $piholeDir
|
||||
mkdir ${piholeDir}
|
||||
${SUDO} chmod 777 ${piholeDir}
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -158,13 +158,13 @@ function gravity_transport() {
|
|||
# tmp file, so we don't have to store the (long!) lists in RAM
|
||||
patternBuffer=$(mktemp)
|
||||
heisenbergCompensator=""
|
||||
if [[ -r $saveLocation ]]; then
|
||||
if [[ -r ${saveLocation} ]]; then
|
||||
# if domain has been saved, add file for date check to only download newer
|
||||
heisenbergCompensator="-z $saveLocation"
|
||||
fi
|
||||
|
||||
# Silently curl url
|
||||
curl -s -L $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
|
||||
curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer}
|
||||
# Check for list updates
|
||||
gravity_patternCheck "$patternBuffer"
|
||||
# Cleanup
|
||||
|
@ -182,8 +182,8 @@ function gravity_spinup() {
|
|||
domain=$(echo "$url" | cut -d'/' -f3)
|
||||
|
||||
# Save the file as list.#.domain
|
||||
saveLocation=$piholeDir/list.$i.$domain.$justDomainsExtension
|
||||
activeDomains[$i]=$saveLocation
|
||||
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
|
||||
activeDomains[$i]=${saveLocation}
|
||||
|
||||
agent="Mozilla/10.0"
|
||||
|
||||
|
@ -213,10 +213,10 @@ function gravity_Schwarzchild() {
|
|||
echo "::: "
|
||||
# Find all active domains and compile them into one file and remove CRs
|
||||
echo -n "::: Aggregating list of domains..."
|
||||
truncate -s 0 $piholeDir/$matterandlight
|
||||
truncate -s 0 ${piholeDir}/${matterandlight}
|
||||
for i in "${activeDomains[@]}"
|
||||
do
|
||||
cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight
|
||||
cat "$i" | tr -d '\r' >> ${piholeDir}/${matterandlight}
|
||||
done
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ function gravity_Schwarzchild() {
|
|||
function gravity_Blacklist(){
|
||||
# Append blacklist entries if they exist
|
||||
echo -n "::: Running blacklist script to update HOSTS file...."
|
||||
$blacklistScript -f -nr -q > /dev/null
|
||||
${blacklistScript} -f -nr -q > /dev/null
|
||||
|
||||
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
|
||||
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
||||
|
@ -241,12 +241,12 @@ function gravity_Whitelist() {
|
|||
for url in "${sources[@]}"
|
||||
do
|
||||
tmp=$(echo "$url" | awk -F '/' '{print $3}')
|
||||
urls=("${urls[@]}" $tmp)
|
||||
urls=("${urls[@]}" ${tmp})
|
||||
done
|
||||
echo " done!"
|
||||
|
||||
echo -n "::: Running whitelist script to update HOSTS file...."
|
||||
$whitelistScript -f -nr -q "${urls[@]}" > /dev/null
|
||||
${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
|
||||
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
|
||||
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
||||
echo " $numWhitelisted domain${plural} whitelisted!"
|
||||
|
@ -255,9 +255,9 @@ function gravity_Whitelist() {
|
|||
function gravity_unique() {
|
||||
# Sort and remove duplicates
|
||||
echo -n "::: Removing duplicate domains...."
|
||||
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon
|
||||
sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon}
|
||||
echo " done!"
|
||||
numberOf=$(wc -l < $piholeDir/$eventHorizon)
|
||||
numberOf=$(wc -l < ${piholeDir}/${eventHorizon})
|
||||
echo "::: $numberOf unique domains trapped in the event horizon."
|
||||
}
|
||||
|
||||
|
@ -266,25 +266,25 @@ function gravity_hostFormat() {
|
|||
echo "::: Formatting domains into a HOSTS file..."
|
||||
hostname=$(</etc/hostname)
|
||||
# If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
if [[ -n ${piholeIPv6} ]];then
|
||||
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
|
||||
echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > $piholeDir/$accretionDisc
|
||||
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > ${piholeDir}/${accretionDisc}
|
||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
||||
else
|
||||
# Otherwise, just create gravity.list as normal using IPv4
|
||||
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
|
||||
echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > $piholeDir/$accretionDisc
|
||||
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > ${piholeDir}/${accretionDisc}
|
||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
||||
fi
|
||||
|
||||
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||
cp $piholeDir/$accretionDisc $adList
|
||||
cp ${piholeDir}/${accretionDisc} ${adList}
|
||||
}
|
||||
|
||||
# blackbody - remove any remnant files from script processes
|
||||
function gravity_blackbody() {
|
||||
# Loop through list files
|
||||
for file in $piholeDir/*.$justDomainsExtension
|
||||
for file in ${piholeDir}/*.${justDomainsExtension}
|
||||
do
|
||||
# If list is in active array then leave it (noop) else rm the list
|
||||
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
|
||||
|
@ -301,10 +301,10 @@ function gravity_advanced() {
|
|||
# This helps with that and makes it easier to read
|
||||
# It also helps with debugging so each stage of the script can be researched more in depth
|
||||
echo -n "::: Formatting list of domains to remove comments...."
|
||||
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
|
||||
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' ${piholeDir}/${matterandlight} | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova}
|
||||
echo " done!"
|
||||
|
||||
numberOf=$(wc -l < $piholeDir/$supernova)
|
||||
numberOf=$(wc -l < ${piholeDir}/${supernova})
|
||||
echo "::: $numberOf domains being pulled in by gravity..."
|
||||
|
||||
gravity_unique
|
||||
|
@ -314,7 +314,7 @@ function gravity_reload() {
|
|||
#Clear no longer needed files...
|
||||
echo ":::"
|
||||
echo -n "::: Cleaning up un-needed files..."
|
||||
$SUDO rm $piholeDir/pihole.*.txt
|
||||
${SUDO} rm ${piholeDir}/pihole.*.txt
|
||||
echo " done!"
|
||||
|
||||
# Reload hosts file
|
||||
|
@ -325,17 +325,17 @@ function gravity_reload() {
|
|||
#First escape forward slashes in the path:
|
||||
adList=${adList//\//\\\/}
|
||||
#Now replace the line in dnsmasq file
|
||||
$SUDO sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
||||
${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \;
|
||||
find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
|
||||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
if [[ ${dnsmasqPid} ]]; then
|
||||
# service already running - reload config
|
||||
$SUDO killall -s HUP dnsmasq
|
||||
${SUDO} killall -s HUP dnsmasq
|
||||
else
|
||||
# service not running, start it up
|
||||
$SUDO service dnsmasq start
|
||||
${SUDO} service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -344,20 +344,20 @@ function gravity_reload() {
|
|||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-f" | "--force" ) force=true;;
|
||||
"-f" | "--force" ) forceGrav=true;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
esac
|
||||
done
|
||||
|
||||
#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list
|
||||
|
||||
if $force; then
|
||||
if [[ ${forceGrav} == true ]]; then
|
||||
echo -n "::: Deleting exising list cache..."
|
||||
$SUDO rm /etc/pihole/list.*
|
||||
${SUDO} rm /etc/pihole/list.*
|
||||
echo " done!"
|
||||
fi
|
||||
|
||||
$SUDO cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
|
||||
${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
|
||||
gravity_collapse
|
||||
gravity_spinup
|
||||
gravity_Schwarzchild
|
||||
|
|
36
pihole
36
pihole
|
@ -27,38 +27,46 @@ fi
|
|||
|
||||
function whitelistFunc {
|
||||
shift
|
||||
$SUDO /opt/pihole/whitelist.sh "$@"
|
||||
${SUDO} /opt/pihole/whitelist.sh "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function blacklistFunc {
|
||||
shift
|
||||
$SUDO /opt/pihole/blacklist.sh "$@"
|
||||
${SUDO} /opt/pihole/blacklist.sh "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function debugFunc {
|
||||
$SUDO /opt/pihole/piholeDebug.sh
|
||||
${SUDO} /opt/pihole/piholeDebug.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
function flushFunc {
|
||||
$SUDO /opt/pihole/piholeLogFlush.sh
|
||||
${SUDO} /opt/pihole/piholeLogFlush.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
function updateDashboardFunc {
|
||||
$SUDO /opt/pihole/updateDashboard.sh
|
||||
${SUDO} /opt/pihole/updateDashboard.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
function updatePiholeFunc {
|
||||
echo "::: Fetching latest changes from Github..."
|
||||
cd /etc/.pihole
|
||||
${SUDO} git pull
|
||||
${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole
|
||||
exit 1
|
||||
}
|
||||
|
||||
function updateGravityFunc {
|
||||
$SUDO /opt/pihole/gravity.sh
|
||||
${SUDO} /opt/pihole/gravity.sh "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function setupLCDFunction {
|
||||
$SUDO /opt/pihole/setupLCD.sh
|
||||
${SUDO} /opt/pihole/setupLCD.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -70,18 +78,18 @@ function queryFunc {
|
|||
|
||||
function chronometerFunc {
|
||||
shift
|
||||
$SUDO /opt/pihole/chronometer.sh "$@"
|
||||
${SUDO} /opt/pihole/chronometer.sh "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
function uninstallFunc {
|
||||
$SUDO /opt/pihole/uninstall.sh
|
||||
${SUDO} /opt/pihole/uninstall.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
function versionFunc {
|
||||
$SUDO /opt/pihole/version.sh
|
||||
${SUDO} /opt/pihole/version.sh
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -96,7 +104,8 @@ function helpFunc {
|
|||
echo "::: -b, blacklist Blacklist domains"
|
||||
echo "::: -d, debug Start a debugging session if having trouble"
|
||||
echo "::: -f, flush Flush the pihole.log file"
|
||||
echo "::: -u, updateDashboard Update the web dashboard manually"
|
||||
echo "::: -ud, updateDashboard Update the web dashboard manually"
|
||||
echo "::: -up, updatePihole Update Pi-hole"
|
||||
echo "::: -g, updateGravity Update the list of ad-serving domains"
|
||||
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it"
|
||||
echo "::: -c, chronometer Calculates stats and displays to an LCD"
|
||||
|
@ -117,8 +126,9 @@ case "$1" in
|
|||
"-b" | "blacklist" ) blacklistFunc "$@";;
|
||||
"-d" | "debug" ) debugFunc;;
|
||||
"-f" | "flush" ) flushFunc;;
|
||||
"-u" | "updateDashboard" ) updateDashboardFunc;;
|
||||
"-g" | "updateGravity" ) updateGravityFunc;;
|
||||
"-ud" | "updateDashboard" ) updateDashboardFunc;;
|
||||
"-up" | "updatePihole" ) updatePiholeFunc;;
|
||||
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
||||
"-s" | "setupLCD" ) setupLCDFunction;;
|
||||
"-c" | "chronometer" ) chronometerFunc "$@";;
|
||||
"-h" | "help" ) helpFunc;;
|
||||
|
|
Loading…
Reference in a new issue