From 9a95531fb917835dfa86994d3476c8a80287d1a4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Mar 2017 00:43:35 +0100 Subject: [PATCH 01/10] Merge pull request #1310 from pi-hole/new/piholecheckout Pi-hole checkout feature --- advanced/Scripts/piholeCheckout.sh | 163 +++++++++++++++++++++++++++++ advanced/bash-completion/pihole | 2 +- pihole | 11 +- 3 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 advanced/Scripts/piholeCheckout.sh diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh new file mode 100644 index 00000000..86ea9a2b --- /dev/null +++ b/advanced/Scripts/piholeCheckout.sh @@ -0,0 +1,163 @@ +#!/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. +# +# Checkout other branches than master +# +# This file is copyright under the latest version of the EUPL. +# 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 + +# 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 + +fully_fetch_repo() { + # Add upstream branches to shallow clone + local directory="${1}" + + cd "${directory}" || return 1 + if is_repo "${directory}"; then + git remote set-branches origin '*' || return 1 + git fetch --quiet || return 1 + else + return 1 + fi + return 0 +} + +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 +} + +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 +} + +warning1() { + echo "::: Note that changing the branch is a severe change of your Pi-hole system." + echo "::: This is not supported unless one of the developers explicitly asks you to do this!" + read -r -p "::: Have you read and understood this? [y/N] " response + case ${response} in + [yY][eE][sS]|[yY]) + echo "::: Continuing." + return 0 + ;; + *) + echo "::: Aborting." + return 1 + ;; + esac +} + +checkout() +{ + local corebranches + local webbranches + + # Avoid globbing + 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 + fi + + if ! warning1 ; then + 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" + echo "::: Web interface" + checkout_pull_branch "${webInterfaceDir}" "devel" + 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 "::: Web interface" + checkout_pull_branch "${webInterfaceDir}" "master" + echo "::: done!" + elif [[ "${1}" == "core" ]] ; then + # 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!" + echo "::: Available branches for core are:" + for e in "${corebranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" + elif [[ "${1}" == "web" ]] ; then + # 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!" + echo "::: Available branches for web are:" + for e in "${webbranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${webInterfaceDir}" "${2}" + else + echo "::: Requested option \"${1}\" is not available!" + exit 1 + 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 + fi +} + diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 05baa820..fc8f2162 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -3,7 +3,7 @@ _pihole() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist" + opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist checkout" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 diff --git a/pihole b/pihole index 41946f35..97f749ab 100755 --- a/pihole +++ b/pihole @@ -8,9 +8,8 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" - -PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then @@ -278,6 +277,12 @@ tailFunc() { exit 0 } +piholeCheckoutFunc() { + source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh + shift + checkout "$@" +} + helpFunc() { cat << EOM ::: Control all PiHole specific functions! @@ -311,6 +316,7 @@ helpFunc() { ::: Blocking can also be disabled only temporarily, e.g., ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq +::: checkout Check out different branches EOM exit 0 } @@ -341,5 +347,6 @@ case "${1}" in "restartdns" ) restartDNS;; "-a" | "admin" ) webpageFunc "$@";; "-t" | "tail" ) tailFunc;; + "checkout" ) piholeCheckoutFunc "$@";; * ) helpFunc;; esac From 0fe64cf5cc14e614cd03d53a1c3bffcfe39f07e9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 16:16:42 +0100 Subject: [PATCH 02/10] Merge pull request #1300 from pi-hole/fix/deletehostrecord Bugfix for when deleting host-record --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index a21300ad..5f032ed1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -134,7 +134,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3 delete_dnsmasq_setting "host-record" - if [ ! -z "${HOSTRECORD+x}" ]; then + if [ ! -z "${HOSTRECORD}" ]; then add_dnsmasq_setting "host-record" "${HOSTRECORD}" fi From de6aaf18abf414f297abd09f30e767a37341bc37 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 17:03:34 +0100 Subject: [PATCH 03/10] Merge pull request #1302 from pi-hole/fix/nowildcardlistfile Check for existence of wildcard blocking list (query adlists) --- pihole | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 97f749ab..dda6d750 100755 --- a/pihole +++ b/pihole @@ -127,17 +127,19 @@ queryFunc() { done # Scan for possible wildcard matches - local wildcards=($(processWildcards "${domain}")) - for domain in ${wildcards[@]}; do - result=$(scanList "\/${domain}\/" ${wildcardlist}) - # Remove empty lines before couting number of results - count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - if [[ ${count} > 0 ]]; then - echo "::: Wildcard blocking ${domain} (${count} results)" - echo "${result}" - echo "" - fi - done + if [ -e "${wildcardlist}" ]; then + local wildcards=($(processWildcards "${domain}")) + for domain in ${wildcards[@]}; do + result=$(scanList "\/${domain}\/" ${wildcardlist}) + # Remove empty lines before couting number of results + count=$(sed '/^\s*$/d' <<< "$result" | wc -l) + if [[ ${count} > 0 ]]; then + echo "::: Wildcard blocking ${domain} (${count} results)" + echo "${result}" + echo "" + fi + done + fi exit 0 } From 6f8893d9504b6f4cb1503c89c67611b31266571a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 23:53:06 +0100 Subject: [PATCH 04/10] Merge pull request #1301 from pi-hole/fix/removewildcard Remove wildcard entry when adding the very same domain either the white- or blacklist --- advanced/Scripts/list.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 90d1b7f0..2ac1e805 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,6 +84,7 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" + RemoveDomain "${dom}" "${wildcardlist}" else RemoveDomain "${dom}" "${listMain}" fi From bc514ea9551a13eaae414c2b2624dfd8a21c3892 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 5 Mar 2017 07:13:41 -0800 Subject: [PATCH 05/10] Merge pull request #1296 from pi-hole/fix/debugVersion Debug version detection improvements --- advanced/Scripts/piholeDebug.sh | 65 +++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 70d73379..0b8a2571 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -24,6 +24,8 @@ WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" ADLISTFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" +PIHOLEGITDIR="/etc/.pihole/" +ADMINGITDIR="/var/www/html/admin/" WHITELISTMATCHES="/tmp/whitelistmatches.list" TIMEOUT=60 @@ -111,22 +113,61 @@ version_check() { header_write "Detecting Installed Package Versions:" local error_found + local pi_hole_ver + local pi_hole_branch + local pi_hole_commit + local admin_ver + local admin_branch + local admin_commit + local light_ver + local php_ver + local status error_found=0 - local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) - local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) - local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ - && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) - local php_ver="$(php -v |& head -n1)" \ - && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) + cd "${PIHOLEGITDIR}" &> /dev/null || \ + { status="Pi-hole git directory not found."; error_found=1; } + if git status &> /dev/null; then + pi_hole_ver=$(git describe --tags --abbrev=0) + pi_hole_branch=$(git rev-parse --abbrev-ref HEAD) + pi_hole_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole: ${pi_hole_ver:-Untagged} (${pi_hole_branch:-Detached}:${pi_hole_commit})" + else + status=${status:-"Pi-hole repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi - (local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}") || log_echo "Unable to obtain Pi-hole branch" - (local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}") || log_echo "Unable to obtain Pi-hole revision" + cd "${ADMINGITDIR}" || \ + { status="Pi-hole Dashboard git directory not found."; error_found=1; } + if git status &> /dev/null; then + admin_ver=$(git describe --tags --abbrev=0) + admin_branch=$(git rev-parse --abbrev-ref HEAD) + admin_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole Dashboard: ${admin_ver:-Untagged} (${admin_branch:-Detached}:${admin_commit})" + else + status=${status:-"Pi-hole Dashboard repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi - (local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}") || log_echo "Unable to obtain AdminLTE branch" - (local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}") || log_echo "Unable to obtain AdminLTE revision" + if light_ver=$(lighttpd -v |& head -n1 | cut -d " " -f1); then + log_echo -r "${light_ver}" + else + log_echo "lighttpd not installed." + error_found=1 + fi + if php_ver=$(php -v |& head -n1); then + log_echo -r "${php_ver}" + else + log_echo "PHP not installed." + error_found=1 + fi return "${error_found}" } From 8460b2544bb85ff3cfd640a6e8c28a3553157ec0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 15:17:25 -0800 Subject: [PATCH 06/10] Merge pull request #1295 from pi-hole/tweak/pullapprove Require 4 approvals instead of five for merging into master --- .pullapprove.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index f9d10062..ff970b29 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -33,6 +33,6 @@ groups: conditions: branches: - master - required: -1 + required: 4 teams: - admin From 33f7979359d148f20e3f97fd3fd62092dd9a9c94 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 5 Mar 2017 07:10:18 -0800 Subject: [PATCH 07/10] Merge pull request #1293 from pi-hole/fix/version Account for hash in versioning --- advanced/Scripts/version.sh | 147 +++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 59 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 11a7af00..fd74c2de 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,67 +8,98 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - -# Flags: -latest=false -current=false - +# Variables DEFAULT="-1" +PHGITDIR="/etc/.pihole/" +WEBGITDIR="/var/www/html/admin/" + +getLocalVersion() { + # Get the tagged version of the local repository + local directory="${1}" + local version + + cd "${directory}" || { echo "${DEFAULT}"; return 1; } + version=$(git describe --tags --always || \ + echo "${DEFAULT}") + if [[ "${version}" =~ ^v ]]; then + echo "${version}" + elif [[ "${version}" == "${DEFAULT}" ]]; then + echo "ERROR" + return 1 + else + echo "Untagged" + fi + return 0 +} + +getLocalHash() { + # Get the short hash of the local repository + local directory="${1}" + local hash + + cd "${directory}" || { echo "${DEFAULT}"; return 1; } + hash=$(git rev-parse --short HEAD || \ + echo "${DEFAULT}") + if [[ "${hash}" == "${DEFAULT}" ]]; then + echo "ERROR" + return 1 + else + echo "${hash}" + fi + return 0 +} + +getRemoteVersion(){ + # Get the version from the remote origin + local daemon="${1}" + local version + + version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \ + awk -F: '$1 ~/tag_name/ { print $2 }' | \ + tr -cd '[[:alnum:]]._-') + if [[ "${version}" =~ ^v ]]; then + echo "${version}" + else + echo "ERROR" + return 1 + fi + return 0 +} + +#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ +# grep sha | \ +# head -n1 | \ +# awk -F ' ' '{ print $2 }' | \ +# tr -cd '[[:alnum:]]._-') + +#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ +# grep sha | \ +# head -n1 | \ +# awk -F ' ' '{ print $2 }' | \ +# tr -cd '[[:alnum:]]._-') + normalOutput() { - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" + echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" } webOutput() { - for var in "$@"; do - case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done - - if [[ "${latest}" == true && "${current}" == false ]]; then - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${webVersionLatest:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - echo "${webVersion}" - else - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" - fi + case "${1}" in + "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; + "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; + * ) echo "::: Invalid Option!"; exit 1; + esac } coreOutput() { - for var in "$@"; do - case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done - - if [[ "${latest}" == true && "${current}" == false ]]; then - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${piholeVersionLatest:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - echo "${piholeVersion}" - else - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" - fi + case "${1}" in + "-l" | "--latest" ) echo $(getRemoteVersion pi-hole);; + "-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");; + * ) echo "::: Invalid Option!"; exit 1; + esac } helpFunc() { @@ -93,10 +124,8 @@ if [[ $# = 0 ]]; then normalOutput fi -for var in "$@"; do - case "${var}" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; - esac -done +case "${1}" in + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; +esac From 38ba079baaaf3d6109962c724e0e4a55dfcfd77f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 23:54:32 +0100 Subject: [PATCH 08/10] Merge pull request #1307 from pi-hole/fix/versionwithoutwebinterface Don't try to obtain version of web interface it it is not installed --- advanced/Scripts/version.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index fd74c2de..7f96e29a 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -81,16 +81,22 @@ getRemoteVersion(){ normalOutput() { echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" - echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + if [ -d "${WEBGITDIR}" ]; then + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + fi } webOutput() { - case "${1}" in - "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; - "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; - "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; - * ) echo "::: Invalid Option!"; exit 1; - esac + if [ -d "${WEBGITDIR}" ]; then + case "${1}" in + "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; + "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; + * ) echo "::: Invalid Option!"; exit 1; + esac + else + echo "::: Web interface not installed!"; exit 1; + fi } coreOutput() { From df18c7cd5953512bb7c444a86585f7eadb7b35bf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 13:01:11 -0800 Subject: [PATCH 09/10] Merge pull request #1313 from pi-hole/new/piholecheckout Checkout adjustments --- advanced/Scripts/piholeCheckout.sh | 131 +++++++++++++++++++---------- 1 file changed, 85 insertions(+), 46 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 86ea9a2b..3b7abbef 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,12 +9,17 @@ # 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 +# setupVars set in basic-install.sh + +source "${setupVars}" + +update="false" fully_fetch_repo() { # Add upstream branches to shallow clone @@ -33,28 +38,44 @@ 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 } + +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() { # Check out specified branch local directory="${1}" local branch="${2}" - local curdir + local oldbranch - curdir="${PWD}" cd "${directory}" || return 1 - git checkout "${branch}" - git pull - cd "${curdir}" || return 1 - return + + oldbranch="$(git symbolic-ref HEAD)" + + git checkout "${branch}" || return 1 + + if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then + update="true" + fi + + git pull || return 1 + return 0 } warning1() { @@ -82,9 +103,23 @@ 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" + 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} == "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 '." + echo "::: Or enter the repository and branch you would like to check out:" + echo "::: 'pihole checkout '" exit 1 fi @@ -92,43 +127,36 @@ 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" - echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } + if [[ ${INSTALL_WEB} == "true" ]]; 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" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" - echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } + if [[ ${INSTALL_WEB} == "true" ]]; 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} ... " + 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!" @@ -137,7 +165,16 @@ checkout() exit 1 fi 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 if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -152,12 +189,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" && "${update}" == "true" ]]; 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 8fa209f0df06e05328101323627e5de3b757ea91 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 13 Mar 2017 17:50:18 -0400 Subject: [PATCH 10/10] Merge pull request #1322 from pi-hole/FixWildCardBlacklisting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only remove from wildcard list if domain is being added to whitelist … --- advanced/Scripts/list.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 2ac1e805..537ebac3 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,7 +84,9 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" - RemoveDomain "${dom}" "${wildcardlist}" + if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then + RemoveDomain "${dom}" "${wildcardlist}" + fi else RemoveDomain "${dom}" "${listMain}" fi