Merge branch 'development' of https://github.com/pi-hole/pi-hole into development / update chro

This commit is contained in:
Tommy Huff 2016-10-24 17:46:38 -04:00
commit e9f14da1b4
14 changed files with 1208 additions and 1235 deletions

View file

@ -1,23 +1,21 @@
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
**In raising this issue, I confirm the following (please check boxes, eg [X]):**
- [ ] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [ ] The issue I am reporting can be *replicated*
- [ ] The issue I'm reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)).
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [] The issue I am reporting can be *replicated*
- [] The issue I'm reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)).
**How familiar are you with the codebase?:**
- [ ] 1 (very unfamiliar)
- [ ] 2
- [ ] 3
- [ ] 4
- [ ] 5
- [ ] 6
- [ ] 7
- [ ] 8
- [ ] 9
- [ ] 10 (very familiar)
- [] 1 (very unfamiliar)
- [] 2
- [] 3
- [] 4
- [] 5
- [] 6
- [] 7
- [] 8
- [] 9
- [] 10 (very familiar)
---
**[FEATURE REQUEST | QUESTION | OTHER]:**
@ -40,3 +38,5 @@ _{replace this section with your content or delete if not a FEATURE REQUEST/QUES
**(Optional) Debug Log generated by `pihole -d`:**
`http://termbin.com/<something>`
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._

View file

@ -1,25 +1,26 @@
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
**By submitting this pull request, I confirm the following (please check boxes, eg [X]):**
- [ ] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [ ] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist.
- [ ] I have considered, and confirmed that this submission will be valuable to others.
- [ ] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [ ] I give this submission freely, and claim no ownership to its content.
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist.
- [] I have considered, and confirmed that this submission will be valuable to others.
- [] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [] I give this submission freely, and claim no ownership to its content.
**How familiar are you with the codebase?:**
- [ ] 1 (very unfamiliar)
- [ ] 2
- [ ] 3
- [ ] 4
- [ ] 5
- [ ] 6
- [ ] 7
- [ ] 8
- [ ] 9
- [ ] 10 (very familiar)
- [] 1 (very unfamiliar)
- [] 2
- [] 3
- [] 4
- [] 5
- [] 6
- [] 7
- [] 8
- [] 9
- [] 10 (very familiar)
---
_{replace this line with your pull request content}_
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._

View file

@ -47,7 +47,7 @@ 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})
#rm $piholeIPfile
@ -61,22 +61,22 @@ 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
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
HandleOther() {
#check validity of domain
validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if [ -z "$validDomain" ]; then
echo "::: $1 is not a valid argument or domain name"
validDomain=$(echo "${1}" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if [ -z "${validDomain}" ]; then
echo "::: ${1} is not a valid argument or domain name"
else
domList=("${domList[@]}" ${validDomain})
fi
@ -84,20 +84,20 @@ HandleOther() {
PopBlacklistFile() {
#check blacklist file exists, and if not, create it
if [[ ! -f ${blacklist} ]];then
if [[ ! -f ${blacklist} ]]; then
touch ${blacklist}
fi
for dom in "${domList[@]}"; do
if "$addmode"; then
AddDomain "$dom"
if "${addmode}"; then
AddDomain "${dom}"
else
RemoveDomain "$dom"
RemoveDomain "${dom}"
fi
done
}
AddDomain() {
#| sed 's/\./\\./g'
#| sed 's/\./\\./g'
bool=false
grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then
@ -105,18 +105,17 @@ AddDomain() {
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
echo "::: $1 already exists in $blacklist! No need to add"
echo "::: ${1} already exists in ${blacklist}! No need to add"
fi
fi
}
RemoveDomain() {
bool=false
grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then
@ -127,7 +126,7 @@ RemoveDomain() {
else
#Domain is in the blacklist file, add to a temporary array
if ${verbose}; then
echo "::: Un-blacklisting $dom..."
echo "::: Un-blacklisting ${dom}..."
fi
domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true
@ -137,12 +136,12 @@ RemoveDomain() {
ModifyHostFile() {
if ${addmode}; then
#add domains to the hosts file
if [[ -r ${blacklist} ]];then
if [[ -r ${blacklist} ]]; then
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s
plural=; [[ "${numberOf}" != "1" ]] && plural=s
echo ":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
if [[ -n ${piholeIPv6} ]];then
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}
@ -150,15 +149,14 @@ ModifyHostFile() {
fi
else
echo ":::"
for dom in "${domToRemoveList[@]}"
do
for dom in "${domToRemoveList[@]}"; do
#we need to remove the domains from the blacklist file and the host file
echo "::: $dom"
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
@ -193,17 +191,15 @@ DisplayBlist() {
verbose=false
echo -e " Displaying Gravity Affected Domains \n"
count=1
while IFS= read -r AD
do
echo "${count}: $AD"
while IFS= read -r AD; do
echo "${count}: ${AD}"
count=$((count+1))
done < "$blacklist"
done < "${blacklist}"
}
###################################################
for var in "$@"
do
for var in "$@"; do
case "$var" in
"-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;;

View file

@ -91,7 +91,6 @@ else
exit 1
fi
#remove CIDR from IPv4
IPv4_address=${IPv4_address%/*}
center(){

View file

@ -1,4 +1,4 @@
#/usr/bin/env bash
#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements
# (c) 2015, 2016 by Jacob Salmela
# Network-wide ad blocking via your Raspberry Pi
@ -36,35 +36,18 @@ cat << EOM
:::
EOM
######## FIRST CHECK ########
# Must be root to debug
if [[ "$EUID" -eq 0 ]]; then
echo "::: Script is executing as root user..."
else
echo "::: Non-root user detected..."
# Check if sudo is actually installed
if [ -x "$(command -v sudo)" ]; then
export SUDO="sudo"
echo "::: sudo command located, debug will run under sudo."
else
echo "::: Unable to locate sudo command. Please install sudo or run this as root."
exit 1
fi
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}
if [ ! -f "${DEBUG_LOG}" ]; then
touch ${DEBUG_LOG}
chmod 644 ${DEBUG_LOG}
chown "$USER":root ${DEBUG_LOG}
else
truncate -s 0 ${DEBUG_LOG}
fi
### Private functions exist here ###
log_write() {
echo "$1" >> "${DEBUG_LOG}"
echo "${1}" >> "${DEBUG_LOG}"
}
version_check() {
@ -85,237 +68,256 @@ version_check() {
php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed."
}
files_check() {
log_write "############################################################"
log_write "########## Files Check ##########"
log_write "############################################################"
#Check existence of setupVars.conf, and source it to get configured network interface for later use in script.
echo -n "::: Detecting existence setupVars.conf..."
setupVars=/etc/pihole/setupVars.conf
if [[ -f ${setupVars} ]];then
echo " found!"
log_write "/etc/pihole/setupVars.conf exists! Contents:"
while read -r line; do
if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue
log_write "${line}"
fi
done < "${setupVars}"
log_write ""
. "${setupVars}"
if [[ -n "${piholeInterface}" ]]; then
# prepend % to the beginning of piholeInterface for later use
piholeInterface="%${piholeInterface}"
fi
else
echo " NOT FOUND!"
log_write "/etc/pihole/setupVars.conf not found!"
fi
}
distro_check() {
echo "############################################################" >> ${DEBUG_LOG}
echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG}
echo "############################################################" >> ${DEBUG_LOG}
log_write "############################################################"
log_write "######## Installed OS Distribution #########"
log_write "############################################################"
echo "::: Checking installed OS Distribution release."
TMP=$(cat /etc/*release || echo "Failed to find release")
echo "::: Writing OS Distribution release to logfile."
echo "$TMP" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "${TMP}"
log_write ""
}
ip_check() {
echo "############################################################" >> ${DEBUG_LOG}
echo "######## IP Address Information #########" >> ${DEBUG_LOG}
echo "############################################################" >> ${DEBUG_LOG}
log_write "############################################################"
log_write "######## IP Address Information #########"
log_write "############################################################"
echo "::: Writing local IPs to logfile"
IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')"
echo "$IPADDR" >> ${DEBUG_LOG}
log_write "${IPADDR}"
IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
&& echo "$IP6ADDR" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
&& log_write "${IP6ADDR}" || log_write "No IPv6 addresses found."
log_write ""
echo "::: Locating default gateway and checking connectivity"
GATEWAY=$(ip r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]]
then
if [[ $? = 0 ]]; then
echo "::: Pinging default IPv4 gateway..."
GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3)
if [[ $? = 0 ]]
then
echo "IPv4 Gateway check:" >> ${DEBUG_LOG}
if [[ $? = 0 ]]; then
log_write "IPv4 Gateway check:"
else
echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG}
log_write "IPv4 Gateway check failed:"
fi
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "${GATEWAY_CHECK}"
log_write ""
echo "::: Pinging Internet via IPv4..."
INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)
if [[ $? = 0 ]]
then
echo "IPv4 Internet check:" >> ${DEBUG_LOG}
if [[ $? = 0 ]]; then
log_write "IPv4 Internet check:"
else
echo "IPv4 Internet check failed:" >> ${DEBUG_LOG}
log_write "IPv4 Internet check failed:"
fi
echo "$INET_CHECK" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "${INET_CHECK}"
log_write ""
fi
GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]]
then
if [[ $? = 0 ]]; then
echo "::: Pinging default IPv6 gateway..."
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3)
if [[ $? = 0 ]]
then
echo "IPv6 Gateway check:" >> ${DEBUG_LOG}
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3)
if [[ $? = 0 ]]; then
log_write "IPv6 Gateway check:"
else
echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG}
log_write "IPv6 Gateway check failed:"
fi
echo "::: Pinging Internet via IPv6..."
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3)
if [[ $? = 0 ]]
then
echo "IPv6 Internet check:" >> ${DEBUG_LOG}
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3)
if [[ $? = 0 ]]; then
log_write "IPv6 Internet check:"
else
echo "IPv6 Internet check failed:" >> ${DEBUG_LOG}
log_write "IPv6 Internet check failed:"
fi
else
GATEWAY_CHECK="No IPv6 Gateway Detected"
fi
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
log_write "${GATEWAY_CHECK}"
echo >> ${DEBUG_LOG}
log_write ""
}
hostnameCheck() {
echo "############################################################" >> ${DEBUG_LOG}
echo "######## Hostname Information #########" >> ${DEBUG_LOG}
echo "############################################################" >> ${DEBUG_LOG}
log_write "############################################################"
log_write "######## Hostname Information #########"
log_write "############################################################"
echo "::: Writing locally configured hostnames to logfile"
# Write the hostname output to compare against entries in /etc/hosts, which is logged next
echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG}
log_write "This Pi-hole is: $(hostname)"
echo "::: Writing hosts file to debug log..."
echo "### Hosts ###" >> ${DEBUG_LOG}
log_write "### Hosts ###"
if [ -e "$HOSTSFILE" ]
then
cat "$HOSTSFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
if [ -e "${HOSTSFILE}" ]; then
cat "${HOSTSFILE}" >> ${DEBUG_LOG}
log_write ""
else
echo "No hosts file found!" >> ${DEBUG_LOG}
log_write "No hosts file found!"
printf ":::\tNo hosts file found!\n"
fi
}
portCheck() {
echo "############################################################" >> ${DEBUG_LOG}
echo "######## Open Port Information #########" >> ${DEBUG_LOG}
echo "############################################################" >> ${DEBUG_LOG}
log_write "############################################################"
log_write "######## Open Port Information #########"
log_write "############################################################"
echo "::: Detecting local server port 80 and 53 processes."
${SUDO} lsof -i :80 >> ${DEBUG_LOG}
${SUDO} lsof -i :53 >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
lsof -i :80 >> ${DEBUG_LOG}
lsof -i :53 >> ${DEBUG_LOG}
log_write ""
}
testResolver() {
echo "############################################################" >> ${DEBUG_LOG}
echo "############ Resolver Functions Check ############" >> ${DEBUG_LOG}
echo "############################################################" >> ${DEBUG_LOG}
log_write "############################################################"
log_write "############ Resolver Functions Check ############"
log_write "############################################################"
# Find a blocked url that has not been whitelisted.
TESTURL="doubleclick.com"
if [ -s "$WHITELISTMATCHES" ]; then
if [ -s "${WHITELISTMATCHES}" ]; then
while read -r line; do
CUTURL=${line#*" "}
if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then
if [ "${CUTURL}" != "Pi-Hole.IsWorking.OK" ]; then
while read -r line2; do
CUTURL2=${line2#*" "}
if [ "$CUTURL" != "$CUTURL2" ]; then
TESTURL="$CUTURL"
if [ "${CUTURL}" != "${CUTURL2}" ]; then
TESTURL="${CUTURL}"
break 2
fi
done < "$WHITELISTMATCHES"
done < "${WHITELISTMATCHES}"
fi
done < "$GRAVITYFILE"
done < "${GRAVITYFILE}"
fi
echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG}
LOCALDIG=$(dig "$TESTURL" @127.0.0.1)
if [[ $? = 0 ]]
then
echo "$LOCALDIG" >> ${DEBUG_LOG}
log_write "Resolution of ${TESTURL} from Pi-hole:"
LOCALDIG=$(dig "${TESTURL}" @127.0.0.1)
if [[ $? = 0 ]]; then
log_write "${LOCALDIG}"
else
echo "Failed to resolve $TESTURL on Pi-hole" >> ${DEBUG_LOG}
log_write "Failed to resolve ${TESTURL} on Pi-hole"
fi
echo >> ${DEBUG_LOG}
log_write ""
echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG}
REMOTEDIG=$(dig "$TESTURL" @8.8.8.8)
if [[ $? = 0 ]]
then
echo "$REMOTEDIG" >> ${DEBUG_LOG}
log_write "Resolution of ${TESTURL} from 8.8.8.8:"
REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8)
if [[ $? = 0 ]]; then
log_write "${REMOTEDIG}"
else
echo "Failed to resolve $TESTURL on 8.8.8.8" >> ${DEBUG_LOG}
log_write "Failed to resolve ${TESTURL} on 8.8.8.8"
fi
echo >> ${DEBUG_LOG}
log_write ""
echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG}
echo "Cache Size:" >> ${DEBUG_LOG}
log_write "Pi-hole dnsmasq specific records lookups"
log_write "Cache Size:"
dig +short chaos txt cachesize.bind >> ${DEBUG_LOG}
echo "Insertions count:" >> ${DEBUG_LOG}
log_write "Insertions count:"
dig +short chaos txt insertions.bind >> ${DEBUG_LOG}
echo "Evictions count:" >> ${DEBUG_LOG}
log_write "Evictions count:"
dig +short chaos txt evictions.bind >> ${DEBUG_LOG}
echo "Misses count:" >> ${DEBUG_LOG}
log_write "Misses count:"
dig +short chaos txt misses.bind >> ${DEBUG_LOG}
echo "Hits count:" >> ${DEBUG_LOG}
log_write "Hits count:"
dig +short chaos txt hits.bind >> ${DEBUG_LOG}
echo "Auth count:" >> ${DEBUG_LOG}
log_write "Auth count:"
dig +short chaos txt auth.bind >> ${DEBUG_LOG}
echo "Upstream Servers:" >> ${DEBUG_LOG}
log_write "Upstream Servers:"
dig +short chaos txt servers.bind >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write ""
}
checkProcesses() {
echo "#######################################" >> ${DEBUG_LOG}
echo "########### Processes Check ###########" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG}
echo ":::"
log_write "#######################################"
log_write "########### Processes Check ###########"
log_write "#######################################"
log_write ":::"
echo "::: Logging status of lighttpd and dnsmasq..."
PROCESSES=( lighttpd dnsmasq )
for i in "${PROCESSES[@]}"
do
echo "" >> ${DEBUG_LOG}
echo -n "$i" >> "$DEBUG_LOG"
echo " processes status:" >> ${DEBUG_LOG}
${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG"
for i in "${PROCESSES[@]}"; do
log_write ""
log_write -n "${i}"
log_write " processes status:"
systemctl -l status "${i}" >> "${DEBUG_LOG}"
done
echo >> ${DEBUG_LOG}
log_write ""
}
debugLighttpd() {
echo "::: Writing lighttpd to debug log..."
echo "#######################################" >> ${DEBUG_LOG}
echo "############ lighttpd.conf ############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$LIGHTTPDFILE" ]
then
log_write "::: Writing lighttpd to debug log..."
log_write "#######################################"
log_write "############ lighttpd.conf ############"
log_write "#######################################"
if [ -e "${LIGHTTPDFILE}" ]; then
while read -r line; do
if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG}
if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue
log_write "${line}"
fi
done < "$LIGHTTPDFILE"
echo >> ${DEBUG_LOG}
done < "${LIGHTTPDFILE}"
log_write ""
else
echo "No lighttpd.conf file found!" >> ${DEBUG_LOG}
log_write "No lighttpd.conf file found!"
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}
if [ -e "${LIGHTTPDERRFILE}" ]; then
log_write "#######################################"
log_write "######### lighttpd error.log ##########"
log_write "#######################################"
cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG}
else
echo "No lighttpd error.log file found!" >> ${DEBUG_LOG}
log_write "No lighttpd error.log file found!"
printf ":::\tNo lighttpd error.log file found\n"
fi
echo >> ${DEBUG_LOG}
log_write ""
}
### END FUNCTIONS ###
version_check
files_check
distro_check
ip_check
hostnameCheck
@ -325,98 +327,92 @@ testResolver
debugLighttpd
echo "::: Writing dnsmasq.conf to debug log..."
echo "#######################################" >> ${DEBUG_LOG}
echo "############### Dnsmasq ###############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$DNSMASQFILE" ]
then
log_write "#######################################"
log_write "############### Dnsmasq ###############"
log_write "#######################################"
if [ -e "${DNSMASQFILE}" ]; then
#cat $DNSMASQFILE >> $DEBUG_LOG
while read -r line; do
if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG}
if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue
log_write "${line}"
fi
done < "$DNSMASQFILE"
echo >> ${DEBUG_LOG}
done < "${DNSMASQFILE}"
log_write ""
else
echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG}
log_write "No dnsmasq.conf file found!"
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}
if [ -e "$PIHOLECONFFILE" ]
then
log_write "#######################################"
log_write "########### 01-pihole.conf ############"
log_write "#######################################"
if [ -e "${PIHOLECONFFILE}" ]; then
while read -r line; do
if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG}
if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue
log_write "${line}"
fi
done < "$PIHOLECONFFILE"
echo >> ${DEBUG_LOG}
done < "${PIHOLECONFFILE}"
log_write
else
echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG}
log_write "No 01-pihole.conf file found!"
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}
if [ -e "$GRAVITYFILE" ]
then
wc -l "$GRAVITYFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "#######################################"
log_write "############ gravity.list #############"
log_write "#######################################"
if [ -e "${GRAVITYFILE}" ]; then
wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG}
log_write ""
else
echo "No gravity.list file found!" >> ${DEBUG_LOG}
log_write "No gravity.list file found!"
printf ":::\tNo gravity.list file found\n"
fi
### Pi-hole application specific logging ###
echo "::: Writing whitelist to debug log..."
echo "#######################################" >> ${DEBUG_LOG}
echo "############## Whitelist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$WHITELISTFILE" ]
then
cat "$WHITELISTFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "#######################################"
log_write "############## Whitelist ##############"
log_write "#######################################"
if [ -e "${WHITELISTFILE}" ]; then
cat "${WHITELISTFILE}" >> ${DEBUG_LOG}
log_write
else
echo "No whitelist.txt file found!" >> ${DEBUG_LOG}
log_write "No whitelist.txt file found!"
printf ":::\tNo whitelist.txt file found!\n"
fi
echo "::: Writing blacklist to debug log..."
echo "#######################################" >> ${DEBUG_LOG}
echo "############## Blacklist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$BLACKLISTFILE" ]
then
cat "$BLACKLISTFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
log_write "#######################################"
log_write "############## Blacklist ##############"
log_write "#######################################"
if [ -e "${BLACKLISTFILE}" ]; then
cat "${BLACKLISTFILE}" >> ${DEBUG_LOG}
log_write
else
echo "No blacklist.txt file found!" >> ${DEBUG_LOG}
log_write "No blacklist.txt file found!"
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}
if [ -e "$ADLISTSFILE" ]
then
log_write "#######################################"
log_write "############ adlists.list #############"
log_write "#######################################"
if [ -e "${ADLISTSFILE}" ]; then
while read -r line; do
if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG}
if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue
log_write "${line}"
fi
done < "$ADLISTSFILE"
echo >> ${DEBUG_LOG}
done < "${ADLISTSFILE}"
log_write
else
echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}
log_write "No adlists.list file found... using adlists.default!"
printf ":::\tNo adlists.list file found... using adlists.default!\n"
fi
@ -425,17 +421,16 @@ fi
dumpPiHoleLog() {
trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
echo -e "::: Writing current Pi-hole 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}
if [ -e "$PIHOLELOG" ]
then
log_write "#######################################"
log_write "############# pihole.log ##############"
log_write "#######################################"
if [ -e "${PIHOLELOG}" ]; then
while true; do
tail -f "$PIHOLELOG" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG}
tail -f "${PIHOLELOG}" >> ${DEBUG_LOG}
log_write ""
done
else
echo "No pihole.log file found!" >> ${DEBUG_LOG}
log_write "No pihole.log file found!"
printf ":::\tNo pihole.log file found!\n"
fi
}
@ -455,9 +450,8 @@ finalWork() {
esac
# Check if termbin.com is reachable. When it's not, point to local log instead
if [ -n "$TERMBIN" ]
then
echo "::: Debug log can be found at : $TERMBIN"
if [ -n "${TERMBIN}" ]; then
echo "::: Debug log can be found at : ${TERMBIN}"
else
echo "::: Debug log can be found at : /var/log/pihole_debug.log"
fi

View file

@ -18,12 +18,12 @@ piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
piholeFilesDir="/etc/.pihole"
spinner() {
local pid=$1
local pid=${1}
local delay=0.50
local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
printf " [%c] " "${spinstr}"
local spinstr=${temp}${spinstr%"$temp"}
sleep ${delay}
printf "\b\b\b\b\b\b"
@ -59,7 +59,7 @@ make_repo() {
}
update_repo() {
# Pull the latest commits
# Pull the latest commits
echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1
git stash -q > /dev/null & spinner $!
@ -117,7 +117,6 @@ elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVers
echo "::: Web Admin version is now at ${webVersion}"
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
echo ""
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
echo "::: Pi-hole core files out of date"
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
@ -127,7 +126,6 @@ elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVers
echo "::: Pi-hole version is now at ${piholeVersion}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ""
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
echo "::: Updating Everything"
getGitFiles ${piholeFilesDir} ${piholeGitUrl}

View file

@ -21,14 +21,13 @@ normalOutput() {
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest})"
echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest})"
}
webOutput() {
for var in "$@"
do
case "$var" in
for var in "$@"; do
case "${var}" in
"-l" | "--latest" ) latest=true;;
"-c" | "--current" ) current=true;;
* ) echo "::: Invalid Option!"; exit 1;
@ -49,9 +48,8 @@ webOutput() {
}
coreOutput() {
for var in "$@"
do
case "$var" in
for var in "$@"; do
case "${var}" in
"-l" | "--latest" ) latest=true;;
"-c" | "--current" ) current=true;;
* ) echo "::: Invalid Option!"; exit 1;
@ -93,9 +91,8 @@ if [[ $# = 0 ]]; then
normalOutput
fi
for var in "$@"
do
case "$var" in
for var in "$@"; do
case "${var}" in
"-a" | "--admin" ) shift; webOutput "$@";;
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
"-h" | "--help" ) helpFunc;;

View file

@ -48,34 +48,34 @@ 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})
#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
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
piholeIPCIDR=$(ip -o -f inet addr show dev "${IPv4dev}" | awk '{print $4}' | awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
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
fi
if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer
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
HandleOther() {
#check validity of domain
validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if [ -z "$validDomain" ]; then
if [ -z "${validDomain}" ]; then
echo "::: $1 is not a valid argument or domain name"
else
domList=("${domList[@]}" ${validDomain})
@ -84,37 +84,36 @@ HandleOther() {
PopWhitelistFile() {
#check whitelist file exists, and if not, create it
if [[ ! -f ${whitelist} ]];then
if [[ ! -f ${whitelist} ]]; then
touch ${whitelist}
fi
for dom in "${domList[@]}"
do
for dom in "${domList[@]}"; do
if ${addmode}; then
AddDomain "$dom"
AddDomain "${dom}"
else
RemoveDomain "$dom"
RemoveDomain "${dom}"
fi
done
}
AddDomain() {
#| sed 's/\./\\./g'
#| sed 's/\./\\./g'
bool=false
grep -Ex -q "$1" ${whitelist} || bool=true
if ${bool}; then
#domain not found in the whitelist file, add it!
if ${verbose}; then
echo -n "::: Adding $1 to $whitelist..."
echo -n "::: Adding ${1}to ${whitelist}..."
fi
echo "$1" >> ${whitelist}
echo "${1}" >> ${whitelist}
modifyHost=true
if ${verbose}; then
echo " done!"
fi
else
if ${verbose}; then
echo "::: $1 already exists in $whitelist, no need to add!"
echo "::: ${1} already exists in ${whitelist}, no need to add!"
fi
fi
}
@ -126,29 +125,29 @@ RemoveDomain() {
if ${bool}; then
#Domain is not in the whitelist file, no need to Remove
if ${verbose}; then
echo "::: $1 is NOT whitelisted! No need to remove"
echo "::: ${1} is NOT whitelisted! No need to remove"
fi
else
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
#if $verbose; then
#echo "::: Un-whitelisting $dom..."
#fi
domToRemoveList=("${domToRemoveList[@]}" $1)
domToRemoveList=("${domToRemoveList[@]}" ${1})
modifyHost=true
fi
fi
}
ModifyHostFile() {
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)
plural=; [[ "$numberOf" != "1" ]] && plural=s
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}
@ -161,17 +160,16 @@ ModifyHostFile() {
#we need to add the removed domains to the hosts file
echo ":::"
echo "::: Modifying HOSTS file to un-whitelist domains..."
for rdom in "${domToRemoveList[@]}"
do
if grep -q "$rdom" /etc/pihole/*.domains; then
echo "::: AdLists contain $rdom, re-adding block"
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}
for rdom in "${domToRemoveList[@]}"; do
if grep -q "${rdom}" /etc/pihole/*.domains; then
echo "::: AdLists contain ${rdom}, re-adding block"
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 " done!"
else
echo -n "::: Restoring block for $rdom on IPv4..."
echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
echo -n "::: Restoring block for ${rdom} on IPv4..."
echo "${rdom}" | awk -v ipv4addr="${piholeIP}" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
echo " done!"
fi
fi
@ -210,25 +208,23 @@ DisplayWlist() {
verbose=false
echo -e " Displaying Gravity Resistant Domains \n"
count=1
while IFS= read -r RD
do
echo "${count}: $RD"
while IFS= read -r RD; do
echo "${count}: ${RD}"
count=$((count+1))
done < "$whitelist"
done < "${whitelist}"
}
###################################################
for var in "$@"
do
case "$var" in
for var in "$@"; do
case "${var}" in
"-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;;
"-q" | "--quiet" ) verbose=false;;
"-h" | "--help" ) helpFunc;;
"-l" | "--list" ) DisplayWlist;;
* ) HandleOther "$var";;
* ) HandleOther "${var}";;
esac
done

View file

@ -1,5 +1,4 @@
_pihole()
{
_pihole() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"

View file

@ -48,7 +48,7 @@ runUnattended=false
######## FIRST CHECK ########
# Must be root to install
echo ":::"
if [[ $EUID -eq 0 ]];then
if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root."
else
echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures"
@ -56,7 +56,8 @@ else
echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source."
echo ":::"
echo "::: Detecting the presence of the sudo utility for continuation of this install..."
if [ -x "$(command -v sudo)" ];then
if [ -x "$(command -v sudo)" ]; then
echo "::: Utility sudo located."
exec curl -sSL https://install.pi-hole.net | sudo bash "$@"
exit $?
@ -68,7 +69,7 @@ fi
# Compatibility
if [ -x "$(command -v apt-get)" ];then
if [ -x "$(command -v apt-get)" ]; then
#Debian Family
#Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS)
phpVer="php5"
@ -76,11 +77,11 @@ if [ -x "$(command -v apt-get)" ];then
#############################################
PKG_MANAGER="apt-get"
PKG_CACHE="/var/lib/apt/lists/"
UPDATE_PKG_CACHE="$PKG_MANAGER update"
PKG_UPDATE="$PKG_MANAGER upgrade"
PKG_INSTALL="$PKG_MANAGER --yes --fix-missing install"
UPDATE_PKG_CACHE="${PKG_MANAGER} update"
PKG_UPDATE="${PKG_MANAGER} upgrade"
PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing install"
# grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE
PKG_COUNT="$PKG_MANAGER -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5)
PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron iproute2 )
LIGHTTPD_USER="www-data"
@ -88,20 +89,20 @@ if [ -x "$(command -v apt-get)" ];then
LIGHTTPD_CFG="lighttpd.conf.debian"
DNSMASQ_USER="dnsmasq"
package_check_install() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "$1"
dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}"
}
elif [ -x "$(command -v rpm)" ];then
elif [ -x "$(command -v rpm)" ]; then
# Fedora Family
if [ -x "$(command -v dnf)" ];then
if [ -x "$(command -v dnf)" ]; then
PKG_MANAGER="dnf"
else
PKG_MANAGER="yum"
fi
PKG_CACHE="/var/cache/$PKG_MANAGER"
UPDATE_PKG_CACHE="$PKG_MANAGER check-update"
PKG_UPDATE="$PKG_MANAGER update -y"
PKG_INSTALL="$PKG_MANAGER install -y"
PKG_COUNT="$PKG_MANAGER check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
PKG_CACHE="/var/cache/${PKG_MANAGER}"
UPDATE_PKG_CACHE="${PKG_MANAGER} check-update"
PKG_UPDATE="${PKG_MANAGER} update -y"
PKG_INSTALL="${PKG_MANAGER} install -y"
PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
INSTALLER_DEPS=( iproute net-tools procps-ng newt git )
PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat )
if grep -q 'Fedora' /etc/redhat-release; then
@ -113,7 +114,7 @@ elif [ -x "$(command -v rpm)" ];then
LIGHTTPD_CFG="lighttpd.conf.fedora"
DNSMASQ_USER="nobody"
package_check_install() {
rpm -qa | grep ^"$1"- > /dev/null || ${PKG_INSTALL} "$1"
rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}"
}
else
echo "OS distribution not supported"
@ -125,9 +126,9 @@ spinner() {
local pid=$1
local delay=0.50
local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
printf " [%c] " "${spinstr}"
local spinstr=${temp}${spinstr%"$temp"}
sleep ${delay}
printf "\b\b\b\b\b\b"
@ -170,7 +171,7 @@ verifyFreeDiskSpace() {
local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}')
# - Unknown free disk space , not a integer
if ! [[ "$existing_free_kilobytes" =~ ^([0-9])+$ ]]; then
if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then
echo "::: Unknown free disk space!"
echo "::: We were unable to determine available free disk space on this system."
echo "::: You may override this check and force the installation, however, it is not recommended"
@ -181,7 +182,7 @@ verifyFreeDiskSpace() {
elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then
echo "::: Insufficient Disk Space!"
echo "::: Your system appears to be low on disk space. pi-hole recommends a minimum of $required_free_kilobytes KiloBytes."
echo "::: You only have $existing_free_kilobytes KiloBytes free."
echo "::: You only have ${existing_free_kilobytes} KiloBytes free."
echo "::: If this is a new install you may need to expand your disk."
echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'"
echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)"
@ -206,23 +207,21 @@ chooseInterface() {
# Loop sentinel variable
local firstLoop=1
while read -r line
do
while read -r line; do
mode="OFF"
if [[ ${firstLoop} -eq 1 ]]; then
firstLoop=0
mode="ON"
fi
interfacesArray+=("$line" "available" "$mode")
done <<< "$availableInterfaces"
interfacesArray+=("${line}" "available" "${mode}")
done <<< "${availableInterfaces}"
# Find out how many interfaces are available to choose from
interfaceCount=$(echo "$availableInterfaces" | wc -l)
interfaceCount=$(echo "${availableInterfaces}" | wc -l)
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount})
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]]; then
for desiredInterface in ${chooseInterfaceOptions}
do
for desiredInterface in ${chooseInterfaceOptions}; do
piholeInterface=${desiredInterface}
echo "::: Using interface: $piholeInterface"
done
@ -279,8 +278,8 @@ use4andor6() {
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: $IPv4_address
Gateway: $IPv4gw" ${r} ${c}); then
IP address: ${IPv4_address}
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.
@ -290,20 +289,19 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
# 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 ]]
do
until [[ ${ipSettingsCorrect} = True ]]; do
# Ask for the IPv4 address
IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "$IPv4_address" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then
echo "::: Your static IPv4 address: $IPv4_address"
IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4_address}" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]; then
echo "::: Your static IPv4 address: ${IPv4_address}"
# 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)
if [[ $? = 0 ]];then
echo "::: Your static IPv4 gateway: $IPv4gw"
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: $IPv4_address
Gateway: $IPv4gw" ${r} ${c}); then
IP address: ${IPv4_address}
Gateway: ${IPv4gw}" ${r} ${c}); then
# After that's done, the loop ends and we move on
ipSettingsCorrect=True
else
@ -329,31 +327,31 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
setDHCPCD() {
# Append these lines to dhcpcd.conf to enable a static IP
echo "## interface $piholeInterface
static ip_address=$IPv4_address
static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | tee -a /etc/dhcpcd.conf >/dev/null
echo "## interface ${piholeInterface}
static ip_address=${IPv4_address}
static routers=${IPv4gw}
static domain_name_servers=${IPv4gw}" | tee -a /etc/dhcpcd.conf >/dev/null
}
setStaticIPv4() {
local IFCFG_FILE
local IPADDR
local CIDR
if [[ -f /etc/dhcpcd.conf ]];then
if [[ -f /etc/dhcpcd.conf ]]; then
# Debian Family
if grep -q "$IPv4_address" /etc/dhcpcd.conf; then
if grep -q "${IPv4_address}" /etc/dhcpcd.conf; then
echo "::: Static IP already configured"
else
setDHCPCD
ip addr replace dev "$piholeInterface" "$IPv4_address"
ip addr replace dev "${piholeInterface}" "${IPv4_address}"
echo ":::"
echo "::: Setting IP to $IPv4_address. You may need to restart after the install is complete."
echo "::: Setting IP to ${IPv4_address}. You may need to restart after the install is complete."
echo ":::"
fi
elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then
# Fedora Family
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface}
if grep -q "$IPv4_address" "${IFCFG_FILE}"; then
if grep -q "${IPv4_address}" "${IFCFG_FILE}"; then
echo "::: Static IP already configured"
else
IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/)
@ -373,7 +371,7 @@ setStaticIPv4() {
echo "DNS2=$piholeDNS2"
echo "USERCTL=no"
}>> "${IFCFG_FILE}"
ip addr replace dev "$piholeInterface" "$IPv4_address"
ip addr replace dev "${piholeInterface}" "${IPv4_address}"
if [ -x "$(command -v nmcli)" ];then
# Tell NetworkManager to read our new sysconfig file
nmcli con load "${IFCFG_FILE}" > /dev/null
@ -389,7 +387,7 @@ setStaticIPv4() {
}
valid_ip() {
local ip=$1
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
@ -441,45 +439,46 @@ setDNS() {
piholeDNS2="8.20.247.20"
;;
Custom)
until [[ ${DNSSettingsCorrect} = True ]]
do
until [[ ${DNSSettingsCorrect} = True ]]; do
strInvalid="Invalid"
if [ ! ${piholeDNS1} ]; then
if [ ! ${piholeDNS2} ]; then
prePopulate=""
else
prePopulate=", $piholeDNS2"
prePopulate=", ${piholeDNS2}"
fi
elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then
prePopulate="$piholeDNS1"
prePopulate="${piholeDNS1}"
elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then
prePopulate="$piholeDNS1, $piholeDNS2"
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)
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
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}
fi
if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then
if ! valid_ip "${piholeDNS2}" && [ "${piholeDNS2}" ]; then
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
@ -527,12 +526,12 @@ version_check_dnsmasq() {
cp ${dnsmasq_pihole_01_snippet} ${dnsmasq_pihole_01_location}
echo " done."
sed -i "s/@INT@/$piholeInterface/" ${dnsmasq_pihole_01_location}
if [[ "$piholeDNS1" != "" ]]; then
if [[ "${piholeDNS1}" != "" ]]; then
sed -i "s/@DNS1@/$piholeDNS1/" ${dnsmasq_pihole_01_location}
else
sed -i '/^server=@DNS1@/d' ${dnsmasq_pihole_01_location}
fi
if [[ "$piholeDNS2" != "" ]]; then
if [[ "${piholeDNS2}" != "" ]]; then
sed -i "s/@DNS2@/$piholeDNS2/" ${dnsmasq_pihole_01_location}
else
sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location}
@ -573,7 +572,7 @@ installConfigs() {
version_check_dnsmasq
if [ ! -d "/etc/lighttpd" ]; then
mkdir /etc/lighttpd
chown "$USER":root /etc/lighttpd
chown "${USER}":root /etc/lighttpd
mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
fi
cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf
@ -628,13 +627,13 @@ update_pacakge_cache() {
#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})
timestampAsDate=$(date -d @"$timestamp" "+%b %e")
timestampAsDate=$(date -d @"${timestamp}" "+%b %e")
today=$(date "+%b %e")
if [ ! "$today" == "$timestampAsDate" ]; then
if [ ! "${today}" == "${timestampAsDate}" ]; then
#update package lists
echo ":::"
echo -n "::: $PKG_MANAGER update has not been run today. Running now..."
echo -n "::: ${PKG_MANAGER} update has not been run today. Running now..."
${UPDATE_PKG_CACHE} &> /dev/null & spinner $!
echo " done!"
fi
@ -644,15 +643,15 @@ notify_package_updates_available() {
# Let user know if they have outdated packages on their system and
# advise them to run a package update at soonest possible.
echo ":::"
echo -n "::: Checking $PKG_MANAGER for upgraded packages...."
echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...."
updatesToInstall=$(eval "${PKG_COUNT}")
echo " done!"
echo ":::"
if [[ ${updatesToInstall} -eq "0" ]]; then
echo "::: Your system is up to date! Continuing with Pi-hole installation..."
else
echo "::: There are $updatesToInstall updates available for your system!"
echo "::: We recommend you run '$PKG_UPDATE' after installing Pi-Hole! "
echo "::: There are ${updatesToInstall} updates available for your system!"
echo "::: We recommend you run '${PKG_UPDATE}' after installing Pi-Hole! "
echo ":::"
fi
}
@ -786,7 +785,7 @@ configureFirewall() {
finalExports() {
#If it already exists, lets overwrite it with the new values.
if [[ -f ${setupVars} ]];then
if [[ -f ${setupVars} ]]; then
rm ${setupVars}
fi
{
@ -798,7 +797,6 @@ finalExports() {
}>> "${setupVars}"
}
installPihole() {
# Install base files and web interface
create_pihole_user
@ -866,7 +864,7 @@ displayFinalMessage() {
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using:
IPv4: ${IPv4_address%/*}
IPv6: $IPv6_address
IPv6: ${IPv6_address}
If you set a new IP address, you should restart the Pi.
@ -876,7 +874,7 @@ View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admi
update_dialogs() {
# reconfigure
if [ "$reconfigure" = true ]; then
if [ "${reconfigure}" = true ]; then
opt1a="Repair"
opt1b="This will retain existing settings"
strAdd="You will remain on the same version"
@ -889,17 +887,17 @@ update_dialogs() {
opt2b="This will allow you to enter new settings"
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \
"$opt1a" "$opt1b" \
"$opt2a" "$opt2b" 3>&2 2>&1 1>&3)
"${opt1a}" "${opt1b}" \
"${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3)
if [[ $? = 0 ]];then
case ${UpdateCmd} in
${opt1a})
echo "::: $opt1a option selected."
echo "::: ${opt1a} option selected."
useUpdateVars=true
;;
${opt2a})
echo "::: $opt2a option selected"
echo "::: ${opt2a} option selected"
useUpdateVars=false
;;
esac
@ -912,53 +910,52 @@ update_dialogs() {
main() {
# Check arguments for the undocumented flags
for var in "$@"
do
for var in "$@"; do
case "$var" in
"--reconfigure" ) reconfigure=true;;
"--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
"--unattended" ) runUnattended=true;;
esac
done
done
if [[ -f ${setupVars} ]];then
if [[ -f ${setupVars} ]]; then
if [[ "${runUnattended}" == true ]]; then
echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
useUpdateVars=true
else
update_dialogs
fi
fi
fi
# Start the installer
# Verify there is enough disk space for the install
if [[ "${skipSpaceCheck}" == true ]]; then
# Start the installer
# Verify there is enough disk space for the install
if [[ "${skipSpaceCheck}" == true ]]; then
echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
else
else
verifyFreeDiskSpace
fi
fi
# Update package cache
update_pacakge_cache
# Update package cache
update_pacakge_cache
# Notify user of package availability
notify_package_updates_available
# Notify user of package availability
notify_package_updates_available
# Install packages used by this installation script
install_dependent_packages INSTALLER_DEPS[@]
# Install packages used by this installation script
install_dependent_packages INSTALLER_DEPS[@]
# Install packages used by the Pi-hole
install_dependent_packages PIHOLE_DEPS[@]
# Install packages used by the Pi-hole
install_dependent_packages PIHOLE_DEPS[@]
if [[ "${reconfigure}" == true ]]; then
if [[ "${reconfigure}" == true ]]; then
echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
else
else
# Get Git files for Core and Admin
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
fi
fi
if [[ ${useUpdateVars} == false ]]; then
if [[ ${useUpdateVars} == false ]]; then
# Display welcome dialogs
welcomeDialogs
# Create directory for Pi-hole storage
@ -978,39 +975,39 @@ if [[ ${useUpdateVars} == false ]]; then
setDNS
# Install and log everything to a file
installPihole | tee ${tmpLog}
else
else
updatePihole | tee ${tmpLog}
fi
fi
# Move the log file into /etc/pihole for storage
mv ${tmpLog} ${instalLogLoc}
# Move the log file into /etc/pihole for storage
mv ${tmpLog} ${instalLogLoc}
if [[ "${useUpdateVars}" == false ]]; then
if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage
fi
fi
echo "::: Restarting services..."
# Start services
start_service dnsmasq
enable_service dnsmasq
start_service lighttpd
enable_service lighttpd
echo "::: done."
echo "::: Restarting services..."
# Start services
start_service dnsmasq
enable_service dnsmasq
start_service lighttpd
enable_service lighttpd
echo "::: done."
echo ":::"
if [[ "${useUpdateVars}" == false ]]; then
echo ":::"
if [[ "${useUpdateVars}" == false ]]; then
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
echo "::: ${IPv4_address%/*}"
echo "::: $IPv6_address"
echo "::: ${IPv6_address}"
echo ":::"
echo "::: If you set a new IP address, you should restart the Pi."
else
else
echo "::: Update complete!"
fi
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://${IPv4_address%/*}/admin"
echo ":::"
echo "::: The install log is located at: /etc/pihole/install.log"
echo "::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin"
}
main "$@"

View file

@ -11,13 +11,13 @@
# (at your option) any later version.
# Must be root to uninstall
if [[ $EUID -eq 0 ]];then
if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root."
else
echo "::: Sudo will be used for the uninstall."
# Check if it is actually installed
# If it isn't, exit because the unnstall cannot complete
if [ -x "$(command -v sudo)" ];then
if [ -x "$(command -v sudo)" ]; then
export SUDO="sudo"
else
echo "::: Please install sudo or run this as root."
@ -26,14 +26,14 @@ else
fi
# Compatability
if [ -x "$(command -v rpm)" ];then
if [ -x "$(command -v rpm)" ]; then
# Fedora Family
if [ -x "$(command -v dnf)" ];then
if [ -x "$(command -v dnf)" ]; then
PKG_MANAGER="dnf"
else
PKG_MANAGER="yum"
fi
PKG_REMOVE="$PKG_MANAGER remove -y"
PKG_REMOVE="${PKG_MANAGER} remove -y"
PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils )
package_check() {
rpm -qa | grep ^$1- > /dev/null
@ -41,10 +41,10 @@ if [ -x "$(command -v rpm)" ];then
package_cleanup() {
${SUDO} ${PKG_MANAGER} -y autoremove
}
elif [ -x "$(command -v apt-get)" ];then
elif [ -x "$(command -v apt-get)" ]; then
# Debian Family
PKG_MANAGER="apt-get"
PKG_REMOVE="$PKG_MANAGER -y remove --purge"
PKG_REMOVE="${PKG_MANAGER} -y remove --purge"
PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget )
package_check() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
@ -62,10 +62,10 @@ spinner() {
local pid=$1
local delay=0.50
local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=${temp}${spinstr%"$temp"}
printf " [%c] " "${spinstr}"
local spinstr=${temp}${spinstr%"$temp}"}
sleep ${delay}
printf "\b\b\b\b\b\b"
done
@ -79,15 +79,15 @@ removeAndPurge() {
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
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;;
[Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;;
[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
done
else
printf ":::\tPackage %s not installed... Not removing.\n" "$i"
printf ":::\tPackage %s not installed... Not removing.\n" "${i}"
fi
done

View file

@ -56,7 +56,7 @@ eventHorizon=${basename}.2.eventHorizon.txt
accretionDisc=${basename}.3.accretionDisc.txt
# Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it)
if [[ -r ${piholeDir}/pihole.conf ]];then
if [[ -r ${piholeDir}/pihole.conf ]]; then
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."
fi
@ -95,7 +95,7 @@ gravity_collapse() {
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
@ -113,11 +113,11 @@ gravity_collapse() {
gravity_patternCheck() {
patternBuffer=$1
# check if the patternbuffer is a non-zero length file
if [[ -s "$patternBuffer" ]];then
if [[ -s "${patternBuffer}" ]]; then
# Some of the blocklists are copyright, they need to be downloaded
# and stored as is. They can be processed for content after they
# have been saved.
cp "$patternBuffer" "$saveLocation"
cp "${patternBuffer}" "${saveLocation}"
echo " List updated, transport successful!"
else
# curl didn't download any host files, probably because of the date check
@ -136,26 +136,25 @@ gravity_transport() {
heisenbergCompensator=""
if [[ -r ${saveLocation} ]]; then
# if domain has been saved, add file for date check to only download newer
heisenbergCompensator="-z $saveLocation"
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"
gravity_patternCheck "${patternBuffer}"
# Cleanup
rm -f "$patternBuffer"
rm -f "${patternBuffer}"
}
# spinup - main gravity function
gravity_spinup() {
echo ":::"
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
for ((i = 0; i < "${#sources[@]}"; i++))
do
for ((i = 0; i < "${#sources[@]}"; i++)); do
url=${sources[$i]}
# Get just the domain from the URL
domain=$(echo "$url" | cut -d'/' -f3)
domain=$(echo "${url}" | cut -d'/' -f3)
# Save the file as list.#.domain
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
@ -163,11 +162,11 @@ gravity_spinup() {
agent="Mozilla/10.0"
echo -n "::: Getting $domain list..."
echo -n "::: Getting ${domain} list..."
# Use a case statement to download lists that need special cURL commands
# to complete properly and reset the user agent when required
case "$domain" in
case "${domain}" in
"adblock.mahakala.is")
agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
cmd_ext="-e http://forum.xda-developers.com/"
@ -180,7 +179,7 @@ gravity_spinup() {
# Default is a simple request
*) cmd_ext=""
esac
gravity_transport "$url" "$cmd_ext" "$agent"
gravity_transport "${url}" "${cmd_ext}" "${agent}"
done
}
@ -190,9 +189,8 @@ gravity_Schwarzchild() {
# Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..."
truncate -s 0 ${piholeDir}/${matterAndLight}
for i in "${activeDomains[@]}"
do
cat "$i" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
for i in "${activeDomains[@]}"; do
cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
done
echo " done!"
}
@ -203,8 +201,8 @@ gravity_Blacklist() {
${blacklistScript} -f -nr -q > /dev/null
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
echo " $numBlacklisted domain${plural} blacklisted!"
plural=; [[ "${numBlacklisted}" != "1" ]] && plural=s
echo " ${numBlacklisted} domain${plural} blacklisted!"
}
gravity_Whitelist() {
@ -214,9 +212,8 @@ gravity_Whitelist() {
echo -n "::: Adding ${#sources[@]} adlist source${plural} to the whitelist..."
urls=()
for url in "${sources[@]}"
do
tmp=$(echo "$url" | awk -F '/' '{print $3}')
for url in "${sources[@]}"; do
tmp=$(echo "${url}" | awk -F '/' '{print $3}')
urls=("${urls[@]}" ${tmp})
done
echo " done!"
@ -224,8 +221,8 @@ gravity_Whitelist() {
echo -n "::: Running whitelist script to update HOSTS file...."
${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!"
plural=; [[ "${numWhitelisted}" != "1" ]] && plural=s
echo " ${numWhitelisted} domain${plural} whitelisted!"
}
gravity_unique() {
@ -234,7 +231,7 @@ gravity_unique() {
sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon}
echo " done!"
numberOf=$(wc -l < ${piholeDir}/${eventHorizon})
echo "::: $numberOf unique domains trapped in the event horizon."
echo "::: ${numberOf} unique domains trapped in the event horizon."
}
gravity_hostFormat() {
@ -248,15 +245,15 @@ gravity_hostFormat() {
echo "::: Error: Unable to determine fully qualified domain name of host"
fi
# 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 "${IPv6_address}" ]];then
if [[ -n "${IPv6_address}" ]]; 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 "$IPv4addr $hostname\n$IPv6_address $hostname\n$IPv4addr pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
echo -e "${IPv4addr} ${hostname}\n${IPv6_address} ${hostname}\n${IPv4addr} pi.hole\n${IPv6_address} pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4addr}" -v ipv6addr="${IPv6_address}" '{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 "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
echo -e "${IPv4addr} ${hostname}\n${IPv4addr} pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4addr}" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
@ -266,13 +263,12 @@ gravity_hostFormat() {
# blackbody - remove any remnant files from script processes
gravity_blackbody() {
# Loop through list files
for file in ${piholeDir}/*.${justDomainsExtension}
do
for file in ${piholeDir}/*.${justDomainsExtension}; do
# If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
:
else
rm -f "$file"
rm -f "${file}"
fi
done
}
@ -290,7 +286,7 @@ gravity_advanced() {
echo " done!"
numberOf=$(wc -l < ${piholeDir}/${supernova})
echo "::: $numberOf domains being pulled in by gravity..."
echo "::: ${numberOf} domains being pulled in by gravity..."
gravity_unique
}
@ -310,8 +306,8 @@ gravity_reload() {
#First escape forward slashes in the path:
adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file
sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
find "$piholeDir" -type f -exec chmod 666 {} \;
sed -i "s/^addn-hosts.*/addn-hosts=${adList}/" /etc/dnsmasq.d/01-pihole.conf
find "${piholeDir}" -type f -exec chmod 666 {} \;
dnsmasqPid=$(pidof dnsmasq)
@ -333,9 +329,8 @@ gravity_reload() {
}
for var in "$@"
do
case "$var" in
for var in "$@"; do
case "${var}" in
"-f" | "--force" ) forceGrav=true;;
"-h" | "--help" ) helpFunc;;
esac

73
pihole
View file

@ -66,8 +66,7 @@ setupLCDFunction() {
queryFunc() {
domain=$2
for list in /etc/pihole/list.*
do
for list in /etc/pihole/list.*; do
count=$(grep ${domain} $list | wc -l)
echo "::: ${list} (${count} results)"
if [[ ${count} > 0 ]]; then
@ -97,25 +96,27 @@ versionFunc() {
}
helpFunc() {
echo "::: Control all PiHole specific functions!"
echo ":::"
echo "::: Usage: pihole [options]"
echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage"
echo ":::"
echo "::: Options:"
echo "::: -w, whitelist Whitelist domains"
echo "::: -b, blacklist Blacklist domains"
echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -f, flush Flush the pihole.log file"
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"
echo "::: -h, help Show this help dialog"
echo "::: -v, version Show current versions"
echo "::: -q, query Query the adlists for a specific domain"
echo "::: uninstall Uninstall Pi-Hole from your system :(!"
exit 0
cat << EOM
::: Control all PiHole specific functions!
:::
::: Usage: pihole [options]
::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage
:::
::: Options:
::: -w, whitelist Whitelist domains
::: -b, blacklist Blacklist domains
::: -d, debug Start a debugging session if having trouble
::: -f, flush Flush the pihole.log file
::: -up, updatePihole Update Pi-hole
::: -g, updateGravity Update the list of ad-serving domains
::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it
::: -c, chronometer Calculates stats and displays to an LCD
::: -h, help Show this help dialog
::: -v, version Show current versions
::: -q, query Query the adlists for a specific domain
::: uninstall Uninstall Pi-Hole from your system :(!
EOM
exit 1
}
if [[ $# = 0 ]]; then
@ -123,19 +124,19 @@ if [[ $# = 0 ]]; then
fi
# Handle redirecting to specific functions based on arguments
case "$1" in
"-w" | "whitelist" ) whitelistFunc "$@";;
"-b" | "blacklist" ) blacklistFunc "$@";;
"-d" | "debug" ) debugFunc;;
"-f" | "flush" ) flushFunc;;
"-up" | "updatePihole" ) updatePiholeFunc;;
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";;
"-s" | "setupLCD" ) setupLCDFunction;;
"-c" | "chronometer" ) chronometerFunc "$@";;
"-h" | "help" ) helpFunc;;
"-v" | "version" ) versionFunc "$@";;
"-q" | "query" ) queryFunc "$@";;
"uninstall" ) uninstallFunc;;
* ) helpFunc;;
case "${1}" in
"-w" | "whitelist" ) whitelistFunc "$@";;
"-b" | "blacklist" ) blacklistFunc "$@";;
"-d" | "debug" ) debugFunc;;
"-f" | "flush" ) flushFunc;;
"-up" | "updatePihole" ) updatePiholeFunc;;
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";;
"-s" | "setupLCD" ) setupLCDFunction;;
"-c" | "chronometer" ) chronometerFunc "$@";;
"-h" | "help" ) helpFunc;;
"-v" | "version" ) versionFunc "$@";;
"-q" | "query" ) queryFunc "$@";;
"uninstall" ) uninstallFunc;;
* ) helpFunc;;
esac