mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-24 00:00:14 +00:00
remove absolute pathnames and store everything in setupvars
This commit is contained in:
parent
fc89851ce9
commit
d4aeef03c7
4 changed files with 196 additions and 196 deletions
|
@ -9,7 +9,6 @@
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 2 of the License, or
|
# the Free Software Foundation, either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
helpFunc()
|
helpFunc()
|
||||||
{
|
{
|
||||||
echo "::: Immediately blacklists one or more domains in the hosts file"
|
echo "::: Immediately blacklists one or more domains in the hosts file"
|
||||||
|
@ -23,42 +22,23 @@ helpFunc()
|
||||||
echo "::: -q, --quiet output is less verbose"
|
echo "::: -q, --quiet output is less verbose"
|
||||||
echo "::: -h, --help Show this help dialog"
|
echo "::: -h, --help Show this help dialog"
|
||||||
echo "::: -l, --list Display your blacklisted domains"
|
echo "::: -l, --list Display your blacklisted domains"
|
||||||
|
echo "::: -c:/path/to/file location of config file"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# = 0 ]]; then
|
|
||||||
helpFunc
|
|
||||||
fi
|
|
||||||
|
|
||||||
#globals
|
|
||||||
basename=pihole
|
|
||||||
piholeDir=/etc/${basename}
|
|
||||||
adList=${piholeDir}/gravity.list
|
|
||||||
blacklist=${piholeDir}/blacklist.txt
|
|
||||||
reload=true
|
|
||||||
addmode=true
|
|
||||||
force=false
|
|
||||||
verbose=true
|
|
||||||
|
|
||||||
domList=()
|
|
||||||
domToRemoveList=()
|
|
||||||
|
|
||||||
piholeIPfile=/etc/pihole/piholeIP
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
|
||||||
|
|
||||||
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}')
|
|
||||||
piholeIP=${piholeIPCIDR%/*}
|
|
||||||
fi
|
|
||||||
|
|
||||||
modifyHost=false
|
modifyHost=false
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
domList=("${domList[@]}" ${validDomain})
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# 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
|
||||||
echo "::: Local calibration requested..."
|
echo "::: Local calibration requested..."
|
||||||
|
@ -66,21 +46,6 @@ if [[ -r ${piholeDir}/pihole.conf ]];then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
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"
|
|
||||||
else
|
|
||||||
domList=("${domList[@]}" ${validDomain})
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
PopBlacklistFile(){
|
PopBlacklistFile(){
|
||||||
#check blacklist file exists, and if not, create it
|
#check blacklist file exists, and if not, create it
|
||||||
if [[ ! -f ${blacklist} ]];then
|
if [[ ! -f ${blacklist} ]];then
|
||||||
|
@ -138,15 +103,11 @@ ModifyHostFile(){
|
||||||
#add domains to the hosts file
|
#add domains to the hosts file
|
||||||
if [[ -r ${blacklist} ]];then
|
if [[ -r ${blacklist} ]];then
|
||||||
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||||
if [[ -n ${piholeIPv6} ]];then
|
sed "s/^/$piholeIP /g" ${blacklist} >> ${adList}
|
||||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
|
fi
|
||||||
else
|
|
||||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo ":::"
|
echo ":::"
|
||||||
for dom in "${domToRemoveList[@]}"
|
for dom in "${domToRemoveList[@]}"
|
||||||
|
@ -201,6 +162,15 @@ DisplayBlist() {
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
|
#globals
|
||||||
|
reload=true
|
||||||
|
addmode=true
|
||||||
|
force=false
|
||||||
|
verbose=true
|
||||||
|
|
||||||
|
domList=()
|
||||||
|
domToRemoveList=()
|
||||||
|
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
|
@ -208,12 +178,38 @@ do
|
||||||
"-d" | "--delmode" ) addmode=false;;
|
"-d" | "--delmode" ) addmode=false;;
|
||||||
"-f" | "--force" ) force=true;;
|
"-f" | "--force" ) force=true;;
|
||||||
"-q" | "--quiet" ) verbose=false;;
|
"-q" | "--quiet" ) verbose=false;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
"-l" | "--list" ) DisplayBlist;;
|
"-l" | "--list" ) DisplayBlist;;
|
||||||
|
-c* ) setupVars=$(echo $var | cut -d ":" -f2);;
|
||||||
* ) HandleOther "$var";;
|
* ) HandleOther "$var";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $# = 0 ]]; then
|
||||||
|
helpFunc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z ${setupVars} ]] ; then
|
||||||
|
setupVars=/etc/pihole/setupVars.conf
|
||||||
|
fi
|
||||||
|
if [[ -f ${setupVars} ]];then
|
||||||
|
. ${setupVars}
|
||||||
|
else
|
||||||
|
echo "::: WARNING: ${setupVars} missing. Possible installation failure."
|
||||||
|
echo "::: Please run 'pihole -r', and choose the 'install' option to reconfigure."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n ${IPv6_address} ]] ; then
|
||||||
|
piholeIP=${IPv6_address}
|
||||||
|
else
|
||||||
|
piholeIP=${IPv4_address}
|
||||||
|
piholeIP=$(echo "${piholeIP}" | cut -f1 -d"/")
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PopBlacklistFile
|
PopBlacklistFile
|
||||||
|
|
||||||
if ${modifyHost} || ${force}; then
|
if ${modifyHost} || ${force}; then
|
||||||
|
|
|
@ -10,6 +10,15 @@
|
||||||
# the Free Software Foundation, either version 2 of the License, or
|
# the Free Software Foundation, either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
domList=("${domList[@]}" ${validDomain})
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
helpFunc()
|
helpFunc()
|
||||||
{
|
{
|
||||||
|
@ -24,63 +33,18 @@ helpFunc()
|
||||||
echo "::: -q, --quiet output is less verbose"
|
echo "::: -q, --quiet output is less verbose"
|
||||||
echo "::: -h, --help Show this help dialog"
|
echo "::: -h, --help Show this help dialog"
|
||||||
echo "::: -l, --list Display your whitelisted domains"
|
echo "::: -l, --list Display your whitelisted domains"
|
||||||
|
echo "::: -c:/path/to/file location of config file"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# = 0 ]]; then
|
|
||||||
helpFunc
|
|
||||||
fi
|
|
||||||
|
|
||||||
#globals
|
|
||||||
basename=pihole
|
|
||||||
piholeDir=/etc/${basename}
|
|
||||||
adList=${piholeDir}/gravity.list
|
|
||||||
whitelist=${piholeDir}/whitelist.txt
|
|
||||||
reload=true
|
|
||||||
addmode=true
|
|
||||||
force=false
|
|
||||||
verbose=true
|
|
||||||
|
|
||||||
domList=()
|
|
||||||
domToRemoveList=()
|
|
||||||
|
|
||||||
piholeIPfile=/etc/pihole/piholeIP
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
|
||||||
|
|
||||||
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}')
|
|
||||||
piholeIP=${piholeIPCIDR%/*}
|
|
||||||
fi
|
|
||||||
|
|
||||||
modifyHost=false
|
modifyHost=false
|
||||||
|
|
||||||
# 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
|
||||||
echo "::: Local calibration requested..."
|
echo "::: Local calibration requested..."
|
||||||
. ${piholeDir}/pihole.conf
|
. ${piholeDir}/pihole.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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"
|
|
||||||
else
|
|
||||||
domList=("${domList[@]}" ${validDomain})
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
PopWhitelistFile(){
|
PopWhitelistFile(){
|
||||||
#check whitelist file exists, and if not, create it
|
#check whitelist file exists, and if not, create it
|
||||||
if [[ ! -f ${whitelist} ]];then
|
if [[ ! -f ${whitelist} ]];then
|
||||||
|
@ -141,44 +105,41 @@ ModifyHostFile(){
|
||||||
if ${addmode}; then
|
if ${addmode}; then
|
||||||
#remove domains in from hosts file
|
#remove domains in from hosts file
|
||||||
if [[ -r ${whitelist} ]];then
|
if [[ -r ${whitelist} ]];then
|
||||||
# Remove whitelist entries
|
# Remove whitelist entries
|
||||||
numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
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 "$piholeIP $line"; done > ${piholeDir}/whitelist.tmp
|
||||||
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
|
echo "l" >> ${piholeDir}/whitelist.tmp
|
||||||
echo "l" >> /etc/pihole/whitelist.tmp
|
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
|
||||||
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
|
rm ${adList}
|
||||||
rm ${adList}
|
mv ${piholeDir}/gravity.tmp ${adList}
|
||||||
mv ${piholeDir}/gravity.tmp ${adList}
|
rm ${piholeDir}/whitelist.tmp
|
||||||
rm ${piholeDir}/whitelist.tmp
|
|
||||||
echo " done!"
|
|
||||||
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#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}
|
|
||||||
echo " done!"
|
|
||||||
else
|
|
||||||
echo -n "::: Restoring block for $rdom on IPv4..."
|
|
||||||
echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
|
|
||||||
echo " done!"
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
#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" ${piholeDir}/*.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 " done!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo -n "::: Removing $rdom from $whitelist..."
|
echo -n "::: Removing $rdom from $whitelist..."
|
||||||
echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist}
|
echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist}
|
||||||
echo " done!"
|
echo " done!"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
Reload() {
|
Reload() {
|
||||||
|
@ -218,19 +179,51 @@ DisplayWlist() {
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
|
#globals
|
||||||
|
reload=true
|
||||||
|
addmode=true
|
||||||
|
force=false
|
||||||
|
verbose=true
|
||||||
|
|
||||||
|
domList=()
|
||||||
|
domToRemoveList=()
|
||||||
|
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
"-nr"| "--noreload" ) reload=false;;
|
"-nr"| "--noreload" ) reload=false;shift;;
|
||||||
"-d" | "--delmode" ) addmode=false;;
|
"-d" | "--delmode" ) addmode=false;shift;;
|
||||||
"-f" | "--force" ) force=true;;
|
"-f" | "--force" ) force=true;shift;;
|
||||||
"-q" | "--quiet" ) verbose=false;;
|
"-q" | "--quiet" ) verbose=false;shift;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;shift;;
|
||||||
"-l" | "--list" ) DisplayWlist;;
|
"-l" | "--list" ) DisplayWlist;shift;;
|
||||||
* ) HandleOther "$var";;
|
-c* ) setupVars=$(echo $var | cut -d ":" -f2);;
|
||||||
|
* ) HandleOther "${var}";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $# = 0 ]]; then
|
||||||
|
helpFunc
|
||||||
|
fi
|
||||||
|
if [[ -z ${setupVars} ]] ; then
|
||||||
|
setupVars=/etc/pihole/setupVars.conf
|
||||||
|
fi
|
||||||
|
if [[ -f ${setupVars} ]];then
|
||||||
|
. ${setupVars}
|
||||||
|
else
|
||||||
|
echo "::: WARNING: ${setupVars} missing. Possible installation failure."
|
||||||
|
echo "::: Please run 'pihole -r', and choose the 'install' option to reconfigure."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n ${IPv6_address} ]] ; then
|
||||||
|
piholeIP=${IPv6_address}
|
||||||
|
else
|
||||||
|
piholeIP=${IPv4_address}
|
||||||
|
piholeIP=$(echo "${piholeIP}" | cut -f1 -d"/")
|
||||||
|
fi
|
||||||
|
|
||||||
PopWhitelistFile
|
PopWhitelistFile
|
||||||
|
|
||||||
if ${modifyHost} || ${force}; then
|
if ${modifyHost} || ${force}; then
|
||||||
|
@ -245,4 +238,4 @@ fi
|
||||||
|
|
||||||
if ${reload}; then
|
if ${reload}; then
|
||||||
Reload
|
Reload
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -24,7 +24,7 @@ setupVars=/etc/pihole/setupVars.conf
|
||||||
|
|
||||||
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
|
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
|
||||||
webInterfaceDir="/var/www/html/admin"
|
webInterfaceDir="/var/www/html/admin"
|
||||||
piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
|
piholeGitUrl="https://github.com/tuplink/pi-hole.git"
|
||||||
piholeFilesDir="/etc/.pihole"
|
piholeFilesDir="/etc/.pihole"
|
||||||
|
|
||||||
useUpdateVars=false
|
useUpdateVars=false
|
||||||
|
@ -58,7 +58,7 @@ else
|
||||||
echo "::: Detecting the presence of the sudo utility for continuation of this install..."
|
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."
|
echo "::: Utility sudo located."
|
||||||
exec curl -sSL https://install.pi-hole.net | sudo bash "$@"
|
exec sudo bash "$0" "$@"
|
||||||
exit $?
|
exit $?
|
||||||
else
|
else
|
||||||
echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed."
|
echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed."
|
||||||
|
@ -796,6 +796,20 @@ finalExports() {
|
||||||
echo "IPv6_address=${IPv6_address}"
|
echo "IPv6_address=${IPv6_address}"
|
||||||
echo "piholeDNS1=${piholeDNS1}"
|
echo "piholeDNS1=${piholeDNS1}"
|
||||||
echo "piholeDNS2=${piholeDNS2}"
|
echo "piholeDNS2=${piholeDNS2}"
|
||||||
|
echo "basename=pihole"
|
||||||
|
echo "piholeDir=/etc/\${basename}"
|
||||||
|
echo "adList=\${piholeDir}/gravity.list"
|
||||||
|
echo "justDomainsExtension=domains"
|
||||||
|
echo "matterAndLight=\${basename}.0.matterandlight.txt"
|
||||||
|
echo "supernova=\${basename}.1.supernova.txt"
|
||||||
|
echo "eventHorizon=\${basename}.2.eventHorizon.txt"
|
||||||
|
echo "accretionDisc=\${basename}.3.accretionDisc.txt"
|
||||||
|
echo "blacklist=/etc/pihole/blacklist.txt"
|
||||||
|
echo "whitelist=/etc/pihole/whitelist.txt"
|
||||||
|
echo "adListFile=/etc/pihole/adlists.list"
|
||||||
|
echo "adListDefault=/etc/pihole/adlists.default"
|
||||||
|
echo "whitelistScript=/opt/pihole/whitelist.sh"
|
||||||
|
echo "blacklistScript=/opt/pihole/blacklist.sh"
|
||||||
}>> "${setupVars}"
|
}>> "${setupVars}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
99
gravity.sh
99
gravity.sh
|
@ -11,7 +11,6 @@
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
# Run this script as root or under sudo
|
# Run this script as root or under sudo
|
||||||
echo ":::"
|
|
||||||
|
|
||||||
helpFunc()
|
helpFunc()
|
||||||
{
|
{
|
||||||
|
@ -22,43 +21,11 @@ helpFunc()
|
||||||
echo "::: Options:"
|
echo "::: Options:"
|
||||||
echo "::: -f, --force Force lists to be downloaded, even if they don't need updating."
|
echo "::: -f, --force Force lists to be downloaded, even if they don't need updating."
|
||||||
echo "::: -h, --help Show this help dialog"
|
echo "::: -h, --help Show this help dialog"
|
||||||
|
echo "::: -c:/path/to/file location of config file"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
adListFile=/etc/pihole/adlists.list
|
|
||||||
adListDefault=/etc/pihole/adlists.default
|
|
||||||
whitelistScript=/opt/pihole/whitelist.sh
|
|
||||||
blacklistScript=/opt/pihole/blacklist.sh
|
|
||||||
|
|
||||||
#Source the setupVars from install script for the IP
|
|
||||||
setupVars=/etc/pihole/setupVars.conf
|
|
||||||
if [[ -f ${setupVars} ]];then
|
|
||||||
. /etc/pihole/setupVars.conf
|
|
||||||
else
|
|
||||||
echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure."
|
|
||||||
echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
#Remove the /* from the end of the IPv4addr.
|
|
||||||
IPv4addr=${IPv4_address%/*}
|
|
||||||
|
|
||||||
# Variables for various stages of downloading and formatting the list
|
|
||||||
basename=pihole
|
|
||||||
piholeDir=/etc/${basename}
|
|
||||||
adList=${piholeDir}/gravity.list
|
|
||||||
justDomainsExtension=domains
|
|
||||||
matterAndLight=${basename}.0.matterandlight.txt
|
|
||||||
supernova=${basename}.1.supernova.txt
|
|
||||||
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
|
|
||||||
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."
|
|
||||||
fi
|
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
# collapse - begin formation of pihole
|
# collapse - begin formation of pihole
|
||||||
gravity_collapse() {
|
gravity_collapse() {
|
||||||
|
@ -199,9 +166,9 @@ gravity_Schwarzchild() {
|
||||||
gravity_Blacklist(){
|
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
|
${blacklistScript} -f -nr -q -c:${setupVars}> /dev/null
|
||||||
|
|
||||||
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
|
numBlacklisted=$(wc -l < "${blacklist}")
|
||||||
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
||||||
echo " $numBlacklisted domain${plural} blacklisted!"
|
echo " $numBlacklisted domain${plural} blacklisted!"
|
||||||
}
|
}
|
||||||
|
@ -221,8 +188,8 @@ gravity_Whitelist() {
|
||||||
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
|
${whitelistScript} -f -nr -q -c:${setupVars} "${urls[@]}" > /dev/null
|
||||||
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
|
numWhitelisted=$(wc -l < "${whitelist}")
|
||||||
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
||||||
echo " $numWhitelisted domain${plural} whitelisted!"
|
echo " $numWhitelisted domain${plural} whitelisted!"
|
||||||
}
|
}
|
||||||
|
@ -304,7 +271,7 @@ gravity_reload() {
|
||||||
# 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!
|
#ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
|
||||||
#First escape forward slashes in the path:
|
#First escape forward slashes in the path:
|
||||||
adList=${adList//\//\\\/}
|
adList=${adList//\//\\\/}
|
||||||
|
@ -312,42 +279,72 @@ gravity_reload() {
|
||||||
sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
||||||
find "$piholeDir" -type f -exec chmod 666 {} \;
|
find "$piholeDir" -type f -exec chmod 666 {} \;
|
||||||
|
|
||||||
dnsmasqPid=$(pidof dnsmasq)
|
dnsmasqPid=$(pidof dnsmasq)
|
||||||
|
|
||||||
if [[ ${dnsmasqPid} ]]; then
|
if [[ ${dnsmasqPid} ]]; then
|
||||||
# service already running - reload config
|
# service already running - reload config
|
||||||
if [ -x "$(command -v systemctl)" ]; then
|
if [ -x "$(command -v systemctl)" ]; then
|
||||||
systemctl restart dnsmasq
|
systemctl restart dnsmasq
|
||||||
else
|
else
|
||||||
service dnsmasq restart
|
service dnsmasq restart
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# service not running, start it up
|
# service not running, start it up
|
||||||
if [ -x "$(command -v systemctl)" ]; then
|
if [ -x "$(command -v systemctl)" ]; then
|
||||||
systemctl start dnsmasq
|
systemctl start dnsmasq
|
||||||
else
|
else
|
||||||
service dnsmasq start
|
service dnsmasq start
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
"-f" | "--force" ) forceGrav=true;;
|
"-f" | "--force" ) forceGrav=true;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
|
-c* ) setupVars=$(echo $var | cut -d ":" -f2);;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo ":::"
|
||||||
|
|
||||||
|
#Source the setupVars from install script for the IP
|
||||||
|
if [[ -z ${setupVars} ]] ; then
|
||||||
|
setupVars=/etc/pihole/setupVars.conf
|
||||||
|
fi
|
||||||
|
if [[ -f ${setupVars} ]];then
|
||||||
|
. ${setupVars}
|
||||||
|
else
|
||||||
|
echo "::: WARNING: ${setupVars} missing. Possible installation failure."
|
||||||
|
echo "::: Please run 'pihole -r', and choose the 'install' option to reconfigure."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Remove the /* from the end of the IPv4addr.
|
||||||
|
IPv4addr=${IPv4_address%/*}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [[ ${forceGrav} == true ]]; then
|
if [[ ${forceGrav} == true ]]; then
|
||||||
echo -n "::: Deleting exising list cache..."
|
echo -n "::: Deleting exising list cache..."
|
||||||
rm /etc/pihole/list.*
|
for f in "${piholeDir}/list.*" ; do
|
||||||
|
# rm ${piholeDir}/list.${f}
|
||||||
|
echo "rm ${piholeDir}/list.${f}"
|
||||||
|
done
|
||||||
echo " done!"
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list
|
#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list
|
||||||
cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
|
cp /etc/.pihole/adlists.default ${piholeDir}/adlists.default
|
||||||
gravity_collapse
|
gravity_collapse
|
||||||
gravity_spinup
|
gravity_spinup
|
||||||
gravity_Schwarzchild
|
gravity_Schwarzchild
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue