mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Imbue gravity.sh with some consistency
Mish-mash of tabs and spaces used for indentation. Mostly tabs though, so going with those. Also indenting blocks and enforcing the loop statement; do done style over the newline for do since it seemed to be more common.
This commit is contained in:
parent
5ebfa5ecf7
commit
aac8e45397
1 changed files with 64 additions and 69 deletions
133
gravity.sh
133
gravity.sh
|
@ -35,11 +35,11 @@ blacklistScript=/opt/pihole/blacklist.sh
|
||||||
#Source the setupVars from install script for the IP
|
#Source the setupVars from install script for the IP
|
||||||
setupVars=/etc/pihole/setupVars.conf
|
setupVars=/etc/pihole/setupVars.conf
|
||||||
if [[ -f ${setupVars} ]];then
|
if [[ -f ${setupVars} ]];then
|
||||||
. /etc/pihole/setupVars.conf
|
. /etc/pihole/setupVars.conf
|
||||||
else
|
else
|
||||||
echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure."
|
echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure."
|
||||||
echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure."
|
echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Remove the /* from the end of the IPv4addr.
|
#Remove the /* from the end of the IPv4addr.
|
||||||
|
@ -56,8 +56,8 @@ eventHorizon=${basename}.2.eventHorizon.txt
|
||||||
accretionDisc=${basename}.3.accretionDisc.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)
|
# 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."
|
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
@ -95,17 +95,17 @@ gravity_collapse() {
|
||||||
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
|
||||||
# Temporary hack to allow non-root access to pihole directory
|
# Temporary hack to allow non-root access to pihole directory
|
||||||
# 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
|
||||||
chmod 777 ${piholeDir}
|
chmod 777 ${piholeDir}
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo "::: Existing pihole directory found"
|
echo "::: Existing pihole directory found"
|
||||||
else
|
else
|
||||||
echo "::: Creating pihole directory..."
|
echo "::: Creating pihole directory..."
|
||||||
mkdir ${piholeDir}
|
mkdir ${piholeDir}
|
||||||
chmod 777 ${piholeDir}
|
chmod 777 ${piholeDir}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ gravity_collapse() {
|
||||||
gravity_patternCheck() {
|
gravity_patternCheck() {
|
||||||
patternBuffer=$1
|
patternBuffer=$1
|
||||||
# check if the patternbuffer is a non-zero length file
|
# 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
|
# 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.
|
||||||
|
@ -151,36 +151,35 @@ gravity_transport() {
|
||||||
gravity_spinup() {
|
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
|
url=${sources[$i]}
|
||||||
url=${sources[$i]}
|
# Get just the domain from the URL
|
||||||
# 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
|
# Save the file as list.#.domain
|
||||||
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
|
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
|
||||||
activeDomains[$i]=${saveLocation}
|
activeDomains[$i]=${saveLocation}
|
||||||
|
|
||||||
agent="Mozilla/10.0"
|
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
|
# 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 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
|
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/"
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +189,7 @@ gravity_Schwarzchild() {
|
||||||
# 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}
|
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!"
|
||||||
|
@ -214,10 +212,9 @@ gravity_Whitelist() {
|
||||||
echo -n "::: Adding ${#sources[@]} adlist 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!"
|
||||||
|
|
||||||
|
@ -248,7 +245,7 @@ gravity_hostFormat() {
|
||||||
echo "::: Error: Unable to determine fully qualified domain name of host"
|
echo "::: Error: Unable to determine fully qualified domain name of host"
|
||||||
fi
|
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 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)
|
# 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}
|
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}
|
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
||||||
|
@ -266,8 +263,7 @@ gravity_hostFormat() {
|
||||||
# blackbody - remove any remnant files from script processes
|
# blackbody - remove any remnant files from script processes
|
||||||
gravity_blackbody() {
|
gravity_blackbody() {
|
||||||
# Loop through list files
|
# Loop through list files
|
||||||
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
|
||||||
:
|
:
|
||||||
|
@ -313,32 +309,31 @@ 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;;
|
esac
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${forceGrav} == true ]]; then
|
if [[ ${forceGrav} == true ]]; then
|
||||||
|
|
Loading…
Reference in a new issue