From 0a0d25dff49dcb1815e8b1868d57a9210caa469f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 10:57:46 -0800 Subject: [PATCH 01/16] Script runs in subshell, no need to cd back to pwd. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 86ea9a2b..0da8dd02 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -33,13 +33,10 @@ fully_fetch_repo() { get_available_branches(){ # Return available branches local directory="${1}" - local curdir - curdir="${PWD}" cd "${directory}" || return 1 # Get reachable remote branches git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' - cd "${curdir}" || return 1 return } @@ -47,14 +44,11 @@ checkout_pull_branch() { # Check out specified branch local directory="${1}" local branch="${2}" - local curdir - curdir="${PWD}" cd "${directory}" || return 1 - git checkout "${branch}" - git pull - cd "${curdir}" || return 1 - return + git checkout "${branch}" || return 1 + git pull || return 1 + return 0 } warning1() { From 20fd61468df87d84d42e5260c0d794bc2285857c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:04:37 -0800 Subject: [PATCH 02/16] Require branch to check out Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 0da8dd02..08684bb9 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -82,6 +82,13 @@ checkout() exit 1 fi + if [[ -z "${1}" ]]; then + echo "::: No option detected. Please use 'pihole checkout '." + echo "::: Or enter the repository and branch you would like to check out:" + echo "::: 'pihole checkout '" + exit 1 + fi + if ! warning1 ; then exit 1 fi From d5b88e0df8144b71245fb5ea8345c7a1fefa3710 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:07:58 -0800 Subject: [PATCH 03/16] Get the right name for the options. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 08684bb9..b97d9680 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -83,7 +83,7 @@ checkout() fi if [[ -z "${1}" ]]; then - echo "::: No option detected. Please use 'pihole checkout '." + echo "::: No option detected. Please use 'pihole checkout '." echo "::: Or enter the repository and branch you would like to check out:" echo "::: 'pihole checkout '" exit 1 From 41e1e4cb683ea2b742fb38b50376ac75b535b9d4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:25:35 -0800 Subject: [PATCH 04/16] Rearrange pull logic, some optimization. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index b97d9680..437dbc39 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -93,43 +93,32 @@ checkout() exit 1 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 # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" + checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" + checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } echo "::: done!" 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 if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -139,6 +128,15 @@ checkout() fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" elif [[ "${1}" == "web" ]] ; 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 if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -153,12 +151,14 @@ checkout() fi # Force updating everything - echo "::: Running installer to upgrade your installation" - if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then - exit 0 - else - echo "Unable to complete update, contact Pi-hole" - exit 1 + if [[ ! "${1}" == "web" ]]; then + echo "::: Running installer to upgrade your installation" + if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + exit 0 + else + echo "Unable to complete update, contact Pi-hole" + exit 1 + fi fi } From 1d60b62e7a13ca6603fba8909d8ae1c3f3f9208c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:11:23 +0100 Subject: [PATCH 05/16] Testing alternative way of fetching/checking out of a single branch --- advanced/Scripts/piholeCheckout.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 437dbc39..381de1c3 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -40,6 +40,24 @@ get_available_branches(){ return } + +fetch_checkout_pull_branch() { + # Check out specified branch + local directory="${1}" + local branch="${2}" + + # Check if branch exists locally + if git rev-parse --quiet --verify development &> /dev/null; then + # Branch exists locally, we can check it out and pull it + checkout_pull_branch "${directory}" "${branch}" || return 1 + else + # Branch does not exist locally, we set the reference for it, fetch, check it put and pull it + git remote set-branches origin "${branch}" || return 1 + git fetch --quiet || return 1 + checkout_pull_branch "${directory}" "${branch}" || return 1 + fi +} + checkout_pull_branch() { # Check out specified branch local directory="${1}" @@ -97,17 +115,17 @@ checkout() # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "core" ]] ; then echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " From febdb4a1905f5580b0bb66b7682051514ccd886d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:24:13 +0100 Subject: [PATCH 06/16] Use git diff to determine if code has changed (no need to run the installer if it hasn't changed at all) --- advanced/Scripts/piholeCheckout.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 381de1c3..112c8ab8 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,13 +9,15 @@ # Please see LICENSE file for your rights under this license. 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 # webInterfaceDir set in basic-install.sh # piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh +update=false + fully_fetch_repo() { # Add upstream branches to shallow clone local directory="${1}" @@ -64,6 +66,10 @@ checkout_pull_branch() { local branch="${2}" cd "${directory}" || return 1 + if [ "$(git diff "${branch}" | grep -c "^")" -gt "0" ]; then + update=true + fi + git checkout "${branch}" || return 1 git pull || return 1 return 0 @@ -169,9 +175,9 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" ]]; then + if [[ ! "${1}" == "web" && ${update} ]]; then echo "::: Running installer to upgrade your installation" - if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + if "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" --unattended; then exit 0 else echo "Unable to complete update, contact Pi-hole" From b961b13d60bde6072bf0e90ea219885c08f1d542 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:27:00 +0100 Subject: [PATCH 07/16] Small bugfix --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 112c8ab8..307d3d48 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -49,7 +49,7 @@ fetch_checkout_pull_branch() { local branch="${2}" # Check if branch exists locally - if git rev-parse --quiet --verify development &> /dev/null; then + if git rev-parse --quiet --verify "${branch}" &> /dev/null; then # Branch exists locally, we can check it out and pull it checkout_pull_branch "${directory}" "${branch}" || return 1 else From 140ac192aa603b373634b6f1b70d1940b24f6f47 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:30:58 +0100 Subject: [PATCH 08/16] The web repo might actually be missing and this is n error (not installed because the user didn't want it) --- advanced/Scripts/piholeCheckout.sh | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 307d3d48..8278cbc9 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -100,10 +100,17 @@ checkout() set -f #This is unlikely - if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then - echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" - echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" - exit 1 + if ! is_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + if [[ ${INSTALL_WEB} ]]; then + if ! is_repo "${ADMIN_INTERFACE_DIR}" ; 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 @@ -122,16 +129,20 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - echo "::: Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + if [[ ${INSTALL_WEB} ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - echo "::: Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + if [[ ${INSTALL_WEB} ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "core" ]] ; then echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " @@ -151,7 +162,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" ]] ; then + elif [[ "${1}" == "web" && ${INSTALL_WEB} ]] ; 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!" From 8cb66544d224fb4b392fa18a53895aa4d6fa4248 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:36:54 +0100 Subject: [PATCH 09/16] Remove "\ " --- advanced/Scripts/piholeCheckout.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 8278cbc9..2b4687db 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,7 +9,7 @@ # Please see LICENSE file for your rights under this license. 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 # webInterfaceDir set in basic-install.sh @@ -188,7 +188,7 @@ checkout() # Force updating everything if [[ ! "${1}" == "web" && ${update} ]]; then echo "::: Running installer to upgrade your installation" - if "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" --unattended; then + if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 else echo "Unable to complete update, contact Pi-hole" From d4a49d192f17413b5f5c02bda0545f0579dfc742 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:38:28 +0100 Subject: [PATCH 10/16] Correct variable name --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 2b4687db..6fd46fab 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -106,7 +106,7 @@ checkout() exit 1; fi if [[ ${INSTALL_WEB} ]]; then - if ! is_repo "${ADMIN_INTERFACE_DIR}" ; 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; From 1b9e7fbf2e4d649ff512259f3949c39186434368 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:40:10 +0100 Subject: [PATCH 11/16] Test if branch is locally available is not reliable because of possible ambiguities --- advanced/Scripts/piholeCheckout.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 6fd46fab..c255d822 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -48,16 +48,10 @@ fetch_checkout_pull_branch() { local directory="${1}" local branch="${2}" - # Check if branch exists locally - if git rev-parse --quiet --verify "${branch}" &> /dev/null; then - # Branch exists locally, we can check it out and pull it - checkout_pull_branch "${directory}" "${branch}" || return 1 - else - # Branch does not exist locally, we set the reference for it, fetch, check it put and pull it - git remote set-branches origin "${branch}" || return 1 - git fetch --quiet || return 1 - checkout_pull_branch "${directory}" "${branch}" || return 1 - fi + # Set the reference for the requested branch, fetch, check it put and pull it + git remote set-branches origin "${branch}" || return 1 + git fetch --quiet || return 1 + checkout_pull_branch "${directory}" "${branch}" || return 1 } checkout_pull_branch() { From bd2d81f691e6b0bba3dd31da21d9b451b36ee881 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:46:52 +0100 Subject: [PATCH 12/16] source setupVars.conf to see if INSTALL_WEB is true or not --- advanced/Scripts/piholeCheckout.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index c255d822..fb5f0fd9 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -15,6 +15,9 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # webInterfaceDir set in basic-install.sh # piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh +# setupVars set in basic-install.sh + +source "${setupVars}" update=false From 9a9d9007cd66980ff97b7341303019a42b2883d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:49:47 +0100 Subject: [PATCH 13/16] Add missing "== true" --- advanced/Scripts/piholeCheckout.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index fb5f0fd9..a3398daa 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -102,7 +102,7 @@ checkout() echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi - if [[ ${INSTALL_WEB} ]]; then + 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" @@ -126,7 +126,7 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - if [[ ${INSTALL_WEB} ]]; then + if [[ ${INSTALL_WEB} == true ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } fi @@ -136,7 +136,7 @@ checkout() echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - if [[ ${INSTALL_WEB} ]]; then + if [[ ${INSTALL_WEB} == true ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } fi @@ -159,7 +159,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" && ${INSTALL_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!" From 38547ced7a83d87c4cb0acc2234dd4ad2f61cac9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:55:37 +0100 Subject: [PATCH 14/16] Can only diff once upstream branch is tracked --- advanced/Scripts/piholeCheckout.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index a3398daa..25874744 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -63,11 +63,15 @@ checkout_pull_branch() { local branch="${2}" cd "${directory}" || return 1 - if [ "$(git diff "${branch}" | grep -c "^")" -gt "0" ]; then + + local oldbranch="$(git symbolic-ref HEAD)" + + git checkout "${branch}" || return 1 + + if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then update=true fi - git checkout "${branch}" || return 1 git pull || return 1 return 0 } From a2404f104a2ab430c20ea4841cd935e9ec25f3d0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 12:21:15 -0800 Subject: [PATCH 15/16] Just some style and linting. And a `cd` in `fetch_checkout_pull_branch` Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 25874744..fe46d413 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -19,7 +19,7 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" source "${setupVars}" -update=false +update="false" fully_fetch_repo() { # Add upstream branches to shallow clone @@ -52,6 +52,7 @@ fetch_checkout_pull_branch() { 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 @@ -61,15 +62,16 @@ checkout_pull_branch() { # Check out specified branch local directory="${1}" local branch="${2}" + local oldbranch cd "${directory}" || return 1 - local oldbranch="$(git symbolic-ref HEAD)" + oldbranch="$(git symbolic-ref HEAD)" git checkout "${branch}" || return 1 if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then - update=true + update="true" fi git pull || return 1 @@ -106,7 +108,7 @@ checkout() echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi - if [[ ${INSTALL_WEB} == true ]]; then + 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" @@ -130,7 +132,7 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - if [[ ${INSTALL_WEB} == true ]]; then + if [[ ${INSTALL_WEB} == "true" ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } fi @@ -140,7 +142,7 @@ checkout() echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - if [[ ${INSTALL_WEB} == true ]]; then + if [[ ${INSTALL_WEB} == "true" ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } fi @@ -163,7 +165,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" && ${INSTALL_WEB} == true ]] ; 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!" @@ -187,7 +189,7 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" && ${update} ]]; then + if [[ ! "${1}" == "web" && "${update}" ]]; then echo "::: Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 From b0ae954f1eae4d21ce976020d69d3d10022ff095 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 12:37:36 -0800 Subject: [PATCH 16/16] Only update when `update` flag is set to "true" Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index fe46d413..3b7abbef 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -189,7 +189,7 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" && "${update}" ]]; then + if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then echo "::: Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0