Merge pull request #11 from diginc/2.6.2_update

Updated version, support for custom DNS server override env vars
This commit is contained in:
diginc
2016-04-25 23:25:54 -05:00
12 changed files with 182 additions and 153 deletions

View File

@@ -1 +1 @@
v1.1.4 v1.2

View File

@@ -2,22 +2,14 @@ A Docker project to make lightweight x86 continers with [pi-hole](https://pi-hol
[![Build Status](https://travis-ci.org/diginc/docker-pi-hole.svg?branch=master)](https://travis-ci.org/diginc/docker-pi-hole) [![Build Status](https://travis-ci.org/diginc/docker-pi-hole.svg?branch=master)](https://travis-ci.org/diginc/docker-pi-hole)
## Docker tags *April 25, 2016 Update*: piholeIP env var replaced by ServerIP env var, update your docker run/docker-compose configs accordingly please.
### Alpine
[![](https://badge.imagelayers.io/diginc/pi-hole:alpine.svg)](https://imagelayers.io/?images=diginc/pi-hole:alpine 'Get your own badge on imagelayers.io')
This is an optimized docker using [alpine](https://hub.docker.com/_/alpine/) as its base. It uses nginx instead of lighttpd.
### Debian
[![](https://badge.imagelayers.io/diginc/pi-hole:debian.svg)](https://imagelayers.io/?images=diginc/pi-hole:debian 'Get your own badge on imagelayers.io')
This version of the docker aims to be as close to a standard pi-hole installation by using the same base OS and the exact configs and scripts (minimally modified to get them working). This serves as a nice baseline for merging and testing upstream repository pi-hole changes.
## Basic Docker Usage ## Basic Docker Usage
If you have no other dockers using port 80 (if you do, read the list below for reverse proxy advice), the minimum options required to run this container are in the script [docker_run.sh](https://github.com/diginc/docker-pi-hole/blob/master/docker_run.sh): If you have no other dockers using port 80 (if you do, read the list below for reverse proxy advice), the minimum options required to run this container are in the script [docker_run.sh](https://github.com/diginc/docker-pi-hole/blob/master/docker_run.sh):
To customize your upstream DNS servers you use docker environment varibales of *DNS1* and *DNS2* passed into docker at runtime. The default servers are Google's 8.8.8.8 and 8.8.4.4.
``` ```
IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
docker run -p 53:53/tcp -p 53:53/udp -p 80:80 --cap-add=NET_ADMIN -e piholeIP="$IP" --name pihole -d diginc/pi-hole docker run -p 53:53/tcp -p 53:53/udp -p 80:80 --cap-add=NET_ADMIN -e piholeIP="$IP" --name pihole -d diginc/pi-hole
@@ -41,6 +33,19 @@ Here are some useful volume mount options to persist your history of stats in th
All of these options get really long when strung together in one command, which is why I'm not going to show all the full commands variations. This is where [docker-compose](https://docs.docker.com/compose/install/) yml files come in handy for representing [really long docker commands in a readable file format](https://github.com/diginc/docker-pi-hole/blob/master/doco-example.yml). All of these options get really long when strung together in one command, which is why I'm not going to show all the full commands variations. This is where [docker-compose](https://docs.docker.com/compose/install/) yml files come in handy for representing [really long docker commands in a readable file format](https://github.com/diginc/docker-pi-hole/blob/master/doco-example.yml).
## Docker tags
### Alpine
[![](https://badge.imagelayers.io/diginc/pi-hole:alpine.svg)](https://imagelayers.io/?images=diginc/pi-hole:alpine 'Get your own badge on imagelayers.io')
This is an optimized docker using [alpine](https://hub.docker.com/_/alpine/) as its base. It uses nginx instead of lighttpd.
### Debian
[![](https://badge.imagelayers.io/diginc/pi-hole:debian.svg)](https://imagelayers.io/?images=diginc/pi-hole:debian 'Get your own badge on imagelayers.io')
This version of the docker aims to be as close to a standard pi-hole installation by using the same base OS and the exact configs and scripts (minimally modified to get them working). This serves as a nice baseline for merging and testing upstream repository pi-hole changes.
## Advanced Usage and Notes ## Advanced Usage and Notes
The standard pi-hole customization abilities apply to this docker, but with docker twists such as using docker volume mounts to map host stored file configurations over the container defaults. Volumes are also important to persist the configuration incase you have remove the pi-hole container which is a typical docker upgrade pattern. The standard pi-hole customization abilities apply to this docker, but with docker twists such as using docker volume mounts to map host stored file configurations over the container defaults. Volumes are also important to persist the configuration incase you have remove the pi-hole container which is a typical docker upgrade pattern.

View File

@@ -15,8 +15,10 @@ COPY ./alpine/gravity.sh /usr/local/bin/
COPY ./alpine/nginx.conf /etc/nginx/nginx.conf COPY ./alpine/nginx.conf /etc/nginx/nginx.conf
# Original upstream pihole code being used # Original upstream pihole code being used
COPY ./pi-hole/adlists.default /etc/pihole/ COPY ./pi-hole/adlists.default /etc/pihole/
COPY ./pi-hole/pihole /usr/local/bin/
COPY ./pi-hole/advanced/Scripts/* /usr/local/bin/ COPY ./pi-hole/advanced/Scripts/* /usr/local/bin/
COPY ./pi-hole/advanced/01-pihole.conf /etc/dnsmasq.conf COPY ./pi-hole/advanced/dnsmasq.conf.original /etc/dnsmasq.conf
COPY ./pi-hole/advanced/01-pihole.conf /etc/dnsmasq.d/
COPY ./pi-hole/advanced/index.html /var/www/html/pihole/index.html COPY ./pi-hole/advanced/index.html /var/www/html/pihole/index.html
COPY ./AdminLTE /var/www/html/admin COPY ./AdminLTE /var/www/html/admin
COPY ./AdminLTE_version.txt /etc/ COPY ./AdminLTE_version.txt /etc/
@@ -31,15 +33,14 @@ RUN mkdir -p /etc/pihole/ && \
touch /var/log/pihole.log && \ touch /var/log/pihole.log && \
chmod 644 /var/log/pihole.log && \ chmod 644 /var/log/pihole.log && \
chown dnsmasq:root /var/log/pihole.log && \ chown dnsmasq:root /var/log/pihole.log && \
sed -i "s/@INT@/eth0/" /etc/dnsmasq.conf && \ sed -i "s/@INT@/eth0/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i "s/@DNS1@/8.8.8.8/" /etc/dnsmasq.conf && \
sed -i "s/@DNS2@/8.8.4.4/" /etc/dnsmasq.conf && \
sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \ sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \
sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php
# This chould be eliminated if the (upstream) files were +x in git # This chould be eliminated if all (upstream) files were +x in git
RUN chmod +x /usr/local/bin/*.sh RUN chmod +x /usr/local/bin/*.sh
# Fix for docker
# Fix dnsmasq in docker
RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf
COPY ./alpine/start.sh / COPY ./alpine/start.sh /

View File

@@ -12,18 +12,19 @@
# Run this script as root or under sudo # Run this script as root or under sudo
echo ":::" echo ":::"
if [[ $EUID -eq 0 ]];then if [[ $EUID -eq 0 ]];then
echo "::: You are root." echo "::: You are root."
else else
echo "::: sudo will be used." echo "::: sudo will be used."
# Check if it is actually installed # Check if it is actually installed
# If it isn't, exit because the install cannot complete # If it isn't, exit because the install cannot complete
if [[ $(dpkg-query -s sudo) ]];then if [[ $(dpkg-query -s sudo) ]];then
export SUDO="sudo" export SUDO="sudo"
else else
echo "::: Please install sudo or run this script as root." echo "::: Please install sudo or run this script as root."
exit 1 exit 1
fi fi
fi fi
piholeIPfile=/tmp/piholeIP piholeIPfile=/tmp/piholeIP
@@ -31,8 +32,8 @@ piholeIPv6file=/etc/pihole/.useIPv6
adListFile=/etc/pihole/adlists.list adListFile=/etc/pihole/adlists.list
adListDefault=/etc/pihole/adlists.default adListDefault=/etc/pihole/adlists.default
whitelistScript=/usr/local/bin/whitelist.sh whitelistScript=/opt/pihole/whitelist.sh
blacklistScript=/usr/local/bin/blacklist.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 # 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
@@ -41,7 +42,7 @@ if [[ -f $piholeIPfile ]];then
else 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 # 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)}') 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%/*} piholeIP=${piholeIPCIDR%/*}
fi fi
@@ -50,22 +51,20 @@ if [[ -f $piholeIPv6file ]];then
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
# Variables for various stages of downloading and formatting the list # Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/$basename
adList=$piholeDir/gravity.list adList=$piholeDir/gravity.list
blacklist=$piholeDir/blacklist.txt #blacklist=$piholeDir/blacklist.txt
whitelist=$piholeDir/whitelist.txt #whitelist=$piholeDir/whitelist.txt
latentWhitelist=$piholeDir/latentWhitelist.txt #latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt matterandlight=$basename.0.matterandlight.txt
supernova=$basename.1.supernova.txt supernova=$basename.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt eventHorizon=$basename.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.txt accretionDisc=$basename.3.accretionDisc.txt
eyeOfTheNeedle=$basename.4.wormhole.txt #eyeOfTheNeedle=$basename.4.wormhole.txt
# After setting defaults, check if there's local overrides # After setting defaults, check if there's local overrides
if [[ -r $piholeDir/pihole.conf ]];then if [[ -r $piholeDir/pihole.conf ]];then
@@ -73,22 +72,6 @@ if [[ -r $piholeDir/pihole.conf ]];then
. $piholeDir/pihole.conf . $piholeDir/pihole.conf
fi fi
spinner(){
local pid=$1
local delay=0.001
local spinstr='/-\|'
spin='-\|/'
i=0
while $SUDO kill -0 $pid 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\b${spin:$i:1}"
sleep .1
done
printf "\b"
}
########################### ###########################
# collapse - begin formation of pihole # collapse - begin formation of pihole
function gravity_collapse() { function gravity_collapse() {
@@ -99,7 +82,7 @@ function gravity_collapse() {
#custom file found, use this instead of default #custom file found, use this instead of default
echo -n "::: Custom adList file detected. Reading..." echo -n "::: Custom adList file detected. Reading..."
sources=() sources=()
while read -a line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ $line = \#* ]] || [[ ! $line ]]; then
echo "" > /dev/null echo "" > /dev/null
@@ -107,12 +90,12 @@ function gravity_collapse() {
sources+=($line) sources+=($line)
fi fi
done < $adListFile done < $adListFile
echo " done!" echo " done!"
else else
#no custom file found, use defaults! #no custom file found, use defaults!
echo -n "::: No custom adlist file detected, reading from default file..." echo -n "::: No custom adlist file detected, reading from default file..."
sources=() sources=()
while read -a line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ $line = \#* ]] || [[ ! $line ]]; then
echo "" > /dev/null echo "" > /dev/null
@@ -120,8 +103,8 @@ function gravity_collapse() {
sources+=($line) sources+=($line)
fi fi
done < $adListDefault done < $adListDefault
echo " done!" echo " done!"
fi fi
# Create the pihole resource directory if it doesn't exist. Future files will be stored here # Create the pihole resource directory if it doesn't exist. Future files will be stored here
if [[ -d $piholeDir ]];then if [[ -d $piholeDir ]];then
@@ -129,12 +112,12 @@ function gravity_collapse() {
# Will update later, needed for existing installs, new installs should # Will update later, needed for existing installs, new installs should
# create this directory as non-root # create this directory as non-root
$SUDO chmod 777 $piholeDir $SUDO chmod 777 $piholeDir
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; & spinner $! echo ":::"
echo "." echo "::: Existing pihole directory found"
else else
echo -n "::: Creating pihole directory..." echo "::: Creating pihole directory..."
mkdir $piholeDir & spinner $! mkdir $piholeDir
echo " done!" $SUDO chmod 777 $piholeDir
fi fi
} }
@@ -146,7 +129,7 @@ function gravity_patternCheck() {
# Some of the blocklists are copyright, they need to be downloaded # Some of the blocklists are copyright, they need to be downloaded
# and stored as is. They can be processed for content after they # and stored as is. They can be processed for content after they
# have been saved. # have been saved.
cp $patternBuffer $saveLocation cp "$patternBuffer" "$saveLocation"
echo " List updated, transport successful!" echo " List updated, transport successful!"
else else
# curl didn't download any host files, probably because of the date check # curl didn't download any host files, probably because of the date check
@@ -169,17 +152,16 @@ function gravity_transport() {
fi fi
# Silently curl url # Silently curl url
curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
# Check for list updates # Check for list updates
gravity_patternCheck $patternBuffer gravity_patternCheck "$patternBuffer"
# Cleanup # Cleanup
rm -f $patternBuffer rm -f "$patternBuffer"
} }
# spinup - main gravity function # spinup - main gravity function
function gravity_spinup() { function gravity_spinup() {
echo "::: " echo ":::"
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
for ((i = 0; i < "${#sources[@]}"; i++)) for ((i = 0; i < "${#sources[@]}"; i++))
do do
@@ -198,17 +180,17 @@ function gravity_spinup() {
# Use a case statement to download lists that need special cURL commands # Use a case statement to download lists that need special cURL commands
# to complete properly and reset the user agent when required # to complete properly and reset the user agent when required
case "$domain" in case "$domain" in
"adblock.mahakala.is") "adblock.mahakala.is")
agent='Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' agent='Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0'
cmd_ext="-e http://forum.xda-developers.com/" cmd_ext="-e http://forum.xda-developers.com/"
;; ;;
"pgl.yoyo.org") "pgl.yoyo.org")
cmd_ext="-d mimetype=plaintext -d hostformat=hosts" cmd_ext="-d mimetype=plaintext -d hostformat=hosts"
;; ;;
# Default is a simple request # Default is a simple request
*) cmd_ext="" *) cmd_ext=""
esac esac
gravity_transport "$url" "$cmd_ext" "$agent" gravity_transport "$url" "$cmd_ext" "$agent"
done done
@@ -216,81 +198,73 @@ function gravity_spinup() {
# Schwarzchild - aggregate domains to one list and add blacklisted domains # Schwarzchild - aggregate domains to one list and add blacklisted domains
function gravity_Schwarzchild() { function gravity_Schwarzchild() {
echo "::: " echo "::: "
# Find all active domains and compile them into one file and remove CRs # Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..." echo -n "::: Aggregating list of domains..."
truncate -s 0 $piholeDir/$matterandlight & spinner $! truncate -s 0 $piholeDir/$matterandlight
for i in "${activeDomains[@]}" for i in "${activeDomains[@]}"
do do
cat $i |tr -d '\r' >> $piholeDir/$matterandlight cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight
done done
echo " done!" echo " done!"
} }
function gravity_Blacklist(){ function gravity_Blacklist(){
# Append blacklist entries if they exist # Append blacklist entries if they exist
echo -n "::: Running blacklist script to update HOSTS file...." echo -n "::: Running blacklist script to update HOSTS file...."
$blacklistScript -f -nr -q > /dev/null & spinner $! $blacklistScript -f -nr -q > /dev/null
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
echo " $numBlacklisted domain${plural} blacklisted!" echo " $numBlacklisted domain${plural} blacklisted!"
} }
function gravity_Whitelist() { function gravity_Whitelist() {
echo ":::" echo ":::"
# Prevent our sources from being pulled into the hole # Prevent our sources from being pulled into the hole
plural=; [[ "${sources[@]}" != "1" ]] && plural=s plural=; [[ "${sources[@]}" != "1" ]] && plural=s
echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..." echo -n "::: Adding ${#sources[@]} adlist source${plural} to the whitelist..."
urls=() urls=()
for url in ${sources[@]} for url in "${sources[@]}"
do do
tmp=$(echo "$url" | awk -F '/' '{print $3}') tmp=$(echo "$url" | awk -F '/' '{print $3}')
urls=("${urls[@]}" $tmp) urls=("${urls[@]}" $tmp)
done done
echo " done!" echo " done!"
echo -n "::: Running whitelist script to update HOSTS file...." echo -n "::: Running whitelist script to update HOSTS file...."
$whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $! $whitelistScript -f -nr -q "${urls[@]}" > /dev/null
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!" echo " $numWhitelisted domain${plural} whitelisted!"
} }
function gravity_unique() { function gravity_unique() {
# Sort and remove duplicates # Sort and remove duplicates
echo -n "::: Removing duplicate domains...." echo -n "::: Removing duplicate domains...."
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon & spinner $! sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$eventHorizon) numberOf=$(wc -l < $piholeDir/$eventHorizon)
echo "::: $numberOf unique domains trapped in the event horizon." echo "::: $numberOf unique domains trapped in the event horizon."
} }
function gravity_hostFormat() { function gravity_hostFormat() {
# Format domain list as "192.168.x.x domain.com" # Format domain list as "192.168.x.x domain.com"
echo "::: Formatting domains into a HOSTS file..." echo "::: Formatting domains into a HOSTS file..."
# 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 hostname=$(</etc/hostname)
if [[ -n $piholeIPv6 ]];then # 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
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! if [[ -n $piholeIPv6 ]];then
echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc # 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)
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 else
# Otherwise, just create gravity.list as normal using IPv4 # Otherwise, just create gravity.list as normal using IPv4
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! # 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 Pi-Hole.IsWorking.OK" > $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 cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
fi fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp $piholeDir/$accretionDisc $adList cp $piholeDir/$accretionDisc $adList
} }
@@ -301,52 +275,55 @@ function gravity_blackbody() {
for file in $piholeDir/*.$justDomainsExtension for file in $piholeDir/*.$justDomainsExtension
do do
# If list is in active array then leave it (noop) else rm the list # If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
: :
else else
rm -f $file rm -f "$file"
fi fi
done done
} }
function gravity_advanced() { function gravity_advanced() {
# Remove comments and print only the domain name # Remove comments and print only the domain name
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious # Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious
# This helps with that and makes it easier to read # 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 # 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...." 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 & spinner $! awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$supernova) numberOf=$(wc -l < $piholeDir/$supernova)
echo "::: $numberOf domains being pulled in by gravity..." echo "::: $numberOf domains being pulled in by gravity..."
gravity_unique gravity_unique
} }
function gravity_reload() { function gravity_reload() {
#Clear no longer needed files... #Clear no longer needed files...
echo ":::" echo ":::"
echo -n "::: Cleaning up un-needed files..." echo -n "::: Cleaning up un-needed files..."
$SUDO rm /etc/pihole/pihole.* $SUDO rm $piholeDir/pihole.*.txt
echo " done!" echo " done!"
# Reload hosts file # Reload hosts file
echo ":::" echo ":::"
echo -n "::: Refresh lists in dnsmasq..." echo -n "::: Refresh lists in dnsmasq..."
#ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
#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
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; & spinner $! find "$piholeDir" -type f -exec $SUDO chmod 666 {} \;
if [[ $dnsmasqPid ]]; then if [[ $dnsmasqPid ]]; then
# service already running - reload config # service already running - reload config
$SUDO kill -HUP $dnsmasqPid & spinner $! $SUDO kill -HUP "$dnsmasqPid"
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start & spinner $! $SUDO service dnsmasq start
fi fi
echo " done!" echo " done!"
} }

View File

@@ -1,18 +1,29 @@
#!/bin/sh #!/bin/sh
dnsmasq --test || exit 1 if [ -n "$ServerIP" ] ; then
php-fpm -t || exit 1
nginx -t || exit 1
if [ -n "$piholeIP" ] ; then
# /tmp/piholeIP is the current override of auto-lookup in gravity.sh # /tmp/piholeIP is the current override of auto-lookup in gravity.sh
echo "$piholeIP" > /tmp/piholeIP; echo "$ServerIP" > /tmp/piholeIP;
else else
echo "ERROR: It is required you pass an environment variables of 'piholeIP' with the IP of your docker host which you are passing 80/53 from" echo "ERROR: To function correctly you must pass an environment variables of 'ServerIP' into the docker container with the IP of your docker host from which you are passing web (80) and dns (53) ports from"
exit 1 exit 1
fi; fi;
gravity.sh # pi-hole version minus the service dnsmasq start dnsType='default'
dnsmasq DNS1=${DNS1:-'8.8.8.8'}
DNS2=${DNS2:-'8.8.4.4'}
if [ "$DNS1" != '8.8.8.8' ] || [ "$DNS2" != '8.8.4.4' ] ; then
dnsType='custom'
fi;
echo "Using $dnsType DNS servers: $DNS1 & $DNS2"
sed -i "s/@DNS1@/$DNS1/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i "s/@DNS2@/$DNS2/" /etc/dnsmasq.d/01-pihole.conf && \
dnsmasq --test -7 /etc/dnsmasq.d || exit 1
php-fpm -t || exit 1
nginx -t || exit 1
gravity.sh # pi-hole version without 'service dnsmasq start'
dnsmasq -7 /etc/dnsmasq.d
php-fpm php-fpm
nginx nginx

View File

@@ -20,9 +20,11 @@ RUN apt-get -q update && \
# Original upstream pihole code being used # Original upstream pihole code being used
COPY ./pi-hole/gravity.sh /usr/local/bin/ COPY ./pi-hole/gravity.sh /usr/local/bin/
COPY ./pi-hole/adlists.default /etc/pihole/ COPY ./pi-hole/adlists.default /etc/pihole/
COPY ./pi-hole/pihole /usr/local/bin/
COPY ./pi-hole/advanced/Scripts/* /usr/local/bin/ COPY ./pi-hole/advanced/Scripts/* /usr/local/bin/
COPY ./pi-hole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf COPY ./pi-hole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf
COPY ./pi-hole/advanced/01-pihole.conf /etc/dnsmasq.conf COPY ./pi-hole/advanced/dnsmasq.conf.original /etc/dnsmasq.conf
COPY ./pi-hole/advanced/01-pihole.conf /etc/dnsmasq.d/
COPY ./pi-hole/advanced/index.html /var/www/html/pihole/index.html COPY ./pi-hole/advanced/index.html /var/www/html/pihole/index.html
COPY ./AdminLTE /var/www/html/admin COPY ./AdminLTE /var/www/html/admin
COPY ./AdminLTE_version.txt /etc/ COPY ./AdminLTE_version.txt /etc/
@@ -37,17 +39,20 @@ RUN mkdir -p /etc/pihole/ && \
touch /var/log/pihole.log && \ touch /var/log/pihole.log && \
chmod 644 /var/log/pihole.log && \ chmod 644 /var/log/pihole.log && \
chown dnsmasq:root /var/log/pihole.log && \ chown dnsmasq:root /var/log/pihole.log && \
sed -i "s/@INT@/eth0/" /etc/dnsmasq.conf && \ sed -i "s/@INT@/eth0/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i "s/@DNS1@/8.8.8.8/" /etc/dnsmasq.conf && \
sed -i "s/@DNS2@/8.8.4.4/" /etc/dnsmasq.conf && \
sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \ sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \
sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php
# This chould be eliminated if the files were +x in git # This chould be eliminated if all (upstream) files were +x in git
RUN chmod +x /usr/local/bin/*.sh RUN chmod +x /usr/local/bin/*.sh
# Fix just for docker
# Fix dnsmasq in docker
RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf
COPY ./debian/start.sh / COPY ./debian/start.sh /
EXPOSE 53 53/udp
EXPOSE 80
ENTRYPOINT ["/tini", "--"] ENTRYPOINT ["/tini", "--"]
CMD /start.sh CMD /start.sh

25
debian/start.sh vendored
View File

@@ -1,16 +1,27 @@
#!/bin/sh #!/bin/sh
dnsmasq --test || exit 1 if [ -n "$ServerIP" ] ; then
lighttpd -t -f /etc/lighttpd/lighttpd.conf || exit 1
if [ -n "$piholeIP" ] ; then
# /tmp/piholeIP is the current override of auto-lookup in gravity.sh # /tmp/piholeIP is the current override of auto-lookup in gravity.sh
echo "$piholeIP" > /tmp/piholeIP; echo "$ServerIP" > /tmp/piholeIP;
else else
echo "ERROR: It is required you pass an environment variables of 'piholeIP' with the IP of your docker host which you are passing 80/53 from" echo "ERROR: It is required you pass an environment variables of 'ServerIP' with the IP of your docker host which you are passing 80/53 from"
exit 1 exit 1
fi; fi;
dnsType='default'
DNS1=${DNS1:-'8.8.8.8'}
DNS2=${DNS2:-'8.8.4.4'}
if [ "$DNS1" != '8.8.8.8' ] || [ "$DNS2" != '8.8.4.4' ] ; then
dnsType='custom'
fi;
echo "Using $dnsType DNS servers: $DNS1 & $DNS2"
sed -i "s/@DNS1@/$DNS1/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i "s/@DNS2@/$DNS2/" /etc/dnsmasq.d/01-pihole.conf && \
dnsmasq --test -7 /etc/dnsmasq.d || exit 1
lighttpd -t -f /etc/lighttpd/lighttpd.conf || exit 1
gravity.sh # dnsmasq start included gravity.sh # dnsmasq start included
service lighttpd start service lighttpd start
tail -f /var/log/lighttpd/*.log /var/log/pihole.log tail -F /var/log/lighttpd/*.log /var/log/pihole.log

13
docker_dev.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
docker build -f alpine.docker -t dockerpihole_alpine .
docker build -f debian.docker -t dockerpihole_debian .
IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
docker run -it --rm --cap-add=NET_ADMIN \
-p 5053:53/tcp \
-p 5053:53/udp \
-p 5080:80 \
-e ServerIP="$IP" \
$@ \
dockerpihole_${image:-alpine}

View File

@@ -1,4 +1,10 @@
#!/bin/bash #!/bin/bash
image=${1:-'diginc/pihole:alpine'}
IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
docker run -p 53:53/tcp -p 53:53/udp -p 80:80 --cap-add=NET_ADMIN -e piholeIP="$IP" --name pihole -d dockerhole_alpine
# Default ports + daemonized docker container
docker run -p 53:53/tcp -p 53:53/udp -p 80:80 \
--cap-add=NET_ADMIN \
-e piholeIP="$IP" \
--name pihole \
-d $image

Submodule pi-hole updated: 396c7ab9ee...3853997295

View File

@@ -1 +1 @@
v2.5.3 v2.6.2