mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
More consistency
Odd mix of variables quoted with and without no-op parameter expansion (i.e. ${thing}) More ${thing} than not, make that the standard
This commit is contained in:
parent
aac8e45397
commit
ebbe1fc236
52
gravity.sh
52
gravity.sh
@ -113,11 +113,11 @@ 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.
|
||||||
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
|
||||||
@ -136,15 +136,15 @@ gravity_transport() {
|
|||||||
heisenbergCompensator=""
|
heisenbergCompensator=""
|
||||||
if [[ -r ${saveLocation} ]]; then
|
if [[ -r ${saveLocation} ]]; then
|
||||||
# if domain has been saved, add file for date check to only download newer
|
# if domain has been saved, add file for date check to only download newer
|
||||||
heisenbergCompensator="-z $saveLocation"
|
heisenbergCompensator="-z ${saveLocation}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Silently curl url
|
# 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
|
# 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
|
||||||
@ -154,7 +154,7 @@ gravity_spinup() {
|
|||||||
for ((i = 0; i < "${#sources[@]}"; i++)); do
|
for ((i = 0; i < "${#sources[@]}"; i++)); 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}
|
||||||
@ -162,11 +162,11 @@ gravity_spinup() {
|
|||||||
|
|
||||||
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/"
|
||||||
@ -179,7 +179,7 @@ gravity_spinup() {
|
|||||||
# 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,7 +190,7 @@ gravity_Schwarzchild() {
|
|||||||
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[@]}"; do
|
for i in "${activeDomains[@]}"; do
|
||||||
cat "$i" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
|
cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
|
||||||
done
|
done
|
||||||
echo " done!"
|
echo " done!"
|
||||||
}
|
}
|
||||||
@ -201,8 +201,8 @@ gravity_Blacklist() {
|
|||||||
${blacklistScript} -f -nr -q > /dev/null
|
${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!"
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity_Whitelist() {
|
gravity_Whitelist() {
|
||||||
@ -213,7 +213,7 @@ gravity_Whitelist() {
|
|||||||
|
|
||||||
urls=()
|
urls=()
|
||||||
for url in "${sources[@]}"; do
|
for url in "${sources[@]}"; 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!"
|
||||||
@ -221,8 +221,8 @@ gravity_Whitelist() {
|
|||||||
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 "${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!"
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity_unique() {
|
gravity_unique() {
|
||||||
@ -231,7 +231,7 @@ gravity_unique() {
|
|||||||
sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon}
|
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."
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity_hostFormat() {
|
gravity_hostFormat() {
|
||||||
@ -247,13 +247,13 @@ gravity_hostFormat() {
|
|||||||
# 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}
|
||||||
else
|
else
|
||||||
# Otherwise, just create gravity.list as normal using IPv4
|
# 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)
|
# 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}
|
echo -e "${IPv4addr} ${hostname}\n${IPv4addr} pi.hole" > ${piholeDir}/${accretionDisc}
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4addr}" '{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
|
||||||
@ -268,7 +268,7 @@ gravity_blackbody() {
|
|||||||
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
|
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
rm -f "$file"
|
rm -f "${file}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -286,7 +286,7 @@ gravity_advanced() {
|
|||||||
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
|
||||||
}
|
}
|
||||||
@ -306,8 +306,8 @@ gravity_reload() {
|
|||||||
#First escape forward slashes in the path:
|
#First escape forward slashes in the path:
|
||||||
adList=${adList//\//\\\/}
|
adList=${adList//\//\\\/}
|
||||||
#Now replace the line in dnsmasq file
|
#Now replace the line in dnsmasq file
|
||||||
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)
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ gravity_reload() {
|
|||||||
|
|
||||||
|
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
case "$var" in
|
case "${var}" in
|
||||||
"-f" | "--force" ) forceGrav=true;;
|
"-f" | "--force" ) forceGrav=true;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user