mirror of
https://github.com/pi-hole/pi-hole
synced 2025-02-10 23:22:38 +00:00
Allow to checkout tags
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
parent
53d09417dd
commit
2e0746707d
@ -18,15 +18,11 @@ source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
|||||||
# is_repo() sourced from basic-install.sh
|
# is_repo() sourced from basic-install.sh
|
||||||
# setupVars set in basic-install.sh
|
# setupVars set in basic-install.sh
|
||||||
# check_download_exists sourced from basic-install.sh
|
# check_download_exists sourced from basic-install.sh
|
||||||
# fully_fetch_repo sourced from basic-install.sh
|
|
||||||
# get_available_branches sourced from basic-install.sh
|
|
||||||
# fetch_checkout_pull_branch sourced from basic-install.sh
|
|
||||||
# checkout_pull_branch sourced from basic-install.sh
|
|
||||||
|
|
||||||
source "${setupVars}"
|
source "${setupVars}"
|
||||||
|
|
||||||
warning1() {
|
warning1() {
|
||||||
echo " Please note that changing branches severely alters your Pi-hole subsystems"
|
echo " Please note that changing branches or tags severely alters your Pi-hole subsystems"
|
||||||
echo " Features that work on the master branch, may not on a development branch"
|
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}"
|
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
|
read -r -p " Have you read and understood this? [y/N] " response
|
||||||
@ -36,15 +32,15 @@ warning1() {
|
|||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "\\n ${INFO} Branch change has been canceled"
|
echo -e "\\n ${INFO} Branch/Tag change has been canceled"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
checkout() {
|
checkout() {
|
||||||
local corebranches
|
local corerefs
|
||||||
local webbranches
|
local webrefs
|
||||||
|
|
||||||
# Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole
|
# Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole
|
||||||
local funcOutput
|
local funcOutput
|
||||||
@ -111,59 +107,59 @@ checkout() {
|
|||||||
echo "master" > /etc/pihole/ftlbranch
|
echo "master" > /etc/pihole/ftlbranch
|
||||||
chmod 644 /etc/pihole/ftlbranch
|
chmod 644 /etc/pihole/ftlbranch
|
||||||
elif [[ "${1}" == "core" ]] ; then
|
elif [[ "${1}" == "core" ]] ; then
|
||||||
str="Fetching branches from ${piholeGitUrl}"
|
str="Fetching branches/tags from ${piholeGitUrl}"
|
||||||
echo -ne " ${INFO} $str"
|
echo -ne " ${INFO} $str"
|
||||||
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||||
echo -e "${OVER} ${CROSS} $str"
|
echo -e "${OVER} ${CROSS} $str"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
corerefs=("$(get_available_refs "${PI_HOLE_FILES_DIR}")")
|
||||||
|
|
||||||
if [[ "${corebranches[*]}" == *"master"* ]]; then
|
if [[ "${corerefs[*]}" == *"master"* ]]; then
|
||||||
echo -e "${OVER} ${TICK} $str"
|
echo -e "${OVER} ${TICK} $str"
|
||||||
echo -e " ${INFO} ${#corebranches[@]} branches available for Pi-hole Core"
|
echo -e " ${INFO} ${#corerefs[@]} branches/tags available for Pi-hole Core"
|
||||||
else
|
else
|
||||||
# Print STDERR output from get_available_branches
|
# Print STDERR output from get_available_refs
|
||||||
echo -e "${OVER} ${CROSS} $str\\n\\n${corebranches[*]}"
|
echo -e "${OVER} ${CROSS} $str\\n\\n${corerefs[*]}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
# Have the user choose the branch they want
|
# Have the user choose the branch/tag they want
|
||||||
if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
if ! (for e in "${corerefs[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
||||||
echo -e " ${INFO} Requested branch \"${2}\" is not available"
|
echo -e " ${INFO} Requested branch/tag \"${2}\" is not available"
|
||||||
echo -e " ${INFO} Available branches for Core are:"
|
echo -e " ${INFO} Available branches/tags for Core are:"
|
||||||
for e in "${corebranches[@]}"; do echo " - $e"; done
|
for e in "${corerefs[@]}"; do echo " - $e"; done
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}"
|
checkout_pull_ref "${PI_HOLE_FILES_DIR}" "${2}"
|
||||||
elif [[ "${1}" == "web" ]] && [[ "${INSTALL_WEB_INTERFACE}" == "true" ]] ; then
|
elif [[ "${1}" == "web" ]] && [[ "${INSTALL_WEB_INTERFACE}" == "true" ]] ; then
|
||||||
str="Fetching branches from ${webInterfaceGitUrl}"
|
str="Fetching branches/tags from ${webInterfaceGitUrl}"
|
||||||
echo -ne " ${INFO} $str"
|
echo -ne " ${INFO} $str"
|
||||||
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
||||||
echo -e "${OVER} ${CROSS} $str"
|
echo -e "${OVER} ${CROSS} $str"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
webrefs=("$(get_available_refs "${webInterfaceDir}")")
|
||||||
|
|
||||||
if [[ "${webbranches[*]}" == *"master"* ]]; then
|
if [[ "${webrefs[*]}" == *"master"* ]]; then
|
||||||
echo -e "${OVER} ${TICK} $str"
|
echo -e "${OVER} ${TICK} $str"
|
||||||
echo -e " ${INFO} ${#webbranches[@]} branches available for Web Admin"
|
echo -e " ${INFO} ${#webrefs[@]} branches/tags available for Web Admin"
|
||||||
else
|
else
|
||||||
# Print STDERR output from get_available_branches
|
# Print STDERR output from get_available_refs
|
||||||
echo -e "${OVER} ${CROSS} $str\\n\\n${webbranches[*]}"
|
echo -e "${OVER} ${CROSS} $str\\n\\n${webrefs[*]}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
# Have the user choose the branch they want
|
# Have the user choose the branch/tags they want
|
||||||
if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
if ! (for e in "${webrefs[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
||||||
echo -e " ${INFO} Requested branch \"${2}\" is not available"
|
echo -e " ${INFO} Requested branch/tag \"${2}\" is not available"
|
||||||
echo -e " ${INFO} Available branches for Web Admin are:"
|
echo -e " ${INFO} Available branches/tags for Web Admin are:"
|
||||||
for e in "${webbranches[@]}"; do echo " - $e"; done
|
for e in "${webrefs[@]}"; do echo " - $e"; done
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
checkout_pull_branch "${webInterfaceDir}" "${2}"
|
checkout_pull_ref "${webInterfaceDir}" "${2}"
|
||||||
# Update local and remote versions via updatechecker
|
# Update local and remote versions via updatechecker
|
||||||
/opt/pihole/updatecheck.sh
|
/opt/pihole/updatecheck.sh
|
||||||
elif [[ "${1}" == "ftl" ]] ; then
|
elif [[ "${1}" == "ftl" ]] ; then
|
||||||
@ -184,7 +180,7 @@ checkout() {
|
|||||||
/opt/pihole/updatecheck.sh
|
/opt/pihole/updatecheck.sh
|
||||||
else
|
else
|
||||||
echo " ${CROSS} Requested branch \"${2}\" is not available"
|
echo " ${CROSS} Requested branch \"${2}\" is not available"
|
||||||
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') )
|
ftlbranches=("$(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}')")
|
||||||
echo -e " ${INFO} Available branches for FTL are:"
|
echo -e " ${INFO} Available branches for FTL are:"
|
||||||
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -36,15 +36,17 @@ source "/opt/pihole/COL_TABLE"
|
|||||||
GitCheckUpdateAvail() {
|
GitCheckUpdateAvail() {
|
||||||
local directory
|
local directory
|
||||||
local curBranch
|
local curBranch
|
||||||
|
local ref_is_tag
|
||||||
directory="${1}"
|
directory="${1}"
|
||||||
curdir=$PWD
|
curdir=$PWD
|
||||||
cd "${directory}" || return
|
cd "${directory}" || return
|
||||||
|
|
||||||
# Fetch latest changes in this repo
|
# Fetch latest changes in this repo
|
||||||
git fetch --quiet origin
|
git fetch --tags --quiet origin
|
||||||
|
|
||||||
# Check current branch. If it is master, then check for the latest available tag instead of latest commit.
|
# Check current branch. If it is master, then check for the latest available tag instead of latest commit.
|
||||||
curBranch=$(git rev-parse --abbrev-ref HEAD)
|
# Remove any leading "heads/" as $curBranch is later used to check if local branch is remote branch or tag
|
||||||
|
curBranch=$(git rev-parse --abbrev-ref HEAD| sed "s/^heads\///g")
|
||||||
if [[ "${curBranch}" == "master" ]]; then
|
if [[ "${curBranch}" == "master" ]]; then
|
||||||
# get the latest local tag
|
# get the latest local tag
|
||||||
LOCAL=$(git describe --abbrev=0 --tags master)
|
LOCAL=$(git describe --abbrev=0 --tags master)
|
||||||
@ -56,6 +58,17 @@ GitCheckUpdateAvail() {
|
|||||||
# need @{0}
|
# need @{0}
|
||||||
LOCAL="$(git rev-parse "@{0}")"
|
LOCAL="$(git rev-parse "@{0}")"
|
||||||
|
|
||||||
|
# check if the local branch ef is a branch or a tag on remote repo
|
||||||
|
if git show-ref -q --verify "refs/remotes/origin/$curBranch" 2>/dev/null; then
|
||||||
|
ref_is_tag=false
|
||||||
|
elif git show-ref -q --verify "refs/tags/$curBranch" 2>/dev/null; then
|
||||||
|
ref_is_tag=true
|
||||||
|
fi
|
||||||
|
if [ "$ref_is_tag" = true ]; then
|
||||||
|
# as there is no tracking upstream branch for a checked out tag, there is need to
|
||||||
|
# check for updates
|
||||||
|
REMOTE="${LOCAL}"
|
||||||
|
else
|
||||||
# The suffix @{upstream} to a branchname
|
# The suffix @{upstream} to a branchname
|
||||||
# (short form <branchname>@{u}) refers
|
# (short form <branchname>@{u}) refers
|
||||||
# to the branch that the branch specified
|
# to the branch that the branch specified
|
||||||
@ -65,6 +78,7 @@ GitCheckUpdateAvail() {
|
|||||||
# defaults to the current one.
|
# defaults to the current one.
|
||||||
REMOTE="$(git rev-parse "@{upstream}")"
|
REMOTE="$(git rev-parse "@{upstream}")"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ "${#LOCAL}" == 0 ]]; then
|
if [[ "${#LOCAL}" == 0 ]]; then
|
||||||
|
@ -460,6 +460,7 @@ update_repo() {
|
|||||||
# This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one
|
# This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
local curBranch
|
local curBranch
|
||||||
|
local ref_is_branch
|
||||||
|
|
||||||
# A variable to store the message we want to display;
|
# A variable to store the message we want to display;
|
||||||
# Again, it's useful to store these in variables in case we need to reuse or change the message;
|
# Again, it's useful to store these in variables in case we need to reuse or change the message;
|
||||||
@ -472,11 +473,26 @@ update_repo() {
|
|||||||
# Stash any local commits as they conflict with our working code
|
# Stash any local commits as they conflict with our working code
|
||||||
git stash --all --quiet &> /dev/null || true # Okay for stash failure
|
git stash --all --quiet &> /dev/null || true # Okay for stash failure
|
||||||
git clean --quiet --force -d || true # Okay for already clean directory
|
git clean --quiet --force -d || true # Okay for already clean directory
|
||||||
|
|
||||||
|
# Check current branch.
|
||||||
|
# Remove any leading "heads/" as $curBranch is later used to check if local branch is remote branch or tag
|
||||||
|
curBranch=$(git rev-parse --abbrev-ref HEAD| sed "s/^heads\///g")
|
||||||
|
|
||||||
|
# check if the local branch ef is a branch or a tag on remote repo
|
||||||
|
if git show-ref -q --verify "refs/remotes/origin/$curBranch" 2>/dev/null; then
|
||||||
|
ref_is_branch=true
|
||||||
|
elif git show-ref -q --verify "refs/tags/$curBranch" 2>/dev/null; then
|
||||||
|
ref_is_branch=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
# only pull if we are on a branch not a tag
|
||||||
|
if [ "$ref_is_branch" = true ]; then
|
||||||
# Pull the latest commits
|
# Pull the latest commits
|
||||||
git pull --no-rebase --quiet &> /dev/null || return $?
|
git pull --no-rebase --quiet &> /dev/null || return $?
|
||||||
# Check current branch. If it is master, then reset to the latest available tag.
|
fi
|
||||||
|
|
||||||
|
# If the current branch is master, then reset to the latest available tag.
|
||||||
# In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks)
|
# In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks)
|
||||||
curBranch=$(git rev-parse --abbrev-ref HEAD)
|
|
||||||
if [[ "${curBranch}" == "master" ]]; then
|
if [[ "${curBranch}" == "master" ]]; then
|
||||||
git reset --hard "$(git describe --abbrev=0 --tags)" || return $?
|
git reset --hard "$(git describe --abbrev=0 --tags)" || return $?
|
||||||
fi
|
fi
|
||||||
@ -2099,28 +2115,28 @@ check_download_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fully_fetch_repo() {
|
fully_fetch_repo() {
|
||||||
# Add upstream branches to shallow clone
|
# Add upstream branches/tags to shallow clone
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
|
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
if is_repo "${directory}"; then
|
if is_repo "${directory}"; then
|
||||||
git remote set-branches origin '*' || return 1
|
git remote set-branches origin '*' || return 1
|
||||||
git fetch --quiet || return 1
|
git fetch --tags --quiet || return 1
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_available_branches() {
|
get_available_refs() {
|
||||||
# Return available branches
|
# Return available branches and tags
|
||||||
local directory
|
local directory
|
||||||
directory="${1}"
|
directory="${1}"
|
||||||
local output
|
local output
|
||||||
|
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
# Get reachable remote branches, but store STDERR as STDOUT variable
|
# Get reachable remote branches and tags, but store STDERR as STDOUT variable
|
||||||
output=$( { git ls-remote --heads --quiet | cut -d'/' -f3- -; } 2>&1 )
|
output=$( { git ls-remote --heads --tags --quiet | cut -d'/' -f3- -; } 2>&1 )
|
||||||
# echo status for calling function to capture
|
# echo status for calling function to capture
|
||||||
echo "$output"
|
echo "$output"
|
||||||
return
|
return
|
||||||
@ -2139,35 +2155,52 @@ fetch_checkout_pull_branch() {
|
|||||||
git stash --all --quiet &> /dev/null || true
|
git stash --all --quiet &> /dev/null || true
|
||||||
git clean --quiet --force -d || true
|
git clean --quiet --force -d || true
|
||||||
git fetch --quiet || return 1
|
git fetch --quiet || return 1
|
||||||
checkout_pull_branch "${directory}" "${branch}" || return 1
|
checkout_pull_ref "${directory}" "${branch}" || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
checkout_pull_branch() {
|
checkout_pull_ref() {
|
||||||
# Check out specified branch
|
# Check out specified branch/tag
|
||||||
local directory
|
local directory
|
||||||
directory="${1}"
|
directory="${1}"
|
||||||
local branch
|
local ref
|
||||||
branch="${2}"
|
ref="${2}"
|
||||||
local oldbranch
|
local oldref
|
||||||
|
local ref_is_tag
|
||||||
|
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
|
|
||||||
oldbranch="$(git symbolic-ref HEAD)"
|
# Get current branch name.
|
||||||
|
oldref="$(git symbolic-ref --quiet HEAD)"
|
||||||
|
|
||||||
str="Switching to branch: '${branch}' from '${oldbranch}'"
|
str="Switching to branch/tag: '${ref}' from '${oldref}'"
|
||||||
printf " %b %s" "${INFO}" "$str"
|
printf " %b %s" "${INFO}" "$str"
|
||||||
git checkout "${branch}" --quiet || return 1
|
|
||||||
|
# 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"
|
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)
|
# 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}"
|
chmod -R a+rX "${directory}"
|
||||||
|
|
||||||
git_pull=$(git pull --no-rebase || return 1)
|
|
||||||
|
|
||||||
printf " %b %s\\n" "${INFO}" "${git_pull}"
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
clone_or_update_repos() {
|
clone_or_update_repos() {
|
||||||
# If the user wants to reconfigure,
|
# If the user wants to reconfigure,
|
||||||
if [[ "${reconfigure}" == true ]]; then
|
if [[ "${reconfigure}" == true ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user