2017-03-08 12:16:40 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2020-05-13 10:49:00 +00:00
|
|
|
# Switch Pi-hole subsystems to a different GitHub branch.
|
2017-03-08 12:16:40 +00:00
|
|
|
#
|
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
2017-03-08 21:27:48 +00:00
|
|
|
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
2022-07-06 20:58:14 +00:00
|
|
|
SKIP_INSTALL="true"
|
2017-06-21 11:49:05 +00:00
|
|
|
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
2017-03-08 21:27:48 +00:00
|
|
|
|
2017-03-08 21:41:11 +00:00
|
|
|
# webInterfaceGitUrl set in basic-install.sh
|
|
|
|
# webInterfaceDir set in basic-install.sh
|
|
|
|
# piholeGitURL set in basic-install.sh
|
2017-03-08 21:27:48 +00:00
|
|
|
# is_repo() sourced from basic-install.sh
|
2017-03-11 15:46:52 +00:00
|
|
|
# setupVars set in basic-install.sh
|
2018-05-01 20:59:12 +00:00
|
|
|
# check_download_exists sourced from basic-install.sh
|
2017-03-11 15:46:52 +00:00
|
|
|
|
|
|
|
source "${setupVars}"
|
2017-03-11 15:24:13 +00:00
|
|
|
|
2017-03-08 12:16:40 +00:00
|
|
|
warning1() {
|
2023-04-20 21:25:04 +00:00
|
|
|
echo " Please note that changing branches or tags severely alters your Pi-hole subsystems"
|
2018-07-20 19:54:24 +00:00
|
|
|
echo " Features that work on the master branch, may not on a development branch"
|
|
|
|
echo -e " ${COL_LIGHT_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}"
|
|
|
|
read -r -p " Have you read and understood this? [y/N] " response
|
|
|
|
case "${response}" in
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
echo ""
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
2023-04-20 21:25:04 +00:00
|
|
|
echo -e "\\n ${INFO} Branch/Tag change has been canceled"
|
2018-07-20 19:54:24 +00:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
2017-03-08 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 12:11:06 +00:00
|
|
|
fully_fetch_repo() {
|
|
|
|
# Add upstream branches/tags to shallow clone
|
|
|
|
local directory="${1}"
|
|
|
|
|
|
|
|
cd "${directory}" || return 1
|
|
|
|
if is_repo "${directory}"; then
|
|
|
|
git remote set-branches origin '*' || return 1
|
|
|
|
git fetch --tags --quiet || return 1
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
get_available_refs() {
|
|
|
|
# Return available branches and tags
|
|
|
|
local directory
|
|
|
|
directory="${1}"
|
|
|
|
local output
|
|
|
|
|
|
|
|
cd "${directory}" || return 1
|
|
|
|
# Get reachable remote branches and tags, but store STDERR as STDOUT variable
|
|
|
|
output=$( { git ls-remote --heads --tags --quiet | cut -d'/' -f3- -; } 2>&1 )
|
|
|
|
# echo status for calling function to capture
|
|
|
|
echo "$output"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_checkout_pull_branch() {
|
|
|
|
# Check out specified branch
|
|
|
|
local directory
|
|
|
|
directory="${1}"
|
|
|
|
local branch
|
|
|
|
branch="${2}"
|
|
|
|
|
|
|
|
# Set the reference for the requested branch, fetch, check it put and pull it
|
|
|
|
cd "${directory}" || return 1
|
|
|
|
git remote set-branches origin "${branch}" || return 1
|
|
|
|
git stash --all --quiet &> /dev/null || true
|
|
|
|
git clean --quiet --force -d || true
|
|
|
|
git fetch --quiet || return 1
|
|
|
|
checkout_pull_ref "${directory}" "${branch}" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
checkout_pull_ref() {
|
|
|
|
# Check out specified branch/tag
|
|
|
|
local directory
|
|
|
|
directory="${1}"
|
|
|
|
local ref
|
|
|
|
ref="${2}"
|
|
|
|
local oldref
|
|
|
|
local ref_is_tag
|
|
|
|
|
|
|
|
cd "${directory}" || return 1
|
|
|
|
|
|
|
|
# Get current branch name.
|
|
|
|
oldref="$(git symbolic-ref --quiet HEAD)"
|
|
|
|
|
|
|
|
str="Switching to branch/tag: '${ref}' from '${oldref}'"
|
|
|
|
printf " %b %s" "${INFO}" "$str"
|
|
|
|
|
|
|
|
# check if the ref is a branch or a tag on the remote repo
|
|
|
|
if git show-ref -q --verify "refs/remotes/origin/$ref" 2>/dev/null; then
|
|
|
|
ref_is_tag=false
|
|
|
|
elif git show-ref -q --verify "refs/tags/$ref" 2>/dev/null; then
|
|
|
|
ref_is_tag=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ref_is_tag" = true ]; then
|
|
|
|
# in case we want to checkout a tag we need explicitly create a new branch/reset the existing one
|
|
|
|
git checkout -B "${ref}" "refs/tags/${ref}" --quiet || return 1
|
|
|
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
|
|
|
else
|
|
|
|
# checkout a branch, this also sets tracking branch
|
|
|
|
git checkout "${ref}" --quiet || return 1
|
|
|
|
printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str"
|
|
|
|
git_pull=$(git pull --no-rebase || return 1)
|
|
|
|
printf " %b %s\\n" "${INFO}" "${git_pull}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
|
|
|
|
chmod -R a+rX "${directory}"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
checkout() {
|
2023-04-20 21:25:04 +00:00
|
|
|
local corerefs
|
|
|
|
local webrefs
|
2018-07-20 19:54:24 +00:00
|
|
|
|
2019-11-14 18:52:07 +00:00
|
|
|
# Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole
|
|
|
|
local funcOutput
|
|
|
|
funcOutput=$(get_binary_name) #Store output of get_binary_name here
|
|
|
|
local binary
|
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}" #binary name will be the last line of the output of get_binary_name (it always begins with pihole-FTL)
|
|
|
|
|
2018-07-20 19:54:24 +00:00
|
|
|
# Avoid globbing
|
|
|
|
set -f
|
|
|
|
|
|
|
|
# This is unlikely
|
|
|
|
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
|
|
|
echo -e " ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!"
|
|
|
|
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
|
|
|
exit 1;
|
2017-03-11 15:30:58 +00:00
|
|
|
fi
|
2018-04-28 13:17:29 +00:00
|
|
|
if [[ "${INSTALL_WEB_INTERFACE}" == "true" ]]; then
|
2018-07-20 19:54:24 +00:00
|
|
|
if ! is_repo "${webInterfaceDir}" ; then
|
|
|
|
echo -e " ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!"
|
|
|
|
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
|
|
|
exit 1;
|
|
|
|
fi
|
2017-03-10 19:25:35 +00:00
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2018-07-20 19:54:24 +00:00
|
|
|
if [[ -z "${1}" ]]; then
|
|
|
|
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}"
|
|
|
|
echo -e " Try 'pihole checkout --help' for more information."
|
|
|
|
exit 1
|
2017-06-21 11:49:05 +00:00
|
|
|
fi
|
|
|
|
|
2018-07-20 19:54:24 +00:00
|
|
|
if ! warning1 ; then
|
|
|
|
exit 1
|
2017-03-10 19:25:35 +00:00
|
|
|
fi
|
2017-06-27 12:28:05 +00:00
|
|
|
|
2018-07-20 19:54:24 +00:00
|
|
|
if [[ "${1}" == "dev" ]] ; then
|
|
|
|
# Shortcut to check out development branches
|
|
|
|
echo -e " ${INFO} Shortcut \"dev\" detected - checking out development / devel branches..."
|
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Pi-hole Core"
|
2020-03-08 23:53:14 +00:00
|
|
|
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo " ${CROSS} Unable to pull Core development branch"; exit 1; }
|
2018-07-20 19:54:24 +00:00
|
|
|
if [[ "${INSTALL_WEB_INTERFACE}" == "true" ]]; then
|
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Web interface"
|
|
|
|
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; }
|
|
|
|
fi
|
|
|
|
#echo -e " ${TICK} Pi-hole Core"
|
|
|
|
|
|
|
|
local path
|
|
|
|
path="development/${binary}"
|
|
|
|
echo "development" > /etc/pihole/ftlbranch
|
2019-05-01 09:20:26 +00:00
|
|
|
chmod 644 /etc/pihole/ftlbranch
|
2018-07-20 19:54:24 +00:00
|
|
|
elif [[ "${1}" == "master" ]] ; then
|
|
|
|
# Shortcut to check out master branches
|
|
|
|
echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..."
|
|
|
|
echo -e " ${INFO} Pi-hole core"
|
|
|
|
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo " ${CROSS} Unable to pull Core master branch"; exit 1; }
|
|
|
|
if [[ ${INSTALL_WEB_INTERFACE} == "true" ]]; then
|
|
|
|
echo -e " ${INFO} Web interface"
|
|
|
|
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; }
|
|
|
|
fi
|
|
|
|
#echo -e " ${TICK} Web Interface"
|
|
|
|
local path
|
|
|
|
path="master/${binary}"
|
|
|
|
echo "master" > /etc/pihole/ftlbranch
|
2019-05-01 09:20:26 +00:00
|
|
|
chmod 644 /etc/pihole/ftlbranch
|
2018-07-20 19:54:24 +00:00
|
|
|
elif [[ "${1}" == "core" ]] ; then
|
2023-04-20 21:25:04 +00:00
|
|
|
str="Fetching branches/tags from ${piholeGitUrl}"
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -ne " ${INFO} $str"
|
|
|
|
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
|
|
|
echo -e "${OVER} ${CROSS} $str"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-20 21:25:04 +00:00
|
|
|
corerefs=("$(get_available_refs "${PI_HOLE_FILES_DIR}")")
|
2018-07-20 19:54:24 +00:00
|
|
|
|
2023-04-20 21:25:04 +00:00
|
|
|
if [[ "${corerefs[*]}" == *"master"* ]]; then
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -e "${OVER} ${TICK} $str"
|
2023-04-20 21:25:04 +00:00
|
|
|
echo -e " ${INFO} ${#corerefs[@]} branches/tags available for Pi-hole Core"
|
2018-07-20 19:54:24 +00:00
|
|
|
else
|
2023-04-20 21:25:04 +00:00
|
|
|
# Print STDERR output from get_available_refs
|
|
|
|
echo -e "${OVER} ${CROSS} $str\\n\\n${corerefs[*]}"
|
2018-07-20 19:54:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
2023-04-20 21:25:04 +00:00
|
|
|
# Have the user choose the branch/tag they want
|
|
|
|
if ! (for e in "${corerefs[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
|
|
|
echo -e " ${INFO} Requested branch/tag \"${2}\" is not available"
|
|
|
|
echo -e " ${INFO} Available branches/tags for Core are:"
|
|
|
|
for e in "${corerefs[@]}"; do echo " - $e"; done
|
2018-07-20 19:54:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-20 21:25:04 +00:00
|
|
|
checkout_pull_ref "${PI_HOLE_FILES_DIR}" "${2}"
|
2018-07-20 19:54:24 +00:00
|
|
|
elif [[ "${1}" == "web" ]] && [[ "${INSTALL_WEB_INTERFACE}" == "true" ]] ; then
|
2023-04-20 21:25:04 +00:00
|
|
|
str="Fetching branches/tags from ${webInterfaceGitUrl}"
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -ne " ${INFO} $str"
|
|
|
|
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
|
|
|
echo -e "${OVER} ${CROSS} $str"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-20 21:25:04 +00:00
|
|
|
webrefs=("$(get_available_refs "${webInterfaceDir}")")
|
2018-07-20 19:54:24 +00:00
|
|
|
|
2023-04-20 21:25:04 +00:00
|
|
|
if [[ "${webrefs[*]}" == *"master"* ]]; then
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -e "${OVER} ${TICK} $str"
|
2023-04-20 21:25:04 +00:00
|
|
|
echo -e " ${INFO} ${#webrefs[@]} branches/tags available for Web Admin"
|
2018-07-20 19:54:24 +00:00
|
|
|
else
|
2023-04-20 21:25:04 +00:00
|
|
|
# Print STDERR output from get_available_refs
|
|
|
|
echo -e "${OVER} ${CROSS} $str\\n\\n${webrefs[*]}"
|
2018-07-20 19:54:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
2023-04-20 21:25:04 +00:00
|
|
|
# Have the user choose the branch/tags they want
|
|
|
|
if ! (for e in "${webrefs[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
|
|
|
echo -e " ${INFO} Requested branch/tag \"${2}\" is not available"
|
|
|
|
echo -e " ${INFO} Available branches/tags for Web Admin are:"
|
|
|
|
for e in "${webrefs[@]}"; do echo " - $e"; done
|
2018-07-20 19:54:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-20 21:25:04 +00:00
|
|
|
checkout_pull_ref "${webInterfaceDir}" "${2}"
|
2022-10-06 10:36:17 +00:00
|
|
|
# Update local and remote versions via updatechecker
|
|
|
|
/opt/pihole/updatecheck.sh
|
2018-07-20 19:54:24 +00:00
|
|
|
elif [[ "${1}" == "ftl" ]] ; then
|
|
|
|
local path
|
2021-08-07 18:07:45 +00:00
|
|
|
local oldbranch
|
2018-07-20 19:54:24 +00:00
|
|
|
path="${2}/${binary}"
|
2021-08-07 18:07:45 +00:00
|
|
|
oldbranch="$(pihole-FTL -b)"
|
2018-07-20 19:54:24 +00:00
|
|
|
|
|
|
|
if check_download_exists "$path"; then
|
|
|
|
echo " ${TICK} Branch ${2} exists"
|
|
|
|
echo "${2}" > /etc/pihole/ftlbranch
|
2019-05-01 09:20:26 +00:00
|
|
|
chmod 644 /etc/pihole/ftlbranch
|
2021-08-07 18:07:45 +00:00
|
|
|
echo -e " ${INFO} Switching to branch: \"${2}\" from \"${oldbranch}\""
|
2018-07-20 19:54:24 +00:00
|
|
|
FTLinstall "${binary}"
|
2019-02-02 18:19:44 +00:00
|
|
|
restart_service pihole-FTL
|
2018-07-20 19:54:24 +00:00
|
|
|
enable_service pihole-FTL
|
2022-10-06 10:36:17 +00:00
|
|
|
# Update local and remote versions via updatechecker
|
|
|
|
/opt/pihole/updatecheck.sh
|
2018-07-20 19:54:24 +00:00
|
|
|
else
|
|
|
|
echo " ${CROSS} Requested branch \"${2}\" is not available"
|
2023-04-20 21:25:04 +00:00
|
|
|
ftlbranches=("$(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}')")
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -e " ${INFO} Available branches for FTL are:"
|
|
|
|
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2017-06-27 12:28:05 +00:00
|
|
|
else
|
2018-07-20 19:54:24 +00:00
|
|
|
echo -e " ${INFO} Requested option \"${1}\" is not available"
|
2017-07-16 12:54:23 +00:00
|
|
|
exit 1
|
2017-06-27 12:28:05 +00:00
|
|
|
fi
|
|
|
|
|
2018-07-20 19:54:24 +00:00
|
|
|
# Force updating everything
|
|
|
|
if [[ ! "${1}" == "web" && ! "${1}" == "ftl" ]]; then
|
|
|
|
echo -e " ${INFO} Running installer to upgrade your installation"
|
|
|
|
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo -e " ${COL_LIGHT_RED} Error: Unable to complete update, please contact support${COL_NC}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-03-10 19:25:35 +00:00
|
|
|
fi
|
2017-03-08 12:16:40 +00:00
|
|
|
}
|