mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Merge pull request #1313 from pi-hole/new/piholecheckout
Checkout adjustments
This commit is contained in:
commit
2e74219ff9
1 changed files with 85 additions and 46 deletions
|
@ -9,12 +9,17 @@
|
||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||||
PH_TEST="true" source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh
|
PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||||
|
|
||||||
# webInterfaceGitUrl set in basic-install.sh
|
# webInterfaceGitUrl set in basic-install.sh
|
||||||
# webInterfaceDir set in basic-install.sh
|
# webInterfaceDir set in basic-install.sh
|
||||||
# piholeGitURL set in basic-install.sh
|
# piholeGitURL set in basic-install.sh
|
||||||
# is_repo() sourced from basic-install.sh
|
# is_repo() sourced from basic-install.sh
|
||||||
|
# setupVars set in basic-install.sh
|
||||||
|
|
||||||
|
source "${setupVars}"
|
||||||
|
|
||||||
|
update="false"
|
||||||
|
|
||||||
fully_fetch_repo() {
|
fully_fetch_repo() {
|
||||||
# Add upstream branches to shallow clone
|
# Add upstream branches to shallow clone
|
||||||
|
@ -33,28 +38,44 @@ fully_fetch_repo() {
|
||||||
get_available_branches(){
|
get_available_branches(){
|
||||||
# Return available branches
|
# Return available branches
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
local curdir
|
|
||||||
|
|
||||||
curdir="${PWD}"
|
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
# Get reachable remote branches
|
# Get reachable remote branches
|
||||||
git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g'
|
git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g'
|
||||||
cd "${curdir}" || return 1
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fetch_checkout_pull_branch() {
|
||||||
|
# Check out specified branch
|
||||||
|
local directory="${1}"
|
||||||
|
local branch="${2}"
|
||||||
|
|
||||||
|
# Set the reference for the requested branch, fetch, check it put and pull it
|
||||||
|
cd "${directory}"
|
||||||
|
git remote set-branches origin "${branch}" || return 1
|
||||||
|
git fetch --quiet || return 1
|
||||||
|
checkout_pull_branch "${directory}" "${branch}" || return 1
|
||||||
|
}
|
||||||
|
|
||||||
checkout_pull_branch() {
|
checkout_pull_branch() {
|
||||||
# Check out specified branch
|
# Check out specified branch
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
local branch="${2}"
|
local branch="${2}"
|
||||||
local curdir
|
local oldbranch
|
||||||
|
|
||||||
curdir="${PWD}"
|
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
git checkout "${branch}"
|
|
||||||
git pull
|
oldbranch="$(git symbolic-ref HEAD)"
|
||||||
cd "${curdir}" || return 1
|
|
||||||
return
|
git checkout "${branch}" || return 1
|
||||||
|
|
||||||
|
if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then
|
||||||
|
update="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git pull || return 1
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
warning1() {
|
warning1() {
|
||||||
|
@ -82,9 +103,23 @@ checkout()
|
||||||
set -f
|
set -f
|
||||||
|
|
||||||
#This is unlikely
|
#This is unlikely
|
||||||
if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then
|
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||||
echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!"
|
echo "::: Critical Error: Core Pi-Hole repo is missing from system!"
|
||||||
echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole"
|
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
if [[ ${INSTALL_WEB} == "true" ]]; then
|
||||||
|
if ! is_repo "${webInterfaceDir}" ; then
|
||||||
|
echo "::: Critical Error: Web Admin repo is missing from system!"
|
||||||
|
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${1}" ]]; then
|
||||||
|
echo "::: No option detected. Please use 'pihole checkout <master|dev>'."
|
||||||
|
echo "::: Or enter the repository and branch you would like to check out:"
|
||||||
|
echo "::: 'pihole checkout <web|core> <branchname>'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -92,43 +127,36 @@ checkout()
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... "
|
|
||||||
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
|
||||||
echo "::: Fetching all branches for Pi-hole core repo failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
|
||||||
echo " done!"
|
|
||||||
echo "::: ${#corebranches[@]} branches available"
|
|
||||||
echo ":::"
|
|
||||||
|
|
||||||
echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... "
|
|
||||||
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
|
||||||
echo "::: Fetching all branches for Pi-hole web interface repo failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
|
||||||
echo " done!"
|
|
||||||
echo "::: ${#webbranches[@]} branches available"
|
|
||||||
echo ":::"
|
|
||||||
|
|
||||||
if [[ "${1}" == "dev" ]] ; then
|
if [[ "${1}" == "dev" ]] ; then
|
||||||
# Shortcut to check out development branches
|
# Shortcut to check out development branches
|
||||||
echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..."
|
echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..."
|
||||||
echo "::: Pi-hole core"
|
echo "::: Pi-hole core"
|
||||||
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development"
|
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; }
|
||||||
echo "::: Web interface"
|
if [[ ${INSTALL_WEB} == "true" ]]; then
|
||||||
checkout_pull_branch "${webInterfaceDir}" "devel"
|
echo "::: Web interface"
|
||||||
|
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; }
|
||||||
|
fi
|
||||||
echo "::: done!"
|
echo "::: done!"
|
||||||
elif [[ "${1}" == "master" ]] ; then
|
elif [[ "${1}" == "master" ]] ; then
|
||||||
# Shortcut to check out master branches
|
# Shortcut to check out master branches
|
||||||
echo "::: Shortcut \"master\" detected - checking out master branches ..."
|
echo "::: Shortcut \"master\" detected - checking out master branches ..."
|
||||||
echo "::: Pi-hole core"
|
echo "::: Pi-hole core"
|
||||||
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master"
|
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; }
|
||||||
echo "::: Web interface"
|
if [[ ${INSTALL_WEB} == "true" ]]; then
|
||||||
checkout_pull_branch "${webInterfaceDir}" "master"
|
echo "::: Web interface"
|
||||||
|
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; }
|
||||||
|
fi
|
||||||
echo "::: done!"
|
echo "::: done!"
|
||||||
elif [[ "${1}" == "core" ]] ; then
|
elif [[ "${1}" == "core" ]] ; then
|
||||||
|
echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... "
|
||||||
|
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||||
|
echo "::: Fetching all branches for Pi-hole core repo failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
||||||
|
echo " done!"
|
||||||
|
echo "::: ${#corebranches[@]} branches available"
|
||||||
|
echo ":::"
|
||||||
# Have to user chosing the branch he wants
|
# Have to user chosing the branch he wants
|
||||||
if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
||||||
echo "::: Requested branch \"${2}\" is not available!"
|
echo "::: Requested branch \"${2}\" is not available!"
|
||||||
|
@ -137,7 +165,16 @@ checkout()
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}"
|
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}"
|
||||||
elif [[ "${1}" == "web" ]] ; then
|
elif [[ "${1}" == "web" && "${INSTALL_WEB}" == "true" ]] ; then
|
||||||
|
echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... "
|
||||||
|
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
||||||
|
echo "::: Fetching all branches for Pi-hole web interface repo failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
||||||
|
echo " done!"
|
||||||
|
echo "::: ${#webbranches[@]} branches available"
|
||||||
|
echo ":::"
|
||||||
# Have to user chosing the branch he wants
|
# Have to user chosing the branch he wants
|
||||||
if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
|
||||||
echo "::: Requested branch \"${2}\" is not available!"
|
echo "::: Requested branch \"${2}\" is not available!"
|
||||||
|
@ -152,12 +189,14 @@ checkout()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Force updating everything
|
# Force updating everything
|
||||||
echo "::: Running installer to upgrade your installation"
|
if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then
|
||||||
if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then
|
echo "::: Running installer to upgrade your installation"
|
||||||
exit 0
|
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then
|
||||||
else
|
exit 0
|
||||||
echo "Unable to complete update, contact Pi-hole"
|
else
|
||||||
exit 1
|
echo "Unable to complete update, contact Pi-hole"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue