mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-07-13 08:44:34 +02:00
Compare commits
No commits in common. "master" and "v6.0" have entirely different histories.
5
.github/CODEOWNERS
vendored
5
.github/CODEOWNERS
vendored
@ -1,5 +0,0 @@
|
||||
# see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-syntax
|
||||
|
||||
# These owners will be the default owners for everything in
|
||||
# the repo. Unless a later match takes precedence,
|
||||
* @pi-hole/core-maintainers
|
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@ -8,6 +8,8 @@ updates:
|
||||
time: "10:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: development
|
||||
reviewers:
|
||||
- "pi-hole/core-maintainers"
|
||||
- package-ecosystem: pip
|
||||
directory: "/test"
|
||||
schedule:
|
||||
@ -16,3 +18,5 @@ updates:
|
||||
time: "10:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: development
|
||||
reviewers:
|
||||
- "pi-hole/core-maintainers"
|
||||
|
1
.github/release.yml
vendored
1
.github/release.yml
vendored
@ -2,7 +2,6 @@ changelog:
|
||||
exclude:
|
||||
labels:
|
||||
- internal
|
||||
- dependencies
|
||||
authors:
|
||||
- dependabot
|
||||
- github-actions
|
||||
|
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@ -19,8 +19,6 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: 0 # Differential ShellCheck requires full git history
|
||||
|
||||
- name: Check scripts in repository are executable
|
||||
run: |
|
||||
@ -30,12 +28,12 @@ jobs:
|
||||
# If FAIL is 1 then we fail.
|
||||
[[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!"
|
||||
|
||||
- name: Differential ShellCheck
|
||||
uses: redhat-plumbers-in-action/differential-shellcheck@v5
|
||||
- name: Run shellcheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
with:
|
||||
severity: warning
|
||||
display-engine: sarif-fmt
|
||||
|
||||
check_together: 'yes'
|
||||
format: tty
|
||||
severity: error
|
||||
|
||||
- name: Spell-Checking
|
||||
uses: codespell-project/actions-codespell@master
|
||||
@ -69,10 +67,8 @@ jobs:
|
||||
ubuntu_22,
|
||||
ubuntu_24,
|
||||
centos_9,
|
||||
centos_10,
|
||||
fedora_40,
|
||||
fedora_41,
|
||||
fedora_42,
|
||||
]
|
||||
env:
|
||||
DISTRO: ${{matrix.distro}}
|
||||
@ -81,7 +77,7 @@ jobs:
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v5.6.0
|
||||
uses: actions/setup-python@v5.4.0
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,6 +10,3 @@ __pycache__
|
||||
.idea/
|
||||
*.iml
|
||||
.vscode/
|
||||
.venv/
|
||||
.fleet/
|
||||
.cache/
|
||||
|
@ -1,2 +0,0 @@
|
||||
external-sources=true # allow shellcheck to read external sources
|
||||
disable=SC3043 #disable SC3043: In POSIX sh, local is undefined.
|
13
README.md
13
README.md
@ -3,7 +3,11 @@
|
||||
#
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/pi-hole/graphics/refs/heads/master/Vortex/vortex_with_text.svg" alt="Pi-hole website" width="168" height="270">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_darkmode.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_lightmode.png">
|
||||
<img src="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_lightmode.png" width="168" height="270" alt="Pi-hole website">
|
||||
</picture>
|
||||
<br>
|
||||
<strong>Network-wide ad blocking via your own Linux hardware</strong>
|
||||
</p>
|
||||
@ -128,10 +132,7 @@ Some of the statistics you can integrate include:
|
||||
- Queries cached
|
||||
- Unique clients
|
||||
|
||||
Access the API using:
|
||||
- your browser: http://pi.hole/api/docs
|
||||
- `curl`: `curl --connect-timeout 2 -ks "https://pi.hole/api/stats/summary" -H "Accept: application/json"`;
|
||||
- the command line - examples: `pihole api config/webserver/port` or `pihole api stats/summary`.
|
||||
Access the API via [`telnet`](https://github.com/pi-hole/FTL), the Web (`admin/api.php`) and Command Line (`pihole -c -j`). You can find out [more details over here](https://discourse.pi-hole.net/t/pi-hole-api/1863).
|
||||
|
||||
### The Command-Line Interface
|
||||
|
||||
@ -139,7 +140,7 @@ The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the
|
||||
|
||||
Some notable features include:
|
||||
|
||||
- [Allowlisting, Denylisting (fka Whitelisting, Blacklisting), and Regex](https://docs.pi-hole.net/core/pihole-command/#allowlisting-denylisting-and-regex)
|
||||
- [Whitelisting, Blacklisting, and Regex](https://docs.pi-hole.net/core/pihole-command/#whitelisting-blacklisting-and-regex)
|
||||
- [Debugging utility](https://docs.pi-hole.net/core/pihole-command/#debugger)
|
||||
- [Viewing the live log file](https://docs.pi-hole.net/core/pihole-command/#tail)
|
||||
- [Updating Ad Lists](https://docs.pi-hole.net/core/pihole-command/#gravity)
|
||||
|
@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
# Determine if terminal is capable of showing colors
|
||||
if [ -t 1 ] && [ "$(tput colors)" -ge 8 ]; then
|
||||
if ([ -t 1 ] && [ $(tput colors) -ge 8 ]) || [ "${WEBCALL}" ]; then
|
||||
# Bold and underline may not show up on all clients
|
||||
# If something MUST be emphasized, use both
|
||||
COL_BOLD='[1m'
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC3043 #https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -19,19 +20,13 @@
|
||||
|
||||
TestAPIAvailability() {
|
||||
|
||||
local chaos_api_list authResponse authStatus authData apiAvailable DNSport
|
||||
|
||||
# as we are running locally, we can get the port value from FTL directly
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
. "${utilsfile}"
|
||||
|
||||
DNSport=$(getFTLConfigValue dns.port)
|
||||
local chaos_api_list availabilityResponse
|
||||
|
||||
# Query the API URLs from FTL using CHAOS TXT local.api.ftl
|
||||
# The result is a space-separated enumeration of full URLs
|
||||
# e.g., "http://localhost:80/api/" "https://localhost:443/api/"
|
||||
chaos_api_list="$(dig +short -p "${DNSport}" chaos txt local.api.ftl @127.0.0.1)"
|
||||
chaos_api_list="$(dig +short chaos txt local.api.ftl @127.0.0.1)"
|
||||
|
||||
# If the query was not successful, the variable is empty
|
||||
if [ -z "${chaos_api_list}" ]; then
|
||||
@ -39,12 +34,6 @@ TestAPIAvailability() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If an error occurred, the variable starts with ;;
|
||||
if [ "${chaos_api_list#;;}" != "${chaos_api_list}" ]; then
|
||||
echo "Communication error. Is FTL running?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Iterate over space-separated list of URLs
|
||||
while [ -n "${chaos_api_list}" ]; do
|
||||
# Get the first URL
|
||||
@ -53,34 +42,24 @@ TestAPIAvailability() {
|
||||
API_URL="${API_URL%\"}"
|
||||
API_URL="${API_URL#\"}"
|
||||
|
||||
# Test if the API is available at this URL, include delimiter for ease in splitting payload
|
||||
authResponse=$(curl --connect-timeout 2 -skS -w ">>%{http_code}" "${API_URL}auth")
|
||||
|
||||
# authStatus is the response http_code, eg. 200, 401.
|
||||
# Shell parameter expansion, remove everything up to and including the >> delim
|
||||
authStatus=${authResponse#*>>}
|
||||
# data is everything from response
|
||||
# Shell parameter expansion, remove the >> delim and everything after
|
||||
authData=${authResponse%>>*}
|
||||
# Test if the API is available at this URL
|
||||
availabilityResponse=$(curl -skS -o /dev/null -w "%{http_code}" "${API_URL}auth")
|
||||
|
||||
# Test if http status code was 200 (OK) or 401 (authentication required)
|
||||
if [ "${authStatus}" = 200 ]; then
|
||||
# API is available without authentication
|
||||
apiAvailable=true
|
||||
needAuth=false
|
||||
break
|
||||
|
||||
elif [ "${authStatus}" = 401 ]; then
|
||||
# API is available with authentication
|
||||
apiAvailable=true
|
||||
needAuth=true
|
||||
# Check if 2FA is required
|
||||
needTOTP=$(echo "${authData}"| jq --raw-output .session.totp 2>/dev/null)
|
||||
break
|
||||
|
||||
else
|
||||
if [ ! "${availabilityResponse}" = 200 ] && [ ! "${availabilityResponse}" = 401 ]; then
|
||||
# API is not available at this port/protocol combination
|
||||
apiAvailable=false
|
||||
API_PORT=""
|
||||
else
|
||||
# API is available at this URL combination
|
||||
|
||||
if [ "${availabilityResponse}" = 200 ]; then
|
||||
# API is available without authentication
|
||||
needAuth=false
|
||||
fi
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
# Remove the first URL from the list
|
||||
local last_api_list
|
||||
last_api_list="${chaos_api_list}"
|
||||
@ -91,12 +70,11 @@ TestAPIAvailability() {
|
||||
# Remove the last element
|
||||
chaos_api_list=""
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# if apiAvailable is false, no working API was found
|
||||
if [ "${apiAvailable}" = false ]; then
|
||||
echo "API not available. Please check FTL.log"
|
||||
# if API_PORT is empty, no working API port was found
|
||||
if [ -n "${API_PORT}" ]; then
|
||||
echo "API not available at: ${API_URL}"
|
||||
echo "Exiting."
|
||||
exit 1
|
||||
fi
|
||||
@ -124,51 +102,22 @@ LoginAPI() {
|
||||
echo "API Authentication: Trying to use CLI password"
|
||||
fi
|
||||
|
||||
# If we can read the CLI password, we can skip 2FA even when it's required otherwise
|
||||
needTOTP=false
|
||||
# Try to authenticate using the CLI password
|
||||
Authentication "${1}"
|
||||
|
||||
elif [ "${1}" = "verbose" ]; then
|
||||
echo "API Authentication: CLI password not available"
|
||||
fi
|
||||
|
||||
if [ -z "${password}" ]; then
|
||||
# no password read from CLI file
|
||||
echo "Please enter your password:"
|
||||
# secretly read the password
|
||||
secretRead; printf '\n'
|
||||
fi
|
||||
|
||||
if [ "${needTOTP}" = true ]; then
|
||||
# 2FA required
|
||||
echo "Please enter the correct second factor."
|
||||
echo "(Can be any number if you used the app password)"
|
||||
read -r totp
|
||||
fi
|
||||
|
||||
# Try to authenticate using the supplied password (CLI file or user input) and TOTP
|
||||
Authentication "${1}"
|
||||
|
||||
# Try to login again until the session is valid
|
||||
while [ ! "${validSession}" = true ] ; do
|
||||
# If this did not work, ask the user for the password
|
||||
while [ "${validSession}" = false ] || [ -z "${validSession}" ] ; do
|
||||
echo "Authentication failed. Please enter your Pi-hole password"
|
||||
|
||||
# Print the error message if there is one
|
||||
if [ ! "${sessionError}" = "null" ] && [ "${1}" = "verbose" ]; then
|
||||
echo "Error: ${sessionError}"
|
||||
fi
|
||||
# Print the session message if there is one
|
||||
if [ ! "${sessionMessage}" = "null" ] && [ "${1}" = "verbose" ]; then
|
||||
echo "Error: ${sessionMessage}"
|
||||
fi
|
||||
|
||||
# secretly read the password
|
||||
secretRead; printf '\n'
|
||||
|
||||
if [ "${needTOTP}" = true ]; then
|
||||
echo "Please enter the correct second factor:"
|
||||
echo "(Can be any number if you used the app password)"
|
||||
read -r totp
|
||||
fi
|
||||
|
||||
# Try to authenticate again
|
||||
Authentication "${1}"
|
||||
done
|
||||
@ -176,19 +125,15 @@ LoginAPI() {
|
||||
}
|
||||
|
||||
Authentication() {
|
||||
sessionResponse="$(curl --connect-timeout 2 -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli" --data "{\"password\":\"${password}\", \"totp\":${totp:-null}}" )"
|
||||
sessionResponse="$(curl -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli " --data "{\"password\":\"${password}\"}" )"
|
||||
|
||||
if [ -z "${sessionResponse}" ]; then
|
||||
echo "No response from FTL server. Please check connectivity"
|
||||
exit 1
|
||||
fi
|
||||
# obtain validity, session ID and sessionMessage from session response
|
||||
# obtain validity and session ID from session response
|
||||
validSession=$(echo "${sessionResponse}"| jq .session.valid 2>/dev/null)
|
||||
SID=$(echo "${sessionResponse}"| jq --raw-output .session.sid 2>/dev/null)
|
||||
sessionMessage=$(echo "${sessionResponse}"| jq --raw-output .session.message 2>/dev/null)
|
||||
|
||||
# obtain the error message from the session response
|
||||
sessionError=$(echo "${sessionResponse}"| jq --raw-output .error.message 2>/dev/null)
|
||||
|
||||
if [ "${1}" = "verbose" ]; then
|
||||
if [ "${validSession}" = true ]; then
|
||||
@ -234,7 +179,7 @@ GetFTLData() {
|
||||
# return only the data
|
||||
if [ "${status}" = 200 ]; then
|
||||
# response OK
|
||||
printf %s "${data}"
|
||||
echo "${data}"
|
||||
else
|
||||
# connection lost
|
||||
echo "${status}"
|
||||
@ -308,23 +253,14 @@ secretRead() {
|
||||
}
|
||||
|
||||
apiFunc() {
|
||||
local data response status status_col verbosity
|
||||
|
||||
# Define if the output will be silent (default) or verbose
|
||||
verbosity="silent"
|
||||
if [ "$1" = "verbose" ]; then
|
||||
verbosity="verbose"
|
||||
shift
|
||||
fi
|
||||
local data response status status_col
|
||||
|
||||
# Authenticate with the API
|
||||
LoginAPI "${verbosity}"
|
||||
|
||||
if [ "${verbosity}" = "verbose" ]; then
|
||||
LoginAPI verbose
|
||||
echo ""
|
||||
|
||||
echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Get the data from the API
|
||||
response=$(GetFTLData "$1" raw)
|
||||
@ -341,18 +277,11 @@ apiFunc() {
|
||||
else
|
||||
status_col="${COL_RED}"
|
||||
fi
|
||||
|
||||
# Only print the status in verbose mode or if the status is not 200
|
||||
if [ "${verbosity}" = "verbose" ] || [ "${status}" != 200 ]; then
|
||||
echo "Status: ${status_col}${status}${COL_NC}"
|
||||
fi
|
||||
|
||||
# Output the data. Format it with jq if available and data is actually JSON.
|
||||
# Otherwise just print it
|
||||
if [ "${verbosity}" = "verbose" ]; then
|
||||
echo "Data:"
|
||||
fi
|
||||
|
||||
if command -v jq >/dev/null && echo "${data}" | jq . >/dev/null 2>&1; then
|
||||
echo "${data}" | jq .
|
||||
else
|
||||
@ -360,5 +289,5 @@ apiFunc() {
|
||||
fi
|
||||
|
||||
# Delete the session
|
||||
LogoutAPI "${verbosity}"
|
||||
LogoutAPI verbose
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -13,8 +13,9 @@
|
||||
readonly scriptPath="/etc/.pihole/advanced/Scripts/database_migration/gravity"
|
||||
|
||||
upgrade_gravityDB(){
|
||||
local database version
|
||||
local database piholeDir version
|
||||
database="${1}"
|
||||
piholeDir="${2}"
|
||||
|
||||
# Exit early if the database does not exist (e.g. in CI tests)
|
||||
if [[ ! -f "${database}" ]]; then
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -11,11 +12,9 @@
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
readonly apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
# shellcheck source="./advanced/Scripts/api.sh"
|
||||
source "${apifile}"
|
||||
|
||||
# Determine database location
|
||||
@ -40,7 +39,6 @@ typeId=""
|
||||
comment=""
|
||||
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${colfile}
|
||||
|
||||
helpFunc() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -11,13 +12,11 @@
|
||||
|
||||
coltable="/opt/pihole/COL_TABLE"
|
||||
if [[ -f ${coltable} ]]; then
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${coltable}
|
||||
fi
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
source "${utilsfile}"
|
||||
|
||||
# Determine database location
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
SKIP_INSTALL="true"
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
|
||||
# webInterfaceGitUrl set in basic-install.sh
|
||||
@ -110,7 +109,7 @@ checkout() {
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
mapfile -t corebranches < <(get_available_branches "${PI_HOLE_FILES_DIR}")
|
||||
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
||||
|
||||
if [[ "${corebranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str"
|
||||
@ -137,7 +136,7 @@ checkout() {
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
mapfile -t webbranches < <(get_available_branches "${webInterfaceDir}")
|
||||
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
||||
|
||||
if [[ "${webbranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str"
|
||||
@ -168,7 +167,7 @@ checkout() {
|
||||
|
||||
# Check if requested branch is available
|
||||
echo -e " ${INFO} Checking for availability of branch ${COL_CYAN}${2}${COL_NC} on GitHub"
|
||||
mapfile -t ftlbranches < <(git ls-remote https://github.com/pi-hole/ftl | grep "refs/heads" | cut -d'/' -f3- -)
|
||||
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep "refs/heads" | cut -d'/' -f3- -) )
|
||||
# If returned array is empty -> connectivity issue
|
||||
if [[ ${#ftlbranches[@]} -eq 0 ]]; then
|
||||
echo -e " ${CROSS} Unable to fetch branches from GitHub. Please check your Internet connection and try again later."
|
||||
@ -210,15 +209,13 @@ checkout() {
|
||||
# Update local and remote versions via updatechecker
|
||||
/opt/pihole/updatecheck.sh
|
||||
else
|
||||
local status
|
||||
status=$?
|
||||
if [ $status -eq 1 ]; then
|
||||
if [ $? -eq 1 ]; then
|
||||
# Binary for requested branch is not available, may still be
|
||||
# int he process of being built or CI build job failed
|
||||
printf " %b Binary for requested branch is not available, please try again later.\\n" "${CROSS}"
|
||||
printf " %b Binary for requested branch is not available, please try again later.\\n" ${CROSS}
|
||||
printf " If the issue persists, please contact Pi-hole Support and ask them to re-generate the binary.\\n"
|
||||
exit 1
|
||||
elif [ $status -eq 2 ]; then
|
||||
elif [ $? -eq 2 ]; then
|
||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||
exit 1
|
||||
else
|
||||
|
@ -8,6 +8,7 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
|
||||
# -u a reference to any variable you haven't previously defined
|
||||
@ -26,7 +27,6 @@ PIHOLE_COLTABLE_FILE="${PIHOLE_SCRIPTS_DIRECTORY}/COL_TABLE"
|
||||
|
||||
# These provide the colors we need for making the log more readable
|
||||
if [[ -f ${PIHOLE_COLTABLE_FILE} ]]; then
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
source ${PIHOLE_COLTABLE_FILE}
|
||||
else
|
||||
COL_NC='\e[0m' # No Color
|
||||
@ -41,7 +41,7 @@ else
|
||||
#OVER="\r\033[K"
|
||||
fi
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/pihole/versions
|
||||
|
||||
# Read the value of an FTL config key. The value is printed to stdout.
|
||||
@ -213,7 +213,7 @@ compare_local_version_to_git_version() {
|
||||
local local_status
|
||||
local_status=$(git status -s)
|
||||
# echo this information out to the user in a nice format
|
||||
if [ "${local_version}" ]; then
|
||||
if [ ${local_version} ]; then
|
||||
log_write "${TICK} Version: ${local_version}"
|
||||
elif [ -n "${DOCKER_VERSION}" ]; then
|
||||
log_write "${TICK} Version: Pi-hole Docker Container ${COL_BOLD}${DOCKER_VERSION}${COL_NC}"
|
||||
@ -296,12 +296,91 @@ check_component_versions() {
|
||||
check_ftl_version
|
||||
}
|
||||
|
||||
os_check() {
|
||||
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
|
||||
# and determines whether or not the script is running on one of those systems
|
||||
local remote_os_domain valid_os valid_version detected_os detected_version cmdResult digReturnCode response
|
||||
remote_os_domain=${OS_CHECK_DOMAIN_NAME:-"versions.pi-hole.net"}
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
cmdResult="$(dig -4 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
# Extract dig response
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
|
||||
if [ "${digReturnCode}" -ne 0 ]; then
|
||||
log_write "${INFO} Distro: ${detected_os^}"
|
||||
log_write "${INFO} Version: ${detected_version}"
|
||||
log_write "${CROSS} dig IPv4 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||
log_write "${CROSS} dig response: ${response}"
|
||||
log_write "${INFO} Retrying via IPv6"
|
||||
|
||||
cmdResult="$(dig -6 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
# Extract dig response
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
fi
|
||||
# If also no success via IPv6
|
||||
if [ "${digReturnCode}" -ne 0 ]; then
|
||||
log_write "${CROSS} dig IPv6 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||
log_write "${CROSS} dig response: ${response}"
|
||||
log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}"
|
||||
else
|
||||
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
||||
for distro_and_versions in "${supportedOS[@]}"
|
||||
do
|
||||
distro_part="${distro_and_versions%%=*}"
|
||||
versions_part="${distro_and_versions##*=}"
|
||||
|
||||
if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then
|
||||
valid_os=true
|
||||
IFS="," read -r -a supportedVer <<<"${versions_part}"
|
||||
for version in "${supportedVer[@]}"
|
||||
do
|
||||
if [[ "${detected_version}" =~ $version ]]; then
|
||||
valid_version=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# If it is a docker container, we can assume the OS is supported
|
||||
[ -n "${DOCKER_VERSION}" ] && valid_os=true && valid_version=true
|
||||
|
||||
local finalmsg
|
||||
if [ "$valid_os" = true ]; then
|
||||
log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}"
|
||||
|
||||
if [ "$valid_version" = true ]; then
|
||||
log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}"
|
||||
finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}"
|
||||
else
|
||||
log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}"
|
||||
finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}"
|
||||
fi
|
||||
else
|
||||
log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}"
|
||||
finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}"
|
||||
fi
|
||||
|
||||
# Print dig response and the final check result
|
||||
log_write "${TICK} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}"
|
||||
log_write "${INFO} dig response: ${response}"
|
||||
log_write "${finalmsg}"
|
||||
fi
|
||||
}
|
||||
|
||||
diagnose_operating_system() {
|
||||
# error message in a variable so we can easily modify it later (or reuse it)
|
||||
local error_msg="Distribution unknown -- most likely you are on an unsupported platform and may run into issues."
|
||||
local detected_os
|
||||
local detected_version
|
||||
|
||||
# Display the current test that is running
|
||||
echo_current_diagnostic "Operating system"
|
||||
|
||||
@ -310,13 +389,8 @@ diagnose_operating_system() {
|
||||
|
||||
# If there is a /etc/*release file, it's probably a supported operating system, so we can
|
||||
if ls /etc/*release 1> /dev/null 2>&1; then
|
||||
# display the attributes to the user
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
log_write "${INFO} Distro: ${detected_os^}"
|
||||
log_write "${INFO} Version: ${detected_version}"
|
||||
# display the attributes to the user from the function made earlier
|
||||
os_check
|
||||
else
|
||||
# If it doesn't exist, it's not a system we currently support and link to FAQ
|
||||
log_write "${CROSS} ${COL_RED}${error_msg}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS})"
|
||||
@ -414,9 +488,7 @@ run_and_print_command() {
|
||||
local output
|
||||
output=$(${cmd} 2>&1)
|
||||
# If the command was successful,
|
||||
local return_code
|
||||
return_code=$?
|
||||
if [[ "${return_code}" -eq 0 ]]; then
|
||||
if [[ $? -eq 0 ]]; then
|
||||
# show the output
|
||||
log_write "${output}"
|
||||
else
|
||||
@ -861,6 +933,7 @@ parse_file() {
|
||||
# Get the lines that are in the file(s) and store them in an array for parsing later
|
||||
local file_info
|
||||
if [[ -f "$filename" ]]; then
|
||||
#shellcheck disable=SC2016
|
||||
IFS=$'\r\n' command eval 'file_info=( $(cat "${filename}") )'
|
||||
else
|
||||
read -r -a file_info <<< "$filename"
|
||||
|
@ -9,12 +9,10 @@
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${colfile}
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
# In case we're running at the same time as a system logrotate, use a
|
||||
@ -37,46 +35,6 @@ FTLFILE=$(getFTLConfigValue "files.log.ftl")
|
||||
if [ -z "$FTLFILE" ]; then
|
||||
FTLFILE="/var/log/pihole/FTL.log"
|
||||
fi
|
||||
WEBFILE=$(getFTLConfigValue "files.log.webserver")
|
||||
if [ -z "$WEBFILE" ]; then
|
||||
WEBFILE="/var/log/pihole/webserver.log"
|
||||
fi
|
||||
|
||||
# Helper function to handle log rotation for a single file
|
||||
rotate_log() {
|
||||
# This function copies x.log over to x.log.1
|
||||
# and then empties x.log
|
||||
# Note that moving the file is not an option, as
|
||||
# dnsmasq would happily continue writing into the
|
||||
# moved file (it will have the same file handler)
|
||||
local logfile="$1"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${logfile} ..."
|
||||
fi
|
||||
cp -p "${logfile}" "${logfile}.1"
|
||||
echo " " > "${logfile}"
|
||||
chmod 640 "${logfile}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${logfile} ..."
|
||||
fi
|
||||
}
|
||||
|
||||
# Helper function to handle log flushing for a single file
|
||||
flush_log() {
|
||||
local logfile="$1"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${logfile} ..."
|
||||
fi
|
||||
echo " " > "${logfile}"
|
||||
chmod 640 "${logfile}"
|
||||
if [ -f "${logfile}.1" ]; then
|
||||
echo " " > "${logfile}.1"
|
||||
chmod 640 "${logfile}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${logfile} ..."
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$*" == *"once"* ]]; then
|
||||
# Nightly logrotation
|
||||
@ -88,16 +46,62 @@ if [[ "$*" == *"once"* ]]; then
|
||||
fi
|
||||
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate
|
||||
else
|
||||
# Handle rotation for each log file
|
||||
rotate_log "${LOGFILE}"
|
||||
rotate_log "${FTLFILE}"
|
||||
rotate_log "${WEBFILE}"
|
||||
# Copy pihole.log over to pihole.log.1
|
||||
# and empty out pihole.log
|
||||
# Note that moving the file is not an option, as
|
||||
# dnsmasq would happily continue writing into the
|
||||
# moved file (it will have the same file handler)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${LOGFILE} ..."
|
||||
fi
|
||||
cp -p "${LOGFILE}" "${LOGFILE}.1"
|
||||
echo " " > "${LOGFILE}"
|
||||
chmod 640 "${LOGFILE}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${LOGFILE} ..."
|
||||
fi
|
||||
# Copy FTL.log over to FTL.log.1
|
||||
# and empty out FTL.log
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${FTLFILE} ..."
|
||||
fi
|
||||
cp -p "${FTLFILE}" "${FTLFILE}.1"
|
||||
echo " " > "${FTLFILE}"
|
||||
chmod 640 "${FTLFILE}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${FTLFILE} ..."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Manual flushing
|
||||
flush_log "${LOGFILE}"
|
||||
flush_log "${FTLFILE}"
|
||||
flush_log "${WEBFILE}"
|
||||
|
||||
# Flush both pihole.log and pihole.log.1 (if existing)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${LOGFILE} ..."
|
||||
fi
|
||||
echo " " > "${LOGFILE}"
|
||||
chmod 640 "${LOGFILE}"
|
||||
if [ -f "${LOGFILE}.1" ]; then
|
||||
echo " " > "${LOGFILE}.1"
|
||||
chmod 640 "${LOGFILE}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${LOGFILE} ..."
|
||||
fi
|
||||
|
||||
# Flush both FTL.log and FTL.log.1 (if existing)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${FTLFILE} ..."
|
||||
fi
|
||||
echo " " > "${FTLFILE}"
|
||||
chmod 640 "${FTLFILE}"
|
||||
if [ -f "${FTLFILE}.1" ]; then
|
||||
echo " " > "${FTLFILE}.1"
|
||||
chmod 640 "${FTLFILE}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${FTLFILE} ..."
|
||||
fi
|
||||
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing database, DNS resolution temporarily unavailable ..."
|
||||
|
@ -1,4 +1,9 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Ignore warning about `local` being undefinded in POSIX
|
||||
# shellcheck disable=SC3043
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2023 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -17,11 +22,9 @@ domain=""
|
||||
|
||||
# Source color table
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
. "${colfile}"
|
||||
|
||||
# Source api functions
|
||||
# shellcheck source="./advanced/Scripts/api.sh"
|
||||
. "${PI_HOLE_INSTALL_DIR}/api.sh"
|
||||
|
||||
Help() {
|
||||
|
@ -12,31 +12,26 @@
|
||||
|
||||
# Variables
|
||||
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/web.git"
|
||||
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
||||
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
SKIP_INSTALL=true
|
||||
|
||||
# when --check-only is passed to this script, it will not perform the actual update
|
||||
CHECK_ONLY=false
|
||||
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
# shellcheck disable=SC1091
|
||||
source "/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${PI_HOLE_INSTALL_DIR}/utils.sh"
|
||||
|
||||
# is_repo() sourced from basic-install.sh
|
||||
# make_repo() sourced from basic-install.sh
|
||||
# update_repo() source from basic-install.sh
|
||||
# getGitFiles() sourced from basic-install.sh
|
||||
# FTLcheckUpdate() sourced from basic-install.sh
|
||||
# getFTLConfigValue() sourced from utils.sh
|
||||
|
||||
# Honour configured paths for the web application.
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
GitCheckUpdateAvail() {
|
||||
local directory
|
||||
@ -112,6 +107,8 @@ main() {
|
||||
web_update=false
|
||||
FTL_update=false
|
||||
|
||||
# Perform an OS check to ensure we're on an appropriate operating system
|
||||
os_check
|
||||
|
||||
# Install packages used by this installation script (necessary if users have removed e.g. git from their systems)
|
||||
package_manager_detect
|
||||
@ -212,7 +209,7 @@ main() {
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole Web Admin files out of date, updating local repo."
|
||||
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
||||
echo -e " ${INFO} If you had made any changes in '${ADMIN_INTERFACE_DIR}', they have been stashed using 'git stash'"
|
||||
echo -e " ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
||||
fi
|
||||
|
||||
if [[ "${FTL_update}" == true ]]; then
|
||||
@ -221,7 +218,7 @@ main() {
|
||||
fi
|
||||
|
||||
if [[ "${FTL_update}" == true || "${core_update}" == true ]]; then
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --repair --unattended || \
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
|
||||
echo -e "${basicError}" && exit 1
|
||||
fi
|
||||
|
||||
|
@ -39,12 +39,9 @@ function get_remote_hash() {
|
||||
}
|
||||
|
||||
# Source the utils file for addOrEditKeyValPair()
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
# shellcheck disable=SC1091
|
||||
. /opt/pihole/utils.sh
|
||||
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
# Remove the below three legacy files if they exist
|
||||
rm -f "/etc/pihole/GitHubVersions"
|
||||
rm -f "/etc/pihole/localbranches"
|
||||
@ -88,13 +85,13 @@ addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}"
|
||||
|
||||
# get Web versions
|
||||
|
||||
WEB_VERSION="$(get_local_version "${ADMIN_INTERFACE_DIR}")"
|
||||
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
|
||||
|
||||
WEB_BRANCH="$(get_local_branch "${ADMIN_INTERFACE_DIR}")"
|
||||
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
|
||||
|
||||
WEB_HASH="$(get_local_hash "${ADMIN_INTERFACE_DIR}")"
|
||||
WEB_HASH="$(get_local_hash /var/www/html/admin)"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}"
|
||||
|
||||
GITHUB_WEB_VERSION="$(get_remote_version web "${WEB_BRANCH}")"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC3043 #https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -87,8 +88,8 @@ getFTLConfigValue(){
|
||||
#######################
|
||||
setFTLConfigValue(){
|
||||
pihole-FTL --config "${1}" "${2}" >/dev/null
|
||||
if [ $? -eq 5 ]; then
|
||||
printf " %s %s set by environment variable. Please unset it to use this function\n" "${CROSS}" "${1}"
|
||||
if [[ $? -eq 5 ]]; then
|
||||
echo -e " ${CROSS} ${1} set by environment variable. Please unset it to use this function"
|
||||
exit 5
|
||||
fi
|
||||
}
|
||||
|
@ -8,16 +8,20 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# Source the versions file populated by updatechecker.sh
|
||||
# Ignore warning about `local` being undefinded in POSIX
|
||||
# shellcheck disable=SC3043
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Source the versions file poupulated by updatechecker.sh
|
||||
cachedVersions="/etc/pihole/versions"
|
||||
|
||||
if [ -f ${cachedVersions} ]; then
|
||||
# shellcheck source=/dev/null
|
||||
# shellcheck disable=SC1090
|
||||
. "$cachedVersions"
|
||||
else
|
||||
echo "Could not find /etc/pihole/versions. Running update now."
|
||||
pihole updatechecker
|
||||
# shellcheck source=/dev/null
|
||||
# shellcheck disable=SC1090
|
||||
. "$cachedVersions"
|
||||
fi
|
||||
|
||||
|
@ -43,8 +43,8 @@ CREATE TABLE adlist
|
||||
|
||||
CREATE TABLE adlist_by_group
|
||||
(
|
||||
adlist_id INTEGER NOT NULL REFERENCES adlist (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
adlist_id INTEGER NOT NULL REFERENCES adlist (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
PRIMARY KEY (adlist_id, group_id)
|
||||
);
|
||||
|
||||
@ -75,8 +75,8 @@ INSERT INTO "info" VALUES('gravity_restored','false');
|
||||
|
||||
CREATE TABLE domainlist_by_group
|
||||
(
|
||||
domainlist_id INTEGER NOT NULL REFERENCES domainlist (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
domainlist_id INTEGER NOT NULL REFERENCES domainlist (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
PRIMARY KEY (domainlist_id, group_id)
|
||||
);
|
||||
|
||||
@ -91,8 +91,8 @@ CREATE TABLE client
|
||||
|
||||
CREATE TABLE client_by_group
|
||||
(
|
||||
client_id INTEGER NOT NULL REFERENCES client (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
client_id INTEGER NOT NULL REFERENCES client (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
PRIMARY KEY (client_id, group_id)
|
||||
);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
# Source utils.sh for getFTLConfigValue()
|
||||
PI_HOLE_SCRIPT_DIR='/opt/pihole'
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
. "${utilsfile}"
|
||||
|
||||
# Get file paths
|
||||
|
@ -3,32 +3,32 @@
|
||||
# Source utils.sh for getFTLConfigValue()
|
||||
PI_HOLE_SCRIPT_DIR='/opt/pihole'
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
. "${utilsfile}"
|
||||
|
||||
# Get file paths
|
||||
FTL_PID_FILE="$(getFTLConfigValue files.pid)"
|
||||
|
||||
# Ensure that permissions are set so that pihole-FTL can edit all necessary files
|
||||
mkdir -p /var/log/pihole
|
||||
chown -R pihole:pihole /etc/pihole/ /var/log/pihole/
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -pm 0640 /var/log/pihole
|
||||
chown -R pihole:pihole /etc/pihole /var/log/pihole
|
||||
chmod -R 0640 /var/log/pihole
|
||||
chmod -R 0660 /etc/pihole
|
||||
|
||||
# allow all users read version file (and use pihole -v)
|
||||
chmod 0644 /etc/pihole/versions
|
||||
# Logrotate config file need to be owned by root and must not be writable by group and others
|
||||
chown root:root /etc/pihole/logrotate
|
||||
chmod 0644 /etc/pihole/logrotate
|
||||
|
||||
# allow all users to enter the directories
|
||||
chmod 0755 /etc/pihole /var/log/pihole
|
||||
|
||||
# allow pihole to access subdirs in /etc/pihole (sets execution bit on dirs)
|
||||
find /etc/pihole/ /var/log/pihole/ -type d -exec chmod 0755 {} +
|
||||
# Set all files (except TLS-related ones) to u+rw g+r
|
||||
find /etc/pihole/ /var/log/pihole/ -type f ! \( -name '*.pem' -o -name '*.crt' \) -exec chmod 0640 {} +
|
||||
# Set TLS-related files to a more restrictive u+rw *only* (they may contain private keys)
|
||||
find /etc/pihole/ -type f \( -name '*.pem' -o -name '*.crt' \) -exec chmod 0600 {} +
|
||||
|
||||
# Logrotate config file need to be owned by root
|
||||
chown root:root /etc/pihole/logrotate
|
||||
# credits https://stackoverflow.com/a/11512211
|
||||
find /etc/pihole -type d -exec chmod 0755 {} \;
|
||||
|
||||
# Touch files to ensure they exist (create if non-existing, preserve if existing)
|
||||
[ -f "${FTL_PID_FILE}" ] || install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}"
|
||||
[ -f /var/log/pihole/FTL.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log
|
||||
[ -f /var/log/pihole/pihole.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log
|
||||
[ -f /var/log/pihole/webserver.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/webserver.log
|
||||
[ -f /etc/pihole/dhcp.leases ] || install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases
|
||||
|
@ -12,7 +12,7 @@
|
||||
# Source utils.sh for getFTLConfigValue(), getFTLPID()
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
. "${utilsfile}"
|
||||
|
||||
|
||||
@ -57,16 +57,13 @@ start() {
|
||||
stop() {
|
||||
if is_running; then
|
||||
kill "${FTL_PID}"
|
||||
# Give FTL 60 seconds to gracefully stop
|
||||
i=1
|
||||
while [ "${i}" -le 60 ]; do
|
||||
for i in 1 2 3 4 5; do
|
||||
if ! is_running; then
|
||||
break
|
||||
fi
|
||||
|
||||
printf "."
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo
|
||||
|
||||
|
@ -28,7 +28,7 @@ ExecReload=/bin/kill -HUP $MAINPID
|
||||
ExecStopPost=/opt/pihole/pihole-FTL-poststop.sh
|
||||
|
||||
# Use graceful shutdown with a reasonable timeout
|
||||
TimeoutStopSec=60s
|
||||
TimeoutStopSec=10s
|
||||
|
||||
# Make /usr, /boot, /etc and possibly some more folders read-only...
|
||||
ProtectSystem=full
|
||||
|
@ -7,7 +7,7 @@ _pihole() {
|
||||
|
||||
case "${prev}" in
|
||||
"pihole")
|
||||
opts="allow allow-regex allow-wild deny checkout debug disable enable flush help logging query repair regex reloaddns reloadlists status tail uninstall updateGravity updatePihole version wildcard arpflush api"
|
||||
opts="allow allow-regex allow-wild deny checkout debug disable enable flush help logging query reconfigure regex reloaddns reloadlists status tail uninstall updateGravity updatePihole version wildcard arpflush api"
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
;;
|
||||
"allow"|"deny"|"wildcard"|"regex"|"allow-regex"|"allow-wild")
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) Pi-hole (https://pi-hole.net)
|
||||
@ -48,6 +49,7 @@ Google (ECS, DNSSEC);8.8.8.8;8.8.4.4;2001:4860:4860:0:0:0:0:8888;2001:4860:4860:
|
||||
OpenDNS (ECS, DNSSEC);208.67.222.222;208.67.220.220;2620:119:35::35;2620:119:53::53
|
||||
Level3;4.2.2.1;4.2.2.2;;
|
||||
Comodo;8.26.56.26;8.20.247.20;;
|
||||
DNS.WATCH (DNSSEC);84.200.69.80;84.200.70.40;2001:1608:10:25:0:0:1c04:b12f;2001:1608:10:25:0:0:9249:d69b
|
||||
Quad9 (filtered, DNSSEC);9.9.9.9;149.112.112.112;2620:fe::fe;2620:fe::9
|
||||
Quad9 (unfiltered, no DNSSEC);9.9.9.10;149.112.112.10;2620:fe::10;2620:fe::fe:10
|
||||
Quad9 (filtered, ECS, DNSSEC);9.9.9.11;149.112.112.11;2620:fe::11;2620:fe::fe:11
|
||||
@ -55,17 +57,6 @@ Cloudflare (DNSSEC);1.1.1.1;1.0.0.1;2606:4700:4700::1111;2606:4700:4700::1001
|
||||
EOM
|
||||
)
|
||||
|
||||
DNS_SERVERS_IPV6_ONLY=$(
|
||||
cat <<EOM
|
||||
Google (ECS, DNSSEC);2001:4860:4860:0:0:0:0:8888;2001:4860:4860:0:0:0:0:8844
|
||||
OpenDNS (ECS, DNSSEC);2620:119:35::35;2620:119:53::53
|
||||
Quad9 (filtered, DNSSEC);2620:fe::fe;2620:fe::9
|
||||
Quad9 (unfiltered, no DNSSEC);2620:fe::10;2620:fe::fe:10
|
||||
Quad9 (filtered, ECS, DNSSEC);2620:fe::11;2620:fe::fe:11
|
||||
Cloudflare (DNSSEC);2606:4700:4700::1111;2606:4700:4700::1001
|
||||
EOM
|
||||
)
|
||||
|
||||
# Location for final installation log storage
|
||||
installLogLoc="/etc/pihole/install.log"
|
||||
# This is a file used for the colorized output
|
||||
@ -90,7 +81,9 @@ PI_HOLE_INSTALL_DIR="/opt/pihole"
|
||||
PI_HOLE_CONFIG_DIR="/etc/pihole"
|
||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||
PI_HOLE_V6_CONFIG="${PI_HOLE_CONFIG_DIR}/pihole.toml"
|
||||
fresh_install=true
|
||||
if [ -z "$useUpdateVars" ]; then
|
||||
useUpdateVars=false
|
||||
fi
|
||||
|
||||
adlistFile="/etc/pihole/adlists.list"
|
||||
# Pi-hole needs an IP address; to begin, these variables are empty since we don't know what the IP is until this script can run
|
||||
@ -98,8 +91,8 @@ IPV4_ADDRESS=${IPV4_ADDRESS}
|
||||
IPV6_ADDRESS=${IPV6_ADDRESS}
|
||||
# Give settings their default values. These may be changed by prompts later in the script.
|
||||
QUERY_LOGGING=
|
||||
WEBPORT=
|
||||
PRIVACY_LEVEL=
|
||||
PIHOLE_INTERFACE=
|
||||
|
||||
# Where old configs go to if a v6 migration is performed
|
||||
V6_CONF_MIGRATION_DIR="/etc/pihole/migration_backup_v6"
|
||||
@ -116,13 +109,11 @@ c=70
|
||||
PIHOLE_META_PACKAGE_CONTROL_APT=$(
|
||||
cat <<EOM
|
||||
Package: pihole-meta
|
||||
Version: 0.4
|
||||
Version: 0.1
|
||||
Maintainer: Pi-hole team <adblock@pi-hole.net>
|
||||
Architecture: all
|
||||
Description: Pi-hole dependency meta package
|
||||
Depends: awk,bash-completion,binutils,ca-certificates,cron|cron-daemon,curl,dialog,dnsutils,dns-root-data,git,grep,iproute2,iputils-ping,jq,libcap2,libcap2-bin,lshw,netcat-openbsd,procps,psmisc,sudo,unzip
|
||||
Section: contrib/metapackages
|
||||
Priority: optional
|
||||
Depends: grep,dnsutils,binutils,git,iproute2,dialog,ca-certificates,cron,curl,iputils-ping,psmisc,sudo,unzip,libcap2-bin,dns-root-data,libcap2,netcat-openbsd,procps,jq,lshw,bash-completion
|
||||
EOM
|
||||
)
|
||||
|
||||
@ -130,12 +121,12 @@ EOM
|
||||
PIHOLE_META_PACKAGE_CONTROL_RPM=$(
|
||||
cat <<EOM
|
||||
Name: pihole-meta
|
||||
Version: 0.2
|
||||
Version: 0.1
|
||||
Release: 1
|
||||
License: EUPL
|
||||
BuildArch: noarch
|
||||
Summary: Pi-hole dependency meta package
|
||||
Requires: bash-completion,bind-utils,binutils,ca-certificates,chkconfig,cronie,curl,dialog,findutils,gawk,git,grep,iproute,jq,libcap,lshw,nmap-ncat,procps-ng,psmisc,sudo,unzip
|
||||
Requires: grep,curl,psmisc,sudo, unzip,jq,git,dialog,ca-certificates, bind-utils, iproute, procps-ng, chkconfig, binutils, cronie, findutils, libcap, nmap-ncat, lshw, bash-completion
|
||||
%description
|
||||
Pi-hole dependency meta package
|
||||
%prep
|
||||
@ -143,9 +134,6 @@ Pi-hole dependency meta package
|
||||
%files
|
||||
%install
|
||||
%changelog
|
||||
* Wed May 28 2025 Pi-hole Team - 0.2
|
||||
- Add gawk to the list of dependencies
|
||||
|
||||
* Sun Sep 29 2024 Pi-hole Team - 0.1
|
||||
- First version being packaged
|
||||
EOM
|
||||
@ -154,12 +142,12 @@ EOM
|
||||
######## Undocumented Flags. Shhh ########
|
||||
# These are undocumented flags; some of which we can use when repairing an installation
|
||||
# The runUnattended flag is one example of this
|
||||
repair=false
|
||||
reconfigure=false
|
||||
runUnattended=false
|
||||
# Check arguments for the undocumented flags
|
||||
for var in "$@"; do
|
||||
case "$var" in
|
||||
"--repair") repair=true ;;
|
||||
"--reconfigure") reconfigure=true ;;
|
||||
"--unattended") runUnattended=true ;;
|
||||
esac
|
||||
done
|
||||
@ -167,7 +155,6 @@ done
|
||||
# If the color table file exists,
|
||||
if [[ -f "${coltable}" ]]; then
|
||||
# source it
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source "${coltable}"
|
||||
# Otherwise,
|
||||
else
|
||||
@ -231,6 +218,176 @@ is_command() {
|
||||
command -v "${check_command}" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
os_check_dig(){
|
||||
local protocol="$1"
|
||||
local domain="$2"
|
||||
local nameserver="$3"
|
||||
local response
|
||||
|
||||
response="$(dig -"${protocol}" +short -t txt "${domain}" "${nameserver}" 2>&1
|
||||
echo $?
|
||||
)"
|
||||
echo "${response}"
|
||||
}
|
||||
|
||||
os_check_dig_response(){
|
||||
# Checks the reply from the dig command to determine if it's a valid response
|
||||
local digReply="$1"
|
||||
local response
|
||||
|
||||
# Dig returned 0 (success), so get the actual response, and loop through it to determine if the detected variables above are valid
|
||||
response="${digReply%%$'\n'*}"
|
||||
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
|
||||
if [ "${response}" == 0 ]; then
|
||||
echo false
|
||||
else
|
||||
echo true
|
||||
fi
|
||||
}
|
||||
|
||||
os_check() {
|
||||
if [ "$PIHOLE_SKIP_OS_CHECK" != true ]; then
|
||||
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
|
||||
# and determines whether or not the script is running on one of those systems
|
||||
local remote_os_domain valid_os valid_version valid_response detected_os detected_version display_warning cmdResult digReturnCode response
|
||||
local piholeNameserver="@ns1.pi-hole.net"
|
||||
remote_os_domain=${OS_CHECK_DOMAIN_NAME:-"versions.pi-hole.net"}
|
||||
|
||||
detected_os=$(grep '^ID=' /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
# Test via IPv4 and hardcoded nameserver ns1.pi-hole.net
|
||||
cmdResult=$(os_check_dig 4 "${remote_os_domain}" "${piholeNameserver}")
|
||||
|
||||
# Gets the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
if [ ! "${digReturnCode}" == "0" ]; then
|
||||
valid_response=false
|
||||
else
|
||||
valid_response=$(os_check_dig_response cmdResult)
|
||||
fi
|
||||
|
||||
# Try again via IPv6 and hardcoded nameserver ns1.pi-hole.net
|
||||
if [ "$valid_response" = false ]; then
|
||||
unset valid_response
|
||||
unset cmdResult
|
||||
unset digReturnCode
|
||||
|
||||
cmdResult=$(os_check_dig 6 "${remote_os_domain}" "${piholeNameserver}")
|
||||
# Gets the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
if [ ! "${digReturnCode}" == "0" ]; then
|
||||
valid_response=false
|
||||
else
|
||||
valid_response=$(os_check_dig_response cmdResult)
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try again without hardcoded nameserver
|
||||
if [ "$valid_response" = false ]; then
|
||||
unset valid_response
|
||||
unset cmdResult
|
||||
unset digReturnCode
|
||||
|
||||
cmdResult=$(os_check_dig 4 "${remote_os_domain}")
|
||||
# Gets the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
if [ ! "${digReturnCode}" == "0" ]; then
|
||||
valid_response=false
|
||||
else
|
||||
valid_response=$(os_check_dig_response cmdResult)
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$valid_response" = false ]; then
|
||||
unset valid_response
|
||||
unset cmdResult
|
||||
unset digReturnCode
|
||||
|
||||
cmdResult=$(os_check_dig 6 "${remote_os_domain}")
|
||||
# Gets the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
if [ ! "${digReturnCode}" == "0" ]; then
|
||||
valid_response=false
|
||||
else
|
||||
valid_response=$(os_check_dig_response cmdResult)
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$valid_response" = true ]; then
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
||||
for distro_and_versions in "${supportedOS[@]}"; do
|
||||
distro_part="${distro_and_versions%%=*}"
|
||||
versions_part="${distro_and_versions##*=}"
|
||||
|
||||
# If the distro part is a (case-insensitive) substring of the computer OS
|
||||
if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then
|
||||
valid_os=true
|
||||
IFS="," read -r -a supportedVer <<<"${versions_part}"
|
||||
for version in "${supportedVer[@]}"; do
|
||||
if [[ "${detected_version}" =~ $version ]]; then
|
||||
valid_version=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$valid_os" = true ] && [ "$valid_version" = true ] && [ "$valid_response" = true ]; then
|
||||
display_warning=false
|
||||
fi
|
||||
|
||||
if [ "$display_warning" != false ]; then
|
||||
if [ "$valid_response" = false ]; then
|
||||
|
||||
if [ "${digReturnCode}" -eq 0 ]; then
|
||||
errStr="dig succeeded, but response was blank. Please contact support"
|
||||
else
|
||||
errStr="dig failed with return code ${digReturnCode}"
|
||||
fi
|
||||
printf " %b %bRetrieval of supported OS list failed. %s. %b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${errStr}" "${COL_NC}"
|
||||
printf " %bUnable to determine if the detected OS (%s %s) is supported%b\\n" "${COL_LIGHT_RED}" "${detected_os^}" "${detected_version}" "${COL_NC}"
|
||||
printf " Possible causes for this include:\\n"
|
||||
printf " - Firewall blocking DNS lookups from Pi-hole device to ns1.pi-hole.net\\n"
|
||||
printf " - DNS resolution issues of the host system\\n"
|
||||
printf " - Other internet connectivity issues\\n"
|
||||
else
|
||||
printf " %b %bUnsupported OS detected: %s %s%b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${detected_os^}" "${detected_version}" "${COL_NC}"
|
||||
printf " If you are seeing this message and you do have a supported OS, please contact support.\\n"
|
||||
fi
|
||||
printf "\\n"
|
||||
printf " %bhttps://docs.pi-hole.net/main/prerequisites/#supported-operating-systems%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
printf " If you wish to attempt to continue anyway, you can try one of the following commands to skip this check:\\n"
|
||||
printf "\\n"
|
||||
printf " e.g: If you are seeing this message on a fresh install, you can run:\\n"
|
||||
printf " %bcurl -sSL https://install.pi-hole.net | sudo PIHOLE_SKIP_OS_CHECK=true bash%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
printf " If you are seeing this message after having run pihole -up:\\n"
|
||||
printf " %bsudo PIHOLE_SKIP_OS_CHECK=true pihole -r%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf " (In this case, your previous run of pihole -up will have already updated the local repository)\\n"
|
||||
printf "\\n"
|
||||
printf " It is possible that the installation will still fail at this stage due to an unsupported configuration.\\n"
|
||||
printf " If that is the case, you can feel free to ask the community on Discourse with the %bCommunity Help%b category:\\n" "${COL_LIGHT_RED}" "${COL_NC}"
|
||||
printf " %bhttps://discourse.pi-hole.net/c/bugs-problems-issues/community-help/%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
exit 1
|
||||
|
||||
else
|
||||
printf " %b %bSupported OS detected%b\\n" "${TICK}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
fi
|
||||
else
|
||||
printf " %b %bPIHOLE_SKIP_OS_CHECK env variable set to true - installer will continue%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Compatibility
|
||||
package_manager_detect() {
|
||||
|
||||
@ -532,11 +689,7 @@ find_IPv4_information() {
|
||||
local IPv4bare
|
||||
|
||||
# Find IP used to route to outside world by checking the route to Google's public DNS server
|
||||
if ! route="$(ip route get 8.8.8.8 2> /dev/null)"; then
|
||||
printf " %b No IPv4 route was detected.\n" "${INFO}"
|
||||
IPV4_ADDRESS=""
|
||||
return
|
||||
fi
|
||||
route=$(ip route get 8.8.8.8)
|
||||
|
||||
# Get just the interface IPv4 address
|
||||
# shellcheck disable=SC2059,SC2086
|
||||
@ -552,32 +705,10 @@ find_IPv4_information() {
|
||||
IPV4_ADDRESS=$(ip -oneline -family inet address show | grep "${IPv4bare}/" | awk '{print $4}' | awk 'END {print}')
|
||||
}
|
||||
|
||||
confirm_ipv6_only() {
|
||||
# Confirm from user before IPv6 only install
|
||||
|
||||
dialog --no-shadow --output-fd 1 \
|
||||
--no-button "Exit" --yes-button "Install IPv6 ONLY" \
|
||||
--yesno "\\n\\nWARNING - no valid IPv4 route detected.\\n\\n\
|
||||
This may be due to a temporary connectivity issue,\\n\
|
||||
or you may be installing on an IPv6 only system.\\n\\n\
|
||||
Do you wish to continue with an IPv6-only installation?\\n\\n" \
|
||||
"${r}" "${c}" && result=0 || result="$?"
|
||||
|
||||
case "${result}" in
|
||||
"${DIALOG_CANCEL}" | "${DIALOG_ESC}")
|
||||
printf " %b Installer exited at IPv6 only message.\\n" "${INFO}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
DNS_SERVERS="$DNS_SERVERS_IPV6_ONLY"
|
||||
printf " %b Proceeding with IPv6 only installation.\\n" "${INFO}"
|
||||
}
|
||||
|
||||
# Get available interfaces that are UP
|
||||
get_available_interfaces() {
|
||||
# There may be more than one so it's all stored in a variable
|
||||
availableInterfaces=$(ip --oneline link show up | awk '{print $2}' | grep -v "^lo" | cut -d':' -f1 | cut -d'@' -f1)
|
||||
availableInterfaces=$(ip --oneline link show up | grep -v "lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
||||
}
|
||||
|
||||
# A function for displaying the dialogs the user sees when first running the installer
|
||||
@ -639,6 +770,7 @@ chooseInterface() {
|
||||
# All further interfaces are deselected
|
||||
status="OFF"
|
||||
done
|
||||
# shellcheck disable=SC2086
|
||||
# Disable check for double quote here as we are passing a string with spaces
|
||||
PIHOLE_INTERFACE=$(dialog --no-shadow --keep-tite --output-fd 1 \
|
||||
--cancel-label "Exit" --ok-label "Select" \
|
||||
@ -727,9 +859,6 @@ collect_v4andv6_information() {
|
||||
printf " %b IPv4 address: %s\\n" "${INFO}" "${IPV4_ADDRESS}"
|
||||
find_IPv6_information
|
||||
printf " %b IPv6 address: %s\\n" "${INFO}" "${IPV6_ADDRESS}"
|
||||
if [ "$IPV4_ADDRESS" == "" ] && [ "$IPV6_ADDRESS" != "" ]; then
|
||||
confirm_ipv6_only
|
||||
fi
|
||||
}
|
||||
|
||||
# Check an IP address to see if it is a valid one
|
||||
@ -982,7 +1111,7 @@ setPrivacyLevel() {
|
||||
|
||||
# A function to display a list of example blocklists for users to select
|
||||
chooseBlocklists() {
|
||||
# Back up any existing adlist file, on the off chance that it exists.
|
||||
# Back up any existing adlist file, on the off chance that it exists. Useful in case of a reconfigure.
|
||||
if [[ -f "${adlistFile}" ]]; then
|
||||
mv "${adlistFile}" "${adlistFile}.old"
|
||||
fi
|
||||
@ -1031,23 +1160,27 @@ installDefaultBlocklists() {
|
||||
echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >>"${adlistFile}"
|
||||
}
|
||||
|
||||
move_old_dnsmasq_ftl_configs() {
|
||||
# Create migration directory /etc/pihole/migration_backup_v6
|
||||
# and make it owned by pihole:pihole
|
||||
mkdir -p "${V6_CONF_MIGRATION_DIR}"
|
||||
chown pihole:pihole "${V6_CONF_MIGRATION_DIR}"
|
||||
|
||||
# Move all conf files originally created by Pi-hole into this directory
|
||||
# - 01-pihole.conf
|
||||
# - 02-pihole-dhcp.conf
|
||||
# - 04-pihole-static-dhcp.conf
|
||||
# - 05-pihole-custom-cname.conf
|
||||
# - 06-rfc6761.conf
|
||||
mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true
|
||||
mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true
|
||||
|
||||
# If the dnsmasq main config file exists
|
||||
remove_old_dnsmasq_ftl_configs() {
|
||||
# Local, named variables
|
||||
local dnsmasq_conf="/etc/dnsmasq.conf"
|
||||
local pihole_01="/etc/dnsmasq.d/01-pihole.conf"
|
||||
local rfc6761_06="/etc/dnsmasq.d/06-rfc6761.conf"
|
||||
local pihole_dhcp_02="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
|
||||
# pihole-FTL does some fancy stuff with config these days, and so we can remove some old config files
|
||||
if [[ -f "${pihole_01}" ]]; then
|
||||
rm "${pihole_01}"
|
||||
fi
|
||||
|
||||
if [[ -f "${rfc6761_06}" ]]; then
|
||||
rm "${rfc6761_06}"
|
||||
fi
|
||||
|
||||
if [[ -f "${pihole_dhcp_02}" ]]; then
|
||||
rm "${pihole_dhcp_02}"
|
||||
fi
|
||||
|
||||
# If the dnsmasq config file exists
|
||||
if [[ -f "${dnsmasq_conf}" ]]; then
|
||||
# There should not be anything custom in here for Pi-hole users
|
||||
# It is no longer needed, but we'll back it up instead of deleting it just in case
|
||||
@ -1078,13 +1211,13 @@ remove_old_pihole_lighttpd_configs() {
|
||||
lighty-disable-mod pihole-admin >/dev/null || true
|
||||
fi
|
||||
|
||||
if [[ -f "${confenabled}" || -L "${confenabled}" ]]; then
|
||||
rm "${confenabled}"
|
||||
fi
|
||||
|
||||
if [[ -f "${confavailable}" ]]; then
|
||||
rm "${confavailable}"
|
||||
fi
|
||||
|
||||
if [[ -f "${confenabled}" ]]; then
|
||||
rm "${confenabled}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clean an existing installation to prepare for upgrade/reinstall
|
||||
@ -1155,7 +1288,8 @@ installConfigs() {
|
||||
fi
|
||||
|
||||
# Install pihole-FTL systemd or init.d service, based on whether systemd is the init system or not
|
||||
if ps -p 1 -o comm= | grep -q systemd; then
|
||||
# Follow debhelper logic, which checks for /run/systemd/system to derive whether systemd is the init system
|
||||
if [[ -d '/run/systemd/system' ]]; then
|
||||
install -T -m 0644 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.systemd" '/etc/systemd/system/pihole-FTL.service'
|
||||
|
||||
# Remove init.d service if present
|
||||
@ -1224,9 +1358,9 @@ stop_service() {
|
||||
local str="Stopping ${1} service"
|
||||
printf " %b %s..." "${INFO}" "${str}"
|
||||
if is_command systemctl; then
|
||||
systemctl -q stop "${1}" || true
|
||||
systemctl stop "${1}" &>/dev/null || true
|
||||
else
|
||||
service "${1}" stop >/dev/null || true
|
||||
service "${1}" stop &>/dev/null || true
|
||||
fi
|
||||
printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}"
|
||||
}
|
||||
@ -1239,10 +1373,10 @@ restart_service() {
|
||||
# If systemctl exists,
|
||||
if is_command systemctl; then
|
||||
# use that to restart the service
|
||||
systemctl -q restart "${1}"
|
||||
systemctl restart "${1}" &>/dev/null
|
||||
else
|
||||
# Otherwise, fall back to the service command
|
||||
service "${1}" restart >/dev/null
|
||||
service "${1}" restart &>/dev/null
|
||||
fi
|
||||
printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}"
|
||||
}
|
||||
@ -1255,10 +1389,10 @@ enable_service() {
|
||||
# If systemctl exists,
|
||||
if is_command systemctl; then
|
||||
# use that to enable the service
|
||||
systemctl -q enable "${1}"
|
||||
systemctl enable "${1}" &>/dev/null
|
||||
else
|
||||
# Otherwise, use update-rc.d to accomplish this
|
||||
update-rc.d "${1}" defaults >/dev/null
|
||||
update-rc.d "${1}" defaults &>/dev/null
|
||||
fi
|
||||
printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}"
|
||||
}
|
||||
@ -1271,10 +1405,10 @@ disable_service() {
|
||||
# If systemctl exists,
|
||||
if is_command systemctl; then
|
||||
# use that to disable the service
|
||||
systemctl -q disable "${1}"
|
||||
systemctl disable "${1}" &>/dev/null
|
||||
else
|
||||
# Otherwise, use update-rc.d to accomplish this
|
||||
update-rc.d "${1}" disable >/dev/null
|
||||
update-rc.d "${1}" disable &>/dev/null
|
||||
fi
|
||||
printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}"
|
||||
}
|
||||
@ -1283,7 +1417,7 @@ check_service_active() {
|
||||
# If systemctl exists,
|
||||
if is_command systemctl; then
|
||||
# use that to check the status of the service
|
||||
systemctl -q is-enabled "${1}" 2>/dev/null
|
||||
systemctl is-enabled "${1}" &>/dev/null
|
||||
else
|
||||
# Otherwise, fall back to service command
|
||||
service "${1}" status &>/dev/null
|
||||
@ -1342,12 +1476,17 @@ notify_package_updates_available() {
|
||||
# Store the list of packages in a variable
|
||||
updatesToInstall=$(eval "${PKG_COUNT}")
|
||||
|
||||
if [[ -d "/lib/modules/$(uname -r)" ]]; then
|
||||
if [[ "${updatesToInstall}" -eq 0 ]]; then
|
||||
printf "%b %b %s... up to date!\\n\\n" "${OVER}" "${TICK}" "${str}"
|
||||
else
|
||||
printf "%b %b %s... %s updates available\\n" "${OVER}" "${TICK}" "${str}" "${updatesToInstall}"
|
||||
printf " %b %bIt is recommended to update your OS after installing the Pi-hole!%b\\n\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
fi
|
||||
else
|
||||
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}"
|
||||
printf " Kernel update detected. If the install fails, please reboot and try again\\n"
|
||||
fi
|
||||
}
|
||||
|
||||
install_dependent_packages() {
|
||||
@ -1555,8 +1694,7 @@ installPihole() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Move old dnsmasq files to $V6_CONF_MIGRATION_DIR for later migration via migrate_dnsmasq_configs()
|
||||
move_old_dnsmasq_ftl_configs
|
||||
remove_old_dnsmasq_ftl_configs
|
||||
remove_old_pihole_lighttpd_configs
|
||||
|
||||
# Install config files
|
||||
@ -1621,10 +1759,86 @@ checkSelinux() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Installation complete message with instructions for the user
|
||||
displayFinalMessage() {
|
||||
# TODO: COME BACK TO THIS, WHAT IS GOING ON?
|
||||
# If the number of arguments is > 0,
|
||||
if [[ "${#1}" -gt 0 ]]; then
|
||||
# set the password to the first argument.
|
||||
pwstring="$1"
|
||||
elif [[ $(pihole-FTL --config webserver.api.pwhash) == '""' ]]; then
|
||||
# Else if the password exists from previous setup, we'll load it later
|
||||
pwstring="unchanged"
|
||||
else
|
||||
# Else, inform the user that there is no set password.
|
||||
pwstring="NOT SET"
|
||||
fi
|
||||
|
||||
# Store a message in a variable and display it
|
||||
additional="View the web interface at http://pi.hole/admin:${WEBPORT} or http://${IPV4_ADDRESS%/*}:${WEBPORT}/admin\\n\\nYour Admin Webpage login password is ${pwstring}"
|
||||
|
||||
# Final completion message to user
|
||||
dialog --no-shadow --keep-tite \
|
||||
--title "Installation Complete!" \
|
||||
--msgbox "Configure your devices to use the Pi-hole as their DNS server using:\
|
||||
\\n\\nIPv4: ${IPV4_ADDRESS%/*}\
|
||||
\\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\
|
||||
\\nIf you have not done so already, the above IP should be set to static.\
|
||||
\\n${additional}" "${r}" "${c}"
|
||||
}
|
||||
|
||||
update_dialogs() {
|
||||
# If pihole -r "reconfigure" option was selected,
|
||||
if [[ "${reconfigure}" = true ]]; then
|
||||
# set some variables that will be used
|
||||
opt1a="Repair"
|
||||
opt1b="This will retain existing settings"
|
||||
strAdd="You will remain on the same version"
|
||||
else
|
||||
# Otherwise, set some variables with different values
|
||||
opt1a="Update"
|
||||
opt1b="This will retain existing settings."
|
||||
strAdd="You will be updated to the latest version."
|
||||
fi
|
||||
opt2a="Reconfigure"
|
||||
opt2b="Resets Pi-hole and allows re-selecting settings."
|
||||
|
||||
# Display the information to the user
|
||||
UpdateCmd=$(dialog --no-shadow --keep-tite --output-fd 1 \
|
||||
--cancel-label Exit \
|
||||
--title "Existing Install Detected!" \
|
||||
--menu "\\n\\nWe have detected an existing install.\
|
||||
\\n\\nPlease choose from the following options:\
|
||||
\\n($strAdd)" \
|
||||
"${r}" "${c}" 2 \
|
||||
"${opt1a}" "${opt1b}" \
|
||||
"${opt2a}" "${opt2b}") || result=$?
|
||||
|
||||
case ${result} in
|
||||
"${DIALOG_CANCEL}" | "${DIALOG_ESC}")
|
||||
printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Set the variable based on if the user chooses
|
||||
case ${UpdateCmd} in
|
||||
# repair, or
|
||||
"${opt1a}")
|
||||
printf " %b %s option selected\\n" "${INFO}" "${opt1a}"
|
||||
useUpdateVars=true
|
||||
;;
|
||||
# reconfigure,
|
||||
"${opt2a}")
|
||||
printf " %b %s option selected\\n" "${INFO}" "${opt2a}"
|
||||
useUpdateVars=false
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_download_exists() {
|
||||
# Check if the download exists and we can reach the server
|
||||
local status
|
||||
status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
||||
local status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
||||
|
||||
# Check the status code
|
||||
if grep -q "200" <<<"$status"; then
|
||||
@ -1708,10 +1922,10 @@ checkout_pull_branch() {
|
||||
return 0
|
||||
}
|
||||
|
||||
clone_or_reset_repos() {
|
||||
# If the user wants to repair/update,
|
||||
if [[ "${repair}" == true ]]; then
|
||||
printf " %b Resetting local repos\\n" "${INFO}"
|
||||
clone_or_update_repos() {
|
||||
# If the user wants to reconfigure,
|
||||
if [[ "${reconfigure}" == true ]]; then
|
||||
printf " %b Performing reconfiguration, skipping download of local repos\\n" "${INFO}"
|
||||
# Reset the Core repo
|
||||
resetRepo ${PI_HOLE_LOCAL_REPO} ||
|
||||
{
|
||||
@ -1724,7 +1938,7 @@ clone_or_reset_repos() {
|
||||
printf " %b Unable to reset %s, exiting installer%b\\n" "${COL_LIGHT_RED}" "${webInterfaceDir}" "${COL_NC}"
|
||||
exit 1
|
||||
}
|
||||
# Otherwise, a fresh installation is happening
|
||||
# Otherwise, a repair is happening
|
||||
else
|
||||
# so get git files for Core
|
||||
getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} ||
|
||||
@ -1743,6 +1957,7 @@ clone_or_reset_repos() {
|
||||
|
||||
# Download FTL binary to random temp directory and install FTL binary
|
||||
# Disable directive for SC2120 a value _can_ be passed to this function, but it is passed from an external script that sources this one
|
||||
# shellcheck disable=SC2120
|
||||
FTLinstall() {
|
||||
# Local, named variables
|
||||
local str="Downloading and Installing FTL"
|
||||
@ -1786,7 +2001,7 @@ FTLinstall() {
|
||||
curl -sSL "https://ftl.pi-hole.net/macvendor.db" -o "${PI_HOLE_CONFIG_DIR}/macvendor.db" || true
|
||||
|
||||
# Stop pihole-FTL service if available
|
||||
stop_service pihole-FTL >/dev/null
|
||||
stop_service pihole-FTL &>/dev/null
|
||||
|
||||
# Install the new version with the correct permissions
|
||||
install -T -m 0755 "${binary}" /usr/bin/pihole-FTL
|
||||
@ -1907,7 +2122,7 @@ get_binary_name() {
|
||||
else
|
||||
printf "%b %b Detected 32bit (i686) architecture\\n" "${OVER}" "${TICK}"
|
||||
fi
|
||||
l_binary="pihole-FTL-386"
|
||||
l_binary="pihole-FTL-linux-386"
|
||||
fi
|
||||
|
||||
# Returning a string value via echo
|
||||
@ -1940,13 +2155,13 @@ FTLcheckUpdate() {
|
||||
path="${ftlBranch}/${binary}"
|
||||
|
||||
# Check whether or not the binary for this FTL branch actually exists. If not, then there is no update!
|
||||
# shellcheck disable=SC1090
|
||||
if ! check_download_exists "$path"; then
|
||||
local status
|
||||
status=$?
|
||||
if [ "${status}" -eq 1 ]; then
|
||||
if [ $? -eq 1 ]; then
|
||||
printf " %b Branch \"%s\" is not available.\\n" "${INFO}" "${ftlBranch}"
|
||||
printf " %b Use %bpihole checkout ftl [branchname]%b to switch to a valid branch.\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
elif [ "${status}" -eq 2 ]; then
|
||||
return 2
|
||||
elif [ $? -eq 2 ]; then
|
||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||
return 3
|
||||
else
|
||||
@ -1974,14 +2189,12 @@ FTLcheckUpdate() {
|
||||
# same as the remote one
|
||||
local FTLversion
|
||||
FTLversion=$(/usr/bin/pihole-FTL tag)
|
||||
local FTLlatesttag
|
||||
|
||||
# Get the latest version from the GitHub API
|
||||
local FTLlatesttag
|
||||
FTLlatesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | jq -sRr 'fromjson? | .tag_name | values')
|
||||
|
||||
if [ -z "${FTLlatesttag}" ]; then
|
||||
if ! FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep --color=never -i Location: | awk -F / '{print $NF}' | tr -d '[:cntrl:]'); then
|
||||
# There was an issue while retrieving the latest version
|
||||
printf " %b Failed to retrieve latest FTL release metadata\\n" "${CROSS}"
|
||||
printf " %b Failed to retrieve latest FTL release metadata" "${CROSS}"
|
||||
return 3
|
||||
fi
|
||||
|
||||
@ -1999,7 +2212,6 @@ FTLcheckUpdate() {
|
||||
# Continue further down...
|
||||
fi
|
||||
else
|
||||
# FTL not installed, then download
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
@ -2099,18 +2311,33 @@ migrate_dnsmasq_configs() {
|
||||
# avoid conflicts with other services on this system
|
||||
|
||||
# Exit early if this is already Pi-hole v6.0
|
||||
# We decide this on the non-existence of the file /etc/pihole/setupVars.conf (either moved by previous migration or fresh install)
|
||||
if [[ ! -f "/etc/pihole/setupVars.conf" ]]; then
|
||||
# We decide this on the presence of the file /etc/pihole/pihole.toml
|
||||
if [[ -f "${PI_HOLE_V6_CONFIG}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Disable lighttpd server during v6 migration
|
||||
disableLighttpd
|
||||
|
||||
# move_old_dnsmasq_ftl_configs() moved everything is in place,
|
||||
# so we can create the new config file /etc/pihole/pihole.toml
|
||||
# Create target directory /etc/pihole/migration_backup_v6
|
||||
# and make it owned by pihole:pihole
|
||||
mkdir -p "${V6_CONF_MIGRATION_DIR}"
|
||||
chown pihole:pihole "${V6_CONF_MIGRATION_DIR}"
|
||||
|
||||
# Move all conf files originally created by Pi-hole into this directory
|
||||
# - 01-pihole.conf
|
||||
# - 02-pihole-dhcp.conf
|
||||
# - 04-pihole-static-dhcp.conf
|
||||
# - 05-pihole-custom-cname.conf
|
||||
# - 06-rfc6761.conf
|
||||
|
||||
mv /etc/dnsmasq.d/0{1,2,4,5}-pihole*.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true
|
||||
mv /etc/dnsmasq.d/06-rfc6761.conf "${V6_CONF_MIGRATION_DIR}/" 2>/dev/null || true
|
||||
|
||||
# Finally, after everything is in place, we can create the new config file
|
||||
# /etc/pihole/pihole.toml
|
||||
# This file will be created with the default settings unless the user has
|
||||
# changed settings via setupVars.conf or the other dnsmasq files moved before
|
||||
# changed settings via setupVars.conf or the other dnsmasq files moved above
|
||||
# During migration, setupVars.conf is moved to /etc/pihole/migration_backup_v6
|
||||
str="Migrating Pi-hole configuration to version 6"
|
||||
printf " %b %s..." "${INFO}" "${str}"
|
||||
@ -2205,6 +2432,8 @@ main() {
|
||||
# Install Pi-hole dependencies
|
||||
install_dependent_packages
|
||||
|
||||
# Check that the installed OS is officially supported - display warning if not
|
||||
os_check
|
||||
|
||||
# Check if there is a usable FTL binary available on this architecture - do
|
||||
# this early on as FTL is a hard dependency for Pi-hole
|
||||
@ -2216,19 +2445,22 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# in case of an update (can be a v5 -> v6 or v6 -> v6 update) or repair
|
||||
# in case of an update (can be a v5 -> v6 or v6 -> v6 update)
|
||||
if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then
|
||||
# retain settings
|
||||
fresh_install=false
|
||||
# if it's running unattended,
|
||||
if [[ "${runUnattended}" == true ]]; then
|
||||
printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}"
|
||||
# Use the setup variables
|
||||
useUpdateVars=true
|
||||
# also disable debconf-apt-progress dialogs
|
||||
export DEBIAN_FRONTEND="noninteractive"
|
||||
else
|
||||
# If running attended, show the available options (repair/reconfigure)
|
||||
update_dialogs
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${fresh_install}" == true ]]; then
|
||||
if [[ "${useUpdateVars}" == false ]]; then
|
||||
# Display welcome dialogs
|
||||
welcomeDialogs
|
||||
# Create directory for Pi-hole storage (/etc/pihole/)
|
||||
@ -2251,8 +2483,9 @@ main() {
|
||||
# Setup adlist file if not exists
|
||||
installDefaultBlocklists
|
||||
fi
|
||||
# Download or reset the appropriate git repos depending on the 'repair' flag
|
||||
clone_or_reset_repos
|
||||
# Download or update the scripts by updating the appropriate git repos
|
||||
clone_or_update_repos
|
||||
|
||||
|
||||
# Create the pihole user
|
||||
create_pihole_user
|
||||
@ -2272,7 +2505,7 @@ main() {
|
||||
|
||||
# /opt/pihole/utils.sh should be installed by installScripts now, so we can use it
|
||||
if [ -f "${PI_HOLE_INSTALL_DIR}/utils.sh" ]; then
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
# shellcheck disable=SC1091
|
||||
source "${PI_HOLE_INSTALL_DIR}/utils.sh"
|
||||
else
|
||||
printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" "${CROSS}"
|
||||
@ -2282,31 +2515,28 @@ main() {
|
||||
# Copy the temp log file into final log location for storage
|
||||
copy_to_install_log
|
||||
|
||||
# Add password to web UI if there is none
|
||||
pw=""
|
||||
# If no password is set,
|
||||
if [[ $(pihole-FTL --config webserver.api.pwhash) == '""' ]]; then
|
||||
# generate a random password
|
||||
pw=$(tr -dc _A-Z-a-z-0-9 </dev/urandom | head -c 8)
|
||||
pihole setpassword "${pw}"
|
||||
fi
|
||||
|
||||
# Migrate existing install to v6.0
|
||||
migrate_dnsmasq_configs
|
||||
|
||||
# Cleanup old v5 sudoers file if it exists
|
||||
sudoers_file="/etc/sudoers.d/pihole"
|
||||
if [[ -f "${sudoers_file}" ]]; then
|
||||
# only remove the file if it contains the Pi-hole header
|
||||
if grep -q "Pi-hole: A black hole for Internet advertisements" "${sudoers_file}"; then
|
||||
rm -f "${sudoers_file}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for and disable systemd-resolved-DNSStubListener before reloading resolved
|
||||
# DNSStubListener needs to remain in place for installer to download needed files,
|
||||
# so this change needs to be made after installation is complete,
|
||||
# but before starting or resttarting the ftl service
|
||||
disable_resolved_stublistener
|
||||
|
||||
if [[ "${fresh_install}" == false ]]; then
|
||||
# Check if gravity database needs to be upgraded. If so, do it without rebuilding
|
||||
# gravity altogether. This may be a very long running task needlessly blocking
|
||||
# the update process.
|
||||
# Only do this on updates, not on fresh installs as the database does not exit yet
|
||||
/opt/pihole/gravity.sh --upgrade
|
||||
fi
|
||||
|
||||
printf " %b Restarting services...\\n" "${INFO}"
|
||||
# Start services
|
||||
@ -2319,66 +2549,44 @@ main() {
|
||||
|
||||
restart_service pihole-FTL
|
||||
|
||||
if [[ "${fresh_install}" == true ]]; then
|
||||
# apply settings to pihole.toml
|
||||
# write privacy level and logging to pihole.toml
|
||||
# needs to be done after FTL service has been started, otherwise pihole.toml does not exist
|
||||
# set on fresh installations by setDNS() and setPrivacyLevel() and setLogging()
|
||||
|
||||
# Upstreams may be needed in order to run gravity.sh
|
||||
if [ -n "${PIHOLE_DNS_1}" ]; then
|
||||
local string="\"${PIHOLE_DNS_1}\""
|
||||
[ -n "${PIHOLE_DNS_2}" ] && string+=", \"${PIHOLE_DNS_2}\""
|
||||
setFTLConfigValue "dns.upstreams" "[ $string ]"
|
||||
fi
|
||||
|
||||
# set on fresh installations by setPrivacyLevel() and setLogging(
|
||||
if [ -n "${QUERY_LOGGING}" ]; then
|
||||
setFTLConfigValue "dns.queryLogging" "${QUERY_LOGGING}"
|
||||
fi
|
||||
|
||||
if [ -n "${PRIVACY_LEVEL}" ]; then
|
||||
setFTLConfigValue "misc.privacylevel" "${PRIVACY_LEVEL}"
|
||||
fi
|
||||
|
||||
if [ -n "${PIHOLE_INTERFACE}" ]; then
|
||||
setFTLConfigValue "dns.interface" "${PIHOLE_INTERFACE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Download and compile the aggregated block list
|
||||
runGravity
|
||||
|
||||
# Update local and remote versions via updatechecker
|
||||
/opt/pihole/updatecheck.sh
|
||||
|
||||
if [[ "${fresh_install}" == true ]]; then
|
||||
# If there is a password
|
||||
if ((${#pw} > 0)); then
|
||||
# display the password
|
||||
printf " %b Web Interface password: %b%s%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${pw}" "${COL_NC}"
|
||||
printf " %b This can be changed using 'pihole setpassword'\\n\\n" "${INFO}"
|
||||
fi
|
||||
|
||||
if [[ "${useUpdateVars}" == false ]]; then
|
||||
# Get the Web interface port, return only the first port and strip all non-numeric characters
|
||||
WEBPORT=$(getFTLConfigValue webserver.port|cut -d, -f1 | tr -cd '0-9')
|
||||
|
||||
# If this is a fresh install, we will set a random password.
|
||||
# Users can change this password after installation if they wish
|
||||
pw=$(tr -dc _A-Z-a-z-0-9 </dev/urandom | head -c 8)
|
||||
pihole setpassword "${pw}" > /dev/null
|
||||
# Display the completion dialog
|
||||
displayFinalMessage "${pw}"
|
||||
|
||||
# If the Web interface was installed,
|
||||
printf " %b View the web interface at http://pi.hole:${WEBPORT}/admin or http://%s/admin\\n\\n" "${INFO}" "${IPV4_ADDRESS%/*}:${WEBPORT}"
|
||||
|
||||
# Explain to the user how to use Pi-hole as their DNS server
|
||||
printf "\\n %b You may now configure your devices to use the Pi-hole as their DNS server\\n" "${INFO}"
|
||||
printf " %b You may now configure your devices to use the Pi-hole as their DNS server\\n" "${INFO}"
|
||||
[[ -n "${IPV4_ADDRESS%/*}" ]] && printf " %b Pi-hole DNS (IPv4): %s\\n" "${INFO}" "${IPV4_ADDRESS%/*}"
|
||||
[[ -n "${IPV6_ADDRESS}" ]] && printf " %b Pi-hole DNS (IPv6): %s\\n" "${INFO}" "${IPV6_ADDRESS}"
|
||||
printf " %b If you have not done so already, the above IP should be set to static.\\n" "${INFO}"
|
||||
|
||||
printf " %b View the web interface at http://pi.hole:${WEBPORT}/admin or http://%s/admin\\n\\n" "${INFO}" "${IPV4_ADDRESS%/*}:${WEBPORT}"
|
||||
printf " %b Web Interface password: %b%s%b\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${pw}" "${COL_NC}"
|
||||
printf " %b This can be changed using 'pihole setpassword'\\n\\n" "${INFO}"
|
||||
|
||||
# Final dialog message to the user
|
||||
dialog --no-shadow --keep-tite \
|
||||
--title "Installation Complete!" \
|
||||
--msgbox "Configure your devices to use the Pi-hole as their DNS server using:\
|
||||
\\n\\nIPv4: ${IPV4_ADDRESS%/*}\
|
||||
\\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\
|
||||
\\nIf you have not done so already, the above IP should be set to static.\
|
||||
\\nView the web interface at http://pi.hole/admin:${WEBPORT} or http://${IPV4_ADDRESS%/*}:${WEBPORT}/admin\\n\\nYour Admin Webpage login password is ${pw}" "${r}" "${c}"
|
||||
|
||||
INSTALL_TYPE="Installation"
|
||||
else
|
||||
INSTALL_TYPE="Update"
|
||||
|
@ -8,13 +8,7 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source "/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "/opt/pihole/utils.sh"
|
||||
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
while true; do
|
||||
read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " answer
|
||||
@ -43,7 +37,6 @@ fi
|
||||
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
SKIP_INSTALL="true"
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
|
||||
# package_manager_detect() sourced from basic-install.sh
|
||||
@ -60,9 +53,17 @@ removeMetaPackage() {
|
||||
}
|
||||
|
||||
removePiholeFiles() {
|
||||
# Remove the web interface of Pi-hole
|
||||
# Only web directories/files that are created by Pi-hole should be removed
|
||||
echo -ne " ${INFO} Removing Web Interface..."
|
||||
${SUDO} rm -rf "${ADMIN_INTERFACE_DIR}" &> /dev/null
|
||||
${SUDO} rm -rf /var/www/html/admin &> /dev/null
|
||||
|
||||
|
||||
# If the web directory is empty after removing these files, then the parent html directory can be removed.
|
||||
if [ -d "/var/www/html" ]; then
|
||||
if [[ ! "$(ls -A /var/www/html)" ]]; then
|
||||
${SUDO} rm -rf /var/www/html &> /dev/null
|
||||
fi
|
||||
fi
|
||||
echo -e "${OVER} ${TICK} Removed Web Interface"
|
||||
|
||||
# Attempt to preserve backwards compatibility with older versions
|
||||
|
141
gravity.sh
141
gravity.sh
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@ -15,13 +16,13 @@ export LC_ALL=C
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
# Source utils.sh for GetFTLConfigValue
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
# shellcheck disable=SC1090
|
||||
. "${utilsfile}"
|
||||
|
||||
coltable="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
# shellcheck disable=SC1090
|
||||
. "${coltable}"
|
||||
# shellcheck source=./advanced/Scripts/database_migration/gravity-db.sh
|
||||
# shellcheck disable=SC1091
|
||||
. "/etc/.pihole/advanced/Scripts/database_migration/gravity-db.sh"
|
||||
|
||||
basename="pihole"
|
||||
@ -57,7 +58,7 @@ fi
|
||||
# Set this only after sourcing pihole-FTL.conf as the gravity database path may
|
||||
# have changed
|
||||
gravityDBfile="${GRAVITYDB}"
|
||||
gravityDBfile_default="${piholeDir}/gravity.db"
|
||||
gravityDBfile_default="/etc/pihole/gravity.db"
|
||||
gravityTEMPfile="${GRAVITYDB}_temp"
|
||||
gravityDIR="$(dirname -- "${gravityDBfile}")"
|
||||
gravityOLDfile="${gravityDIR}/gravity_old.db"
|
||||
@ -126,7 +127,7 @@ gravity_swap_databases() {
|
||||
oldAvail=false
|
||||
if [ "${availableBlocks}" -gt "$((gravityBlocks * 2))" ] && [ -f "${gravityDBfile}" ]; then
|
||||
oldAvail=true
|
||||
cp -p "${gravityDBfile}" "${gravityOLDfile}"
|
||||
cp "${gravityDBfile}" "${gravityOLDfile}"
|
||||
fi
|
||||
|
||||
# Drop the gravity and antigravity tables + subsequent VACUUM the current
|
||||
@ -139,7 +140,7 @@ gravity_swap_databases() {
|
||||
else
|
||||
# Check if the backup directory exists
|
||||
if [ ! -d "${gravityBCKdir}" ]; then
|
||||
mkdir -p "${gravityBCKdir}" && chown pihole:pihole "${gravityBCKdir}"
|
||||
mkdir -p "${gravityBCKdir}"
|
||||
fi
|
||||
|
||||
# If multiple gravityBCKfile's are present (appended with a number), rotate them
|
||||
@ -305,7 +306,7 @@ migrate_to_database() {
|
||||
fi
|
||||
|
||||
# Check if gravity database needs to be updated
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
|
||||
# Migrate list files to new database
|
||||
if [ -e "${adListFile}" ]; then
|
||||
@ -333,7 +334,7 @@ migrate_to_database() {
|
||||
fi
|
||||
|
||||
# Check if gravity database needs to be updated
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
}
|
||||
|
||||
# Determine if DNS resolution is available before proceeding
|
||||
@ -348,24 +349,17 @@ gravity_CheckDNSResolutionAvailable() {
|
||||
echo -e " ${CROSS} DNS resolution is currently unavailable"
|
||||
fi
|
||||
|
||||
str="Waiting up to 120 seconds for DNS resolution..."
|
||||
str="Waiting until DNS resolution is available..."
|
||||
echo -ne " ${INFO} ${str}"
|
||||
|
||||
# Default DNS timeout is two seconds, plus 1 second for each dot > 120 seconds
|
||||
for ((i = 0; i < 40; i++)); do
|
||||
if getent hosts github.com &> /dev/null; then
|
||||
# If we reach this point, DNS resolution is available
|
||||
echo -e "${OVER} ${TICK} DNS resolution is available"
|
||||
return 0
|
||||
fi
|
||||
until getent hosts github.com &> /dev/null; do
|
||||
# Append one dot for each second waiting
|
||||
echo -ne "."
|
||||
str="${str}."
|
||||
echo -ne " ${OVER} ${INFO} ${str}"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# DNS resolution is still unavailable after 120 seconds
|
||||
return 1
|
||||
|
||||
# If we reach this point, DNS resolution is available
|
||||
echo -e "${OVER} ${TICK} DNS resolution is available"
|
||||
}
|
||||
|
||||
# Function: try_restore_backup
|
||||
@ -424,7 +418,7 @@ gravity_DownloadBlocklists() {
|
||||
echo -e " ${INFO} Storing gravity database in ${COL_BOLD}${gravityDBfile}${COL_NC}"
|
||||
fi
|
||||
|
||||
local url domain str compression adlist_type directory success
|
||||
local url domain str target compression adlist_type directory success
|
||||
echo ""
|
||||
|
||||
# Prepare new gravity database
|
||||
@ -573,12 +567,12 @@ gravity_DownloadBlocklists() {
|
||||
if [[ "${check_url}" =~ ${regex} ]]; then
|
||||
echo -e " ${CROSS} Invalid Target"
|
||||
else
|
||||
timeit gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${compression}" "${adlist_type}" "${domain}"
|
||||
timeit gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" "${adlist_type}" "${domain}"
|
||||
fi
|
||||
echo ""
|
||||
done
|
||||
|
||||
DownloadBlocklists_done=true
|
||||
gravity_Blackbody=true
|
||||
}
|
||||
|
||||
compareLists() {
|
||||
@ -607,7 +601,7 @@ compareLists() {
|
||||
|
||||
# Download specified URL and perform checks on HTTP status and file content
|
||||
gravity_DownloadBlocklistFromUrl() {
|
||||
local url="${1}" adlistID="${2}" saveLocation="${3}" compression="${4}" gravity_type="${5}" domain="${6}"
|
||||
local url="${1}" adlistID="${2}" saveLocation="${3}" target="${4}" compression="${5}" gravity_type="${6}" domain="${7}"
|
||||
local modifiedOptions="" listCurlBuffer str httpCode success="" ip cmd_ext
|
||||
local file_path permissions ip_addr port blocked=false download=true
|
||||
|
||||
@ -653,6 +647,32 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
str="Status:"
|
||||
echo -ne " ${INFO} ${str} Pending..."
|
||||
blocked=false
|
||||
case $(getFTLConfigValue dns.blocking.mode) in
|
||||
"IP-NODATA-AAAA" | "IP")
|
||||
# Get IP address of this domain
|
||||
ip="$(dig "${domain}" +short)"
|
||||
# Check if this IP matches any IP of the system
|
||||
if [[ -n "${ip}" && $(grep -Ec "inet(|6) ${ip}" <<<"$(ip a)") -gt 0 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NXDOMAIN")
|
||||
if [[ $(dig "${domain}" | grep "NXDOMAIN" -c) -ge 1 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NODATA")
|
||||
if [[ $(dig "${domain}" | grep "NOERROR" -c) -ge 1 ]] && [[ -z $(dig +short "${domain}") ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NULL" | *)
|
||||
if [[ $(dig "${domain}" +short | grep "0.0.0.0" -c) -ge 1 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if this domain is blocked by Pi-hole but only if the domain is not a
|
||||
# local file or empty
|
||||
if [[ $url != "file"* ]] && [[ -n "${domain}" ]]; then
|
||||
@ -750,7 +770,6 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
|
||||
if [[ "${download}" == true ]]; then
|
||||
# See https://github.com/pi-hole/pi-hole/issues/6159 for justification of the below disable directive
|
||||
# shellcheck disable=SC2086
|
||||
httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${modifiedOptions} -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2>/dev/null)
|
||||
fi
|
||||
@ -802,11 +821,11 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
done="true"
|
||||
# Check if $listCurlBuffer is a non-zero length file
|
||||
elif [[ -s "${listCurlBuffer}" ]]; then
|
||||
# Move the downloaded list to the final location
|
||||
mv "${listCurlBuffer}" "${saveLocation}"
|
||||
# Ensure the file has the correct permissions
|
||||
fix_owner_permissions "${saveLocation}"
|
||||
# Compare lists if they are identical
|
||||
# Determine if blocklist is non-standard and parse as appropriate
|
||||
gravity_ParseFileIntoDomains "${listCurlBuffer}" "${saveLocation}"
|
||||
# Remove curl buffer file after its use
|
||||
rm "${listCurlBuffer}"
|
||||
# Compare lists if are they identical
|
||||
compareLists "${adlistID}" "${saveLocation}"
|
||||
# Add domains to database table file
|
||||
pihole-FTL "${gravity_type}" parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||
@ -835,6 +854,37 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse source files into domains format
|
||||
gravity_ParseFileIntoDomains() {
|
||||
local src="${1}" destination="${2}"
|
||||
|
||||
# Remove comments and print only the domain name
|
||||
# Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous
|
||||
# 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
|
||||
# 1) Convert all characters to lowercase
|
||||
tr '[:upper:]' '[:lower:]' <"${src}" >"${destination}"
|
||||
|
||||
# 2) Remove carriage returns
|
||||
# 3) Remove lines starting with ! (ABP Comments)
|
||||
# 4) Remove lines starting with [ (ABP Header)
|
||||
# 5) Remove lines containing ABP extended CSS selectors ("##", "#$#", "#@#", "#?#") and Adguard JavaScript (#%#) preceded by a letter
|
||||
# 6) Remove comments (text starting with "#", include possible spaces before the hash sign)
|
||||
# 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses)
|
||||
# 8) Remove empty lines
|
||||
|
||||
sed -i -r \
|
||||
-e 's/\r$//' \
|
||||
-e 's/\s*!.*//g' \
|
||||
-e 's/\s*\[.*//g' \
|
||||
-e '/[a-z]\#[$?@%]{0,3}\#/d' \
|
||||
-e 's/\s*#.*//g' \
|
||||
-e 's/^.*\s+//g' \
|
||||
-e '/^$/d' "${destination}"
|
||||
|
||||
fix_owner_permissions "${destination}"
|
||||
}
|
||||
|
||||
# Report number of entries in a table
|
||||
gravity_Table_Count() {
|
||||
local table="${1}"
|
||||
@ -882,13 +932,13 @@ gravity_Cleanup() {
|
||||
# invalid_domains location
|
||||
rm "${GRAVITY_TMPDIR}"/*.ph-non-domains 2>/dev/null
|
||||
|
||||
# Ensure this function only runs when gravity_DownloadBlocklists() has completed
|
||||
if [[ "${DownloadBlocklists_done:-}" == true ]]; then
|
||||
# Remove any unused .domains/.etag/.sha files
|
||||
for file in "${listsCacheDir}"/*."${domainsExtension}"; do
|
||||
# If list is not in active array, then remove it and all associated files
|
||||
# Ensure this function only runs when gravity_SetDownloadOptions() has completed
|
||||
if [[ "${gravity_Blackbody:-}" == true ]]; then
|
||||
# Remove any unused .domains files
|
||||
for file in "${piholeDir}"/*."${domainsExtension}"; do
|
||||
# If list is not in active array, then remove it
|
||||
if [[ ! "${activeDomains[*]}" == *"${file}"* ]]; then
|
||||
rm -f "${file}"* 2>/dev/null ||
|
||||
rm -f "${file}" 2>/dev/null ||
|
||||
echo -e " ${CROSS} Failed to remove ${file##*/}"
|
||||
fi
|
||||
done
|
||||
@ -1022,7 +1072,7 @@ migrate_to_listsCache_dir() {
|
||||
# If not, we need to migrate the old files to the new directory
|
||||
local str="Migrating the list's cache directory to new location"
|
||||
echo -ne " ${INFO} ${str}..."
|
||||
mkdir -p "${listsCacheDir}" && chown pihole:pihole "${listsCacheDir}"
|
||||
mkdir -p "${listsCacheDir}"
|
||||
|
||||
# Move the old files to the new directory
|
||||
if mv "${piholeDir}"/list.* "${listsCacheDir}/" 2>/dev/null; then
|
||||
@ -1032,7 +1082,7 @@ migrate_to_listsCache_dir() {
|
||||
fi
|
||||
|
||||
# Update the list's paths in the corresponding .sha1 files to the new location
|
||||
sed -i "s|${piholeDir}/|${listsCacheDir}/|g" "${listsCacheDir}"/*.sha1 2>/dev/null
|
||||
sed -i "s|${piholeDir}/|${listsCacheDir}/|g" "${listsCacheDir}"/*.sha1
|
||||
}
|
||||
|
||||
helpFunc() {
|
||||
@ -1081,19 +1131,13 @@ for var in "$@"; do
|
||||
"-t" | "--timeit") timed=true ;;
|
||||
"-r" | "--repair") repairSelector "$3" ;;
|
||||
"-u" | "--upgrade")
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
exit 0
|
||||
;;
|
||||
"-h" | "--help") helpFunc ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if DNS is available, no need to do any database manipulation if we're not able to download adlists
|
||||
if ! timeit gravity_CheckDNSResolutionAvailable; then
|
||||
echo -e " ${CROSS} No DNS resolution available. Please contact support."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove OLD (backup) gravity file, if it exists
|
||||
if [[ -f "${gravityOLDfile}" ]]; then
|
||||
rm "${gravityOLDfile}"
|
||||
@ -1134,6 +1178,11 @@ if [[ "${forceDelete:-}" == true ]]; then
|
||||
fi
|
||||
|
||||
# Gravity downloads blocklists next
|
||||
if ! timeit gravity_CheckDNSResolutionAvailable; then
|
||||
echo -e " ${CROSS} Can not complete gravity update, no DNS is available. Please contact support."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! gravity_DownloadBlocklists; then
|
||||
echo -e " ${CROSS} Unable to create gravity database. Please try again later. If the problem persists, please contact support."
|
||||
exit 1
|
||||
|
@ -23,7 +23,7 @@ pihole -r
|
||||
.br
|
||||
\fBpihole -g\fR
|
||||
.br
|
||||
\fBpihole\fR \fB-q\fR [options]
|
||||
\fBpihole\fR -\fBq\fR [options]
|
||||
.br
|
||||
\fBpihole\fR \fB-l\fR (\fBon|off|off noflush\fR)
|
||||
.br
|
||||
@ -43,7 +43,7 @@ pihole -r
|
||||
.br
|
||||
\fBpihole\fR \fBcheckout\fR repo [branch]
|
||||
.br
|
||||
\fBpihole\fR \fBapi\fR [verbose] endpoint
|
||||
\fBpihole\fR \api\fR endpoint
|
||||
.br
|
||||
\fBpihole\fR \fBhelp\fR
|
||||
.br
|
||||
@ -234,14 +234,10 @@ Available commands and options:
|
||||
branchname Update subsystems to the specified branchname
|
||||
.br
|
||||
|
||||
\fBapi\fR [verbose] endpoint
|
||||
\fBapi\fR endpoint
|
||||
.br
|
||||
Query the Pi-hole API at <endpoint>
|
||||
.br
|
||||
|
||||
verbose Show authentication and status messages
|
||||
.br
|
||||
|
||||
.SH "EXAMPLE"
|
||||
|
||||
Some usage examples
|
||||
@ -327,11 +323,6 @@ Switching Pi-hole subsystem branches
|
||||
Queries FTL for the stats/summary endpoint
|
||||
.br
|
||||
|
||||
\fBpihole api verbose stats/summary\fR
|
||||
.br
|
||||
Same as above, but shows authentication and status messages
|
||||
.br
|
||||
|
||||
.SH "COLOPHON"
|
||||
|
||||
Get sucked into the latest news and community activity by entering Pi-hole's orbit. Information about Pi-hole, and the latest version of the software can be found at https://pi-hole.net.
|
||||
|
37
pihole
37
pihole
@ -17,16 +17,13 @@ readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||
|
||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
source "${colfile}"
|
||||
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
source "${utilsfile}"
|
||||
|
||||
# Source api functions
|
||||
readonly apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
# shellcheck source=./advanced/Scripts/api.sh
|
||||
source "${apifile}"
|
||||
|
||||
versionsfile="/etc/pihole/versions"
|
||||
@ -34,7 +31,6 @@ if [ -f "${versionsfile}" ]; then
|
||||
# Only source versionsfile if the file exits
|
||||
# fixes a warning during installation where versionsfile does not exist yet
|
||||
# but gravity calls `pihole -status` and thereby sourcing the file
|
||||
# shellcheck source=/dev/null
|
||||
source "${versionsfile}"
|
||||
fi
|
||||
|
||||
@ -111,11 +107,11 @@ updatePiholeFunc() {
|
||||
fi
|
||||
}
|
||||
|
||||
repairPiholeFunc() {
|
||||
reconfigurePiholeFunc() {
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
unsupportedFunc
|
||||
else
|
||||
/etc/.pihole/automated\ install/basic-install.sh --repair
|
||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
@ -251,14 +247,12 @@ Time:
|
||||
data=$(PostFTLData "dns/blocking" "{ \"blocking\": ${1}, \"timer\": ${tt} }")
|
||||
|
||||
# Check the response
|
||||
local extra timer
|
||||
extra=" forever"
|
||||
timer="$(echo "${data}"| jq --raw-output '.timer' )"
|
||||
local extra=" forever"
|
||||
local timer="$(echo "${data}"| jq --raw-output '.timer' )"
|
||||
if [[ "${timer}" != "null" ]]; then
|
||||
extra=" for ${timer}s"
|
||||
fi
|
||||
local str
|
||||
str="Pi-hole $(echo "${data}" | jq --raw-output '.blocking')${extra}"
|
||||
local str="Pi-hole $(echo "${data}" | jq --raw-output '.blocking')${extra}"
|
||||
|
||||
# Logout from the API
|
||||
LogoutAPI
|
||||
@ -381,16 +375,14 @@ statusFunc() {
|
||||
|
||||
tailFunc() {
|
||||
# Warn user if Pi-hole's logging is disabled
|
||||
local logging_enabled
|
||||
logging_enabled=$(getFTLConfigValue dns.queryLogging)
|
||||
local logging_enabled=$(getFTLConfigValue dns.queryLogging)
|
||||
if [[ "${logging_enabled}" != "true" ]]; then
|
||||
echo " ${CROSS} Warning: Query logging is disabled"
|
||||
fi
|
||||
echo -e " ${INFO} Press Ctrl-C to exit"
|
||||
|
||||
# Get logfile path
|
||||
LOGFILE=$(getFTLConfigValue files.log.dnsmasq)
|
||||
readonly LOGFILE
|
||||
readonly LOGFILE=$(getFTLConfigValue files.log.dnsmasq)
|
||||
|
||||
# Strip date from each line
|
||||
# Color blocklist/denylist/wildcard entries as red
|
||||
@ -406,10 +398,7 @@ tailFunc() {
|
||||
|
||||
piholeCheckoutFunc() {
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
echo -e "${CROSS} Function not supported in Docker images"
|
||||
echo "Please build a custom image following the steps at"
|
||||
echo "https://github.com/pi-hole/docker-pi-hole?tab=readme-ov-file#building-the-image-locally"
|
||||
exit 0
|
||||
unsupportedFunc
|
||||
else
|
||||
if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then
|
||||
echo "Switch Pi-hole subsystems to a different GitHub branch
|
||||
@ -431,7 +420,6 @@ piholeCheckoutFunc() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#shellcheck source=./advanced/Scripts/piholeCheckout.sh
|
||||
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
||||
shift
|
||||
checkout "$@"
|
||||
@ -488,12 +476,11 @@ Debugging Options:
|
||||
Add '-c' or '--check-database' to include a Pi-hole database integrity check
|
||||
Add '-a' to automatically upload the log to tricorder.pi-hole.net
|
||||
-f, flush Flush the Pi-hole log
|
||||
-r, repair Repair Pi-hole subsystems
|
||||
-r, reconfigure Reconfigure or Repair Pi-hole subsystems
|
||||
-t, tail [arg] View the live output of the Pi-hole log.
|
||||
Add an optional argument to filter the log
|
||||
(regular expressions are supported)
|
||||
api <endpoint> Query the Pi-hole API at <endpoint>
|
||||
Precede <endpoint> with 'verbose' option to show authentication and status messages
|
||||
|
||||
|
||||
Options:
|
||||
@ -546,7 +533,7 @@ case "${1}" in
|
||||
"--allow-wild" | "allow-wild" ) need_root=0;;
|
||||
"-f" | "flush" ) ;;
|
||||
"-up" | "updatePihole" ) ;;
|
||||
"-r" | "repair" ) ;;
|
||||
"-r" | "reconfigure" ) ;;
|
||||
"-l" | "logging" ) ;;
|
||||
"uninstall" ) ;;
|
||||
"enable" ) need_root=0;;
|
||||
@ -589,7 +576,7 @@ case "${1}" in
|
||||
"-d" | "debug" ) debugFunc "$@";;
|
||||
"-f" | "flush" ) flushFunc "$@";;
|
||||
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
||||
"-r" | "repair" ) repairPiholeFunc;;
|
||||
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
||||
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
||||
"-l" | "logging" ) piholeLogging "$@";;
|
||||
"uninstall" ) uninstallFunc;;
|
||||
@ -602,6 +589,6 @@ case "${1}" in
|
||||
"updatechecker" ) shift; updateCheckFunc "$@";;
|
||||
"arpflush" ) arpFunc "$@";;
|
||||
"-t" | "tail" ) tailFunc "$2";;
|
||||
"api" ) shift; apiFunc "$@";;
|
||||
"api" ) apiFunc "$2";;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
@ -1,19 +0,0 @@
|
||||
FROM quay.io/centos/centos:stream10
|
||||
# Disable SELinux
|
||||
RUN echo "SELINUX=disabled" > /etc/selinux/config
|
||||
RUN yum install -y --allowerasing curl git initscripts
|
||||
|
||||
ENV GITDIR=/etc/.pihole
|
||||
ENV SCRIPTDIR=/opt/pihole
|
||||
|
||||
RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole
|
||||
ADD . $GITDIR
|
||||
RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/
|
||||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR
|
||||
|
||||
RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
@ -15,5 +15,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -12,5 +12,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -12,5 +12,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -13,5 +13,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -13,5 +13,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -1,17 +0,0 @@
|
||||
FROM fedora:42
|
||||
RUN dnf install -y git initscripts
|
||||
|
||||
ENV GITDIR=/etc/.pihole
|
||||
ENV SCRIPTDIR=/opt/pihole
|
||||
|
||||
RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole
|
||||
ADD . $GITDIR
|
||||
RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/
|
||||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR
|
||||
|
||||
RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
@ -12,5 +12,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -13,5 +13,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -13,5 +13,6 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
@ -1,6 +1,6 @@
|
||||
pyyaml == 6.0.2
|
||||
pytest == 8.3.5
|
||||
pytest == 8.3.4
|
||||
pytest-xdist == 3.6.1
|
||||
pytest-testinfra == 10.2.2
|
||||
tox == 4.26.0
|
||||
pytest-testinfra == 10.1.1
|
||||
tox == 4.24.1
|
||||
pytest-clarity == 1.0.1
|
||||
|
@ -89,10 +89,10 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
umask 0027
|
||||
runUnattended=true
|
||||
fresh_install=false
|
||||
useUpdateVars=true
|
||||
source /opt/pihole/basic-install.sh > /dev/null
|
||||
runUnattended=true
|
||||
fresh_install=false
|
||||
useUpdateVars=true
|
||||
main
|
||||
/opt/pihole/pihole-FTL-prestart.sh
|
||||
"""
|
||||
@ -127,6 +127,10 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||
check_localversion = test_cmd.format("r", "/etc/pihole/versions", piholeuser)
|
||||
actual_rc = host.run(check_localversion).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable logrotate
|
||||
check_logrotate = test_cmd.format("r", "/etc/pihole/logrotate", piholeuser)
|
||||
actual_rc = host.run(check_logrotate).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable macvendor.db
|
||||
check_macvendor = test_cmd.format("r", "/etc/pihole/macvendor.db", piholeuser)
|
||||
actual_rc = host.run(check_macvendor).rc
|
||||
@ -245,7 +249,6 @@ def test_FTL_detect_no_errors(host, arch, detected_string, supported):
|
||||
{
|
||||
"-A /bin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
"-A /usr/bin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
"-A /usr/sbin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
},
|
||||
host,
|
||||
)
|
||||
@ -466,6 +469,50 @@ def test_validate_ip(host):
|
||||
test_address("0.0.0.0#00001", False)
|
||||
|
||||
|
||||
def test_os_check_fails(host):
|
||||
"""Confirms install fails on unsupported OS"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
cat <<EOT > /etc/os-release
|
||||
ID=UnsupportedOS
|
||||
VERSION_ID="2"
|
||||
EOT
|
||||
"""
|
||||
)
|
||||
detectOS = host.run(
|
||||
"""t
|
||||
source /opt/pihole/basic-install.sh
|
||||
os_check
|
||||
"""
|
||||
)
|
||||
expected_stdout = "Unsupported OS detected: UnsupportedOS"
|
||||
assert expected_stdout in detectOS.stdout
|
||||
|
||||
|
||||
def test_os_check_passes(host):
|
||||
"""Confirms OS meets the requirements"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
"""
|
||||
)
|
||||
detectOS = host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
os_check
|
||||
"""
|
||||
)
|
||||
expected_stdout = "Supported OS detected"
|
||||
assert expected_stdout in detectOS.stdout
|
||||
|
||||
|
||||
def test_package_manager_has_pihole_deps(host):
|
||||
"""Confirms OS is able to install the required packages for Pi-hole"""
|
||||
mock_command("dialog", {"*": ("", "0")}, host)
|
||||
|
@ -1,10 +0,0 @@
|
||||
[tox]
|
||||
envlist = py3
|
||||
|
||||
[testenv:py3]
|
||||
allowlist_externals = docker
|
||||
deps = -rrequirements.txt
|
||||
setenv =
|
||||
COLUMNS=120
|
||||
commands = docker buildx build --load --progress plain -f _centos_10.Dockerfile -t pytest_pihole:test_container ../
|
||||
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py
|
@ -1,10 +0,0 @@
|
||||
[tox]
|
||||
envlist = py3
|
||||
|
||||
[testenv]
|
||||
allowlist_externals = docker
|
||||
deps = -rrequirements.txt
|
||||
setenv =
|
||||
COLUMNS=120
|
||||
commands = docker buildx build --load --progress plain -f _fedora_42.Dockerfile -t pytest_pihole:test_container ../
|
||||
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py
|
Loading…
x
Reference in New Issue
Block a user