mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-19 05:40:13 +00:00
Merge branch 'development' into webUIprivacymode
This commit is contained in:
commit
321ea8a3a9
16 changed files with 1179 additions and 972 deletions
|
@ -15,8 +15,6 @@
|
|||
piLog="/var/log/pihole.log"
|
||||
gravity="/etc/pihole/gravity.list"
|
||||
|
||||
today=$(date "+%b %e")
|
||||
|
||||
. /etc/pihole/setupVars.conf
|
||||
|
||||
CalcBlockedDomains() {
|
||||
|
@ -35,7 +33,7 @@ CalcBlockedDomains() {
|
|||
|
||||
CalcQueriesToday() {
|
||||
if [ -e "${piLog}" ]; then
|
||||
queriesToday=$(cat "${piLog}" | grep "${today}" | awk '/query/ {print $6}' | wc -l)
|
||||
queriesToday=$(awk '/query\[/ {print $6}' < "${piLog}" | wc -l)
|
||||
else
|
||||
queriesToday="Err."
|
||||
fi
|
||||
|
@ -43,7 +41,7 @@ CalcQueriesToday() {
|
|||
|
||||
CalcblockedToday() {
|
||||
if [ -e "${piLog}" ] && [ -e "${gravity}" ];then
|
||||
blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
blockedToday=$(awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' < "${piLog}" | wc -l)
|
||||
else
|
||||
blockedToday="Err."
|
||||
fi
|
||||
|
@ -104,7 +102,7 @@ normalChrono() {
|
|||
|
||||
echo "Blocking: ${blockedDomainsTotal}"
|
||||
echo "Queries: ${queriesToday}" #same total calculation as dashboard
|
||||
echo "Pi-holed: ${blockedToday} (${percentBlockedToday}%)"
|
||||
echo "Pi-holed: ${blockedToday} (${percentBlockedToday}%)"
|
||||
|
||||
sleep 5
|
||||
done
|
||||
|
|
100
advanced/Scripts/update.sh
Normal file → Executable file
100
advanced/Scripts/update.sh
Normal file → Executable file
|
@ -22,9 +22,15 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
|||
is_repo() {
|
||||
# Use git to check if directory is currently under VCS, return the value
|
||||
local directory="${1}"
|
||||
local curdir
|
||||
local rc
|
||||
|
||||
git -C "${directory}" status --short &> /dev/null
|
||||
return
|
||||
curdir="${PWD}"
|
||||
cd "${directory}" &> /dev/null || return 1
|
||||
git status --short &> /dev/null
|
||||
rc=$?
|
||||
cd "${curdir}" &> /dev/null || return 1
|
||||
return "${rc}"
|
||||
}
|
||||
|
||||
prep_repo() {
|
||||
|
@ -40,22 +46,24 @@ make_repo() {
|
|||
local remoteRepo="${2}"
|
||||
local directory="${1}"
|
||||
|
||||
(prep_repo "${directory}" && git clone -q --depth 1 "${remoteRepo}" "${directory}" > /dev/null)
|
||||
(prep_repo "${directory}" && git clone -q --depth 1 "${remoteRepo}" "${directory}")
|
||||
return
|
||||
}
|
||||
|
||||
update_repo() {
|
||||
local directory="${1}"
|
||||
local retVal=0
|
||||
# Pull the latest commits
|
||||
local curdir
|
||||
|
||||
curdir="${PWD}"
|
||||
cd "${directory}" &> /dev/null || return 1
|
||||
# Pull the latest commits
|
||||
# Stash all files not tracked for later retrieval
|
||||
git -C "${directory}" stash --all --quiet &> /dev/null || ${retVal}=1
|
||||
git stash --all --quiet
|
||||
# Force a clean working directory for cloning
|
||||
git -C "${directory}" clean --force -d &> /dev/null || ${retVal}=1
|
||||
git clean --force -d
|
||||
# Fetch latest changes and apply
|
||||
git -C "${directory}" pull --quiet &> /dev/null || ${retVal}=1
|
||||
return ${retVal}
|
||||
git pull --quiet
|
||||
cd "${curdir}" &> /dev/null || return 1
|
||||
}
|
||||
|
||||
getGitFiles() {
|
||||
|
@ -76,33 +84,59 @@ getGitFiles() {
|
|||
fi
|
||||
}
|
||||
|
||||
GitCheckUpdateAvail() {
|
||||
local directory="${1}"
|
||||
curdir=$PWD;
|
||||
cd "${directory}"
|
||||
|
||||
# Fetch latest changes in this repo
|
||||
git fetch --quiet origin
|
||||
status="$(git status -sb)"
|
||||
|
||||
# Change back to original directory
|
||||
cd "${curdir}"
|
||||
|
||||
if [[ $status == *"behind"* ]]; then
|
||||
# Local branch is behind remote branch -> Update
|
||||
return 0
|
||||
else
|
||||
# Local branch is up-to-date or in a situation
|
||||
# where this updater cannot be used (like on a
|
||||
# branch that exists only locally)
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local pihole_version_current
|
||||
local pihole_version_latest
|
||||
local web_version_current
|
||||
local web_version_latest
|
||||
|
||||
if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${ADMIN_INTERFACE_DIR}" ; then #This is unlikely
|
||||
#This is unlikely
|
||||
if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
|
||||
echo "::: Critical Error: One or more Pi-Hole repos are missing from system!"
|
||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "::: Checking for updates..."
|
||||
# Checks Pi-hole version string in format vX.X.X
|
||||
pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)"
|
||||
pihole_version_latest="$(/usr/local/bin/pihole version --pihole --latest)"
|
||||
web_version_current="$(/usr/local/bin/pihole version --admin --current)"
|
||||
web_version_latest="$(/usr/local/bin/pihole version --admin --latest)"
|
||||
|
||||
if [[ "${pihole_version_latest}" == "-1" || "${web_version_latest}" == "-1" ]]; then
|
||||
echo "*** Unable to contact GitHub for latest version. Please try again later, contact support if this continues."
|
||||
exit 1
|
||||
if GitCheckUpdateAvail "${PI_HOLE_FILES_DIR}" ; then
|
||||
core_update=true
|
||||
echo "::: Pi-hole Core: update available"
|
||||
else
|
||||
core_update=false
|
||||
echo "::: Pi-hole Core: up to date"
|
||||
fi
|
||||
|
||||
if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then
|
||||
web_update=true
|
||||
echo "::: Web Interface: update available"
|
||||
else
|
||||
web_update=false
|
||||
echo "::: Web Interface: up to date"
|
||||
fi
|
||||
|
||||
# Logic
|
||||
# If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!):
|
||||
# Update anyway
|
||||
# If Core up to date AND web up to date:
|
||||
# Do nothing
|
||||
# If Core up to date AND web NOT up to date:
|
||||
|
@ -112,46 +146,40 @@ main() {
|
|||
# if Core NOT up to date AND web NOT up to date:
|
||||
# pull pihole repo run install --unattended
|
||||
|
||||
if [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
|
||||
echo ":::"
|
||||
echo "::: Pi-hole version is $pihole_version_current"
|
||||
echo "::: Web Admin version is $web_version_current"
|
||||
if ! ${core_update} && ! ${web_update} ; then
|
||||
echo ":::"
|
||||
echo "::: Everything is up to date!"
|
||||
exit 0
|
||||
|
||||
elif [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" < "${web_version_latest}" ]]; then
|
||||
elif ! ${core_update} && ${web_update} ; then
|
||||
echo ":::"
|
||||
echo "::: Pi-hole Web Admin files out of date"
|
||||
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
||||
|
||||
web_updated=true
|
||||
|
||||
elif [[ "${pihole_version_current}" < "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
|
||||
elif ${core_update} && ! ${web_update} ; then
|
||||
echo ":::"
|
||||
echo "::: Pi-hole core files out of date"
|
||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
||||
core_updated=true
|
||||
|
||||
elif [[ "${pihole_version_current}" < "${pihole_version_latest}" ]] && [[ "${web_version_current}" < "${web_version_latest}" ]]; then
|
||||
elif ${core_update} && ${web_update} ; then
|
||||
echo ":::"
|
||||
echo "::: Updating Everything"
|
||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||
/etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
||||
web_updated=true
|
||||
core_updated=true
|
||||
else
|
||||
echo "*** Update script has malfunctioned, fallthrough reached. Please contact support"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${web_updated}" == true ]]; then
|
||||
if [[ "${web_update}" == true ]]; then
|
||||
web_version_current="$(/usr/local/bin/pihole version --admin --current)"
|
||||
echo ":::"
|
||||
echo "::: Web Admin version is now at ${web_version_current}"
|
||||
echo "::: If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
||||
fi
|
||||
|
||||
if [[ "${core_updated}" == true ]]; then
|
||||
if [[ "${core_update}" == true ]]; then
|
||||
pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)"
|
||||
echo ":::"
|
||||
echo "::: Pi-hole version is now at ${pihole_version_current}"
|
||||
|
|
|
@ -19,8 +19,9 @@ helpFunc() {
|
|||
:::
|
||||
::: Options:
|
||||
::: -p, password Set web interface password, an empty input will remove any previously set password
|
||||
::: -c, celsius Set Celcius temperature unit
|
||||
::: -c, celsius Set Celsius temperature unit
|
||||
::: -f, fahrenheit Set Fahrenheit temperature unit
|
||||
::: -k, kelvin Set Kelvin temperature unit
|
||||
::: -h, --help Show this help dialog
|
||||
EOM
|
||||
exit 0
|
||||
|
@ -31,11 +32,7 @@ SetTemperatureUnit(){
|
|||
# Remove setting from file (create backup setupVars.conf.bak)
|
||||
sed -i.bak '/TEMPERATUREUNIT/d' /etc/pihole/setupVars.conf
|
||||
# Save setting to file
|
||||
if [[ $unit == "F" ]] ; then
|
||||
echo "TEMPERATUREUNIT=F" >> /etc/pihole/setupVars.conf
|
||||
else
|
||||
echo "TEMPERATUREUNIT=C" >> /etc/pihole/setupVars.conf
|
||||
fi
|
||||
echo "TEMPERATUREUNIT=${unit}" >> /etc/pihole/setupVars.conf
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,6 +61,7 @@ SetWebPassword(){
|
|||
echo "WEBPASSWORD=${hash}" >> /etc/pihole/setupVars.conf
|
||||
echo "New password set"
|
||||
else
|
||||
echo "WEBPASSWORD=" >> /etc/pihole/setupVars.conf
|
||||
echo "Password removed"
|
||||
fi
|
||||
|
||||
|
@ -72,15 +70,21 @@ SetWebPassword(){
|
|||
SetDNSServers(){
|
||||
|
||||
# Remove setting from file (create backup setupVars.conf.bak)
|
||||
sed -i.bak '/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/DNS_FQDN_REQUIRED/d;' /etc/pihole/setupVars.conf
|
||||
sed -i.bak '/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/DNS_FQDN_REQUIRED/d;/DNS_BOGUS_PRIV/d;' /etc/pihole/setupVars.conf
|
||||
# Save setting to file
|
||||
echo "PIHOLE_DNS_1=${args[2]}" >> /etc/pihole/setupVars.conf
|
||||
echo "PIHOLE_DNS_2=${args[3]}" >> /etc/pihole/setupVars.conf
|
||||
if [[ "${args[3]}" != "none" ]]; then
|
||||
echo "PIHOLE_DNS_2=${args[3]}" >> /etc/pihole/setupVars.conf
|
||||
else
|
||||
echo "PIHOLE_DNS_2=" >> /etc/pihole/setupVars.conf
|
||||
fi
|
||||
|
||||
# Replace within actual dnsmasq config file
|
||||
sed -i '/server=/d;' /etc/dnsmasq.d/01-pihole.conf
|
||||
echo "server=${args[2]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||
echo "server=${args[3]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||
if [[ "${args[3]}" != "none" ]]; then
|
||||
echo "server=${args[3]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||
fi
|
||||
|
||||
# Remove domain-needed entry
|
||||
sed -i '/domain-needed/d;' /etc/dnsmasq.d/01-pihole.conf
|
||||
|
@ -222,13 +226,27 @@ SetPrivacyMode(){
|
|||
else
|
||||
echo "API_PRIVACY_MODE=false" >> /etc/pihole/setupVars.conf
|
||||
fi
|
||||
}
|
||||
|
||||
ResolutionSettings() {
|
||||
|
||||
typ=${args[2]}
|
||||
state=${args[3]}
|
||||
|
||||
if [[ "${typ}" == "forward" ]]; then
|
||||
sed -i.bak '/API_GET_UPSTREAM_DNS_HOSTNAME/d;' /etc/pihole/setupVars.conf
|
||||
echo "API_GET_UPSTREAM_DNS_HOSTNAME=${state}" >> /etc/pihole/setupVars.conf
|
||||
elif [[ "${typ}" == "clients" ]]; then
|
||||
sed -i.bak '/API_GET_CLIENT_HOSTNAME/d;' /etc/pihole/setupVars.conf
|
||||
echo "API_GET_CLIENT_HOSTNAME=${state}" >> /etc/pihole/setupVars.conf
|
||||
fi
|
||||
}
|
||||
|
||||
case "${args[1]}" in
|
||||
"-p" | "password" ) SetWebPassword;;
|
||||
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
|
||||
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
|
||||
"-k" | "kelvin" ) unit="K"; SetTemperatureUnit;;
|
||||
"setdns" ) SetDNSServers;;
|
||||
"setexcludedomains" ) SetExcludeDomains;;
|
||||
"setexcludeclients" ) SetExcludeClients;;
|
||||
|
@ -241,6 +259,7 @@ case "${args[1]}" in
|
|||
"-h" | "--help" ) helpFunc;;
|
||||
"domainname" ) SetDNSDomainName;;
|
||||
"privacymode" ) SetPrivacyMode;;
|
||||
"resolve" ) ResolutionSettings;;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue