From 77808223dc3d4730c3053b14300b98fe996b8377 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 10:05:10 +0100 Subject: [PATCH 1/9] remove stock comments from 01-pihole.conf and add warning to the top --- advanced/01-pihole.conf | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 339bbf90..e7e627a4 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -9,53 +9,31 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# If you want dnsmasq to read another file, as well as /etc/hosts, use -# this. +############################################################################### +# FILE AUTOMATICALLY POPULATED BY PI-HOLE INSTALL/UPDATE PROCEDURE. # +# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # +############################################################################### + addn-hosts=/etc/pihole/gravity.list -# The following two options make you a better netizen, since they -# tell dnsmasq to filter out queries which the public DNS cannot -# answer, and which load the servers (especially the root servers) -# unnecessarily. If you have a dial-on-demand link they also stop -# these requests from bringing up the link unnecessarily. - -# Never forward plain names (without a dot or domain part) domain-needed -# Never forward addresses in the non-routed address spaces. + bogus-priv -# If you don't want dnsmasq to read /etc/resolv.conf or any other -# file, getting its servers from this file instead (see below), then -# uncomment this. no-resolv -# Add other name servers here, with domain specs if they are for -# non-public domains. server=@DNS1@ server=@DNS2@ -# If you want dnsmasq to listen for DHCP and DNS requests only on -# specified interfaces (and the loopback) give the name of the -# interface (eg eth0) here. interface=@INT@ -# Or which to listen on by address (remember to include 127.0.0.1 if -# you use this.) + listen-address=127.0.0.1 -# Set the cachesize here. cache-size=10000 -# For debugging purposes, log each DNS query as it passes through -# dnsmasq. log-queries log-facility=/var/log/pihole.log -# Normally responses which come from /etc/hosts and the DHCP lease -# file have Time-To-Live set as zero, which conventionally means -# do not cache further. If you are happy to trade lower load on the -# server for potentially stale date, you can set a time-to-live (in -# seconds) here. local-ttl=300 -# This allows it to continue functioning without being blocked by syslog, and allows syslog to use dnsmasq for DNS queries without risking deadlock log-async From 97a013b2b7de5f09c88fc0d35881feb00706f710 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 10:34:05 +0100 Subject: [PATCH 2/9] Add direction to change upstream servers in setupVars.conf --- advanced/01-pihole.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index e7e627a4..fd8e27f2 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -12,6 +12,12 @@ ############################################################################### # FILE AUTOMATICALLY POPULATED BY PI-HOLE INSTALL/UPDATE PROCEDURE. # # ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # +# # +# IF YOU WISH TO CHANGE THE UPSTREAM SERVERS, CHANGE THEM IN: # +# /etc/pihole/setupVars.conf # +# # +# ANY OTHER CHANGES SHOULD BE MADE IN A SEPERATE CONFIG FILE # +# OR IN /etc/dnsmasq.conf # ############################################################################### addn-hosts=/etc/pihole/gravity.list From 29ad2496b63a0a838e11873eaa4e089d232d3de7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:05:48 +0100 Subject: [PATCH 3/9] don't output "elevating with sudo" in pihole script, just do it. --- advanced/Scripts/update.sh | 12 +++++++++ advanced/Scripts/version.sh | 17 +++++++++++- pihole | 52 ++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 advanced/Scripts/update.sh diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh new file mode 100644 index 00000000..bdd6ab88 --- /dev/null +++ b/advanced/Scripts/update.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Whitelists domains +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e7e7c782..521fa26c 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -10,6 +10,10 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. + + + +normalOutput(){ piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) @@ -17,4 +21,15 @@ piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/relea 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)" -echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" \ No newline at end of file +echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" + +} + +for var in "$@" +do + case "$var" in + "-j" | "--json" ) outputJSON;; + "-h" | "--help" ) displayHelp;; + * ) normalOutput;; + esac +done \ No newline at end of file diff --git a/pihole b/pihole index 4ed446be..25a03864 100755 --- a/pihole +++ b/pihole @@ -13,7 +13,6 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then if [ -x "$(command -v sudo)" ];then - echo "::: Elevating to root with sudo" exec sudo bash "$0" "$@" exit $? else @@ -44,9 +43,48 @@ flushFunc() { exit 0 } +getGitFiles() { + # Setup git repos for directory and repository passed + # as arguments 1 and 2 + echo ":::" + echo "::: Checking for existing repository..." + if is_repo "${1}"; then + update_repo "${1}" + else + make_repo "${1}" "${2}" + fi +} + +is_repo() { + # Use git to check if directory is currently under VCS + echo -n "::: Checking $1 is a repo..." + cd "${1}" &> /dev/null || return 1 + git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 +} + +make_repo() { + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" +} + +update_repo() { + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git pull -q > /dev/null & spinner $! + echo " done!" +} updatePiholeFunc() { + webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" + webInterfaceDir="/var/www/html/admin" + piholeGitUrl="https://github.com/pi-hole/pi-hole.git" + piholeFilesDir="/etc/.pihole" + if [ ! -d "/etc/.pihole" ]; then #This is unlikely echo "::: Critical Error: Pi-Hole repo missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" @@ -75,17 +113,17 @@ updatePiholeFunc() { echo ":::" if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date!" + echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" echo "::: No need to update!" echo ":::" else echo "::: An Update is available for the Web Admin!" echo ":::" echo "::: Fetching latest changes from GitHub..." - cd /var/www/html/admin - git pull origin master + # Update Git files for Core + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersion}" + echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" echo "::: See https://changes.pi-hole.net for details" fi else @@ -97,8 +135,8 @@ updatePiholeFunc() { fi echo "::: Fetching latest changes from GitHub..." - cd /etc/.pihole - git pull origin master + # Update Git files for Core + getGitFiles ${piholeFilesDir} ${piholeGitUrl} /etc/.pihole/automated\ install/basic-install.sh --unattended echo ":::" From 013d77488af0375cd485540cae8f487b4e784318 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:07:11 +0100 Subject: [PATCH 4/9] complete overhaul of version script. Now with optional arguments! --- advanced/Scripts/version.sh | 91 ++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 521fa26c..e77fdfc2 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -10,26 +10,93 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. - - +# Flags: +latest=false +current=false normalOutput(){ -piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) -webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) + 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)" -echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" + 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)" + echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" } +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} + 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/",$//') + fi +} + +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} + 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)" + fi +} + +helpFunc() +{ + echo ":::" + echo "::: Show Pi-hole/Web Admin versions" + echo ":::" + echo "::: Usage: pihole -v [ -a | -p ] [ -l | -c ]" + echo ":::" + echo "::: Options:" + echo "::: -a, --admin Show both current and latest versions of web admin" + echo "::: -p, --pihole Show both current and latest versions of Pi-hole core files" + echo "::: -l, --latest (Only after -a | -p) Return only latest version" + echo "::: -c, --current (Only after -a | -p) Return only current version" + echo "::: -h, --help Show this help dialog" + echo ":::" + exit 0 +} + +if [[ $# = 0 ]]; then + normalOutput +fi + for var in "$@" do case "$var" in - "-j" | "--json" ) outputJSON;; - "-h" | "--help" ) displayHelp;; - * ) normalOutput;; + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; + * ) helpFunc;; esac done \ No newline at end of file From 77e8be09a1c33445cd2046ec23d8df5a430723b9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:07:42 +0100 Subject: [PATCH 5/9] handle passing arguments to version script --- pihole | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 25a03864..c4faad57 100755 --- a/pihole +++ b/pihole @@ -193,7 +193,8 @@ uninstallFunc() { } versionFunc() { - /opt/pihole/version.sh + shift + /opt/pihole/version.sh "$@" exit 0 } @@ -235,7 +236,7 @@ case "$1" in "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; -"-v" | "version" ) versionFunc;; +"-v" | "version" ) versionFunc "$@";; "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; * ) helpFunc;; From ce46c4dec47940e74d93082a55b27f66bb907e6b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:11:02 +0100 Subject: [PATCH 6/9] remove prematurely added code --- advanced/Scripts/update.sh | 70 +++++++++++++++++++++++++++ pihole | 96 +------------------------------------- 2 files changed, 72 insertions(+), 94 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index bdd6ab88..e471ab39 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -10,3 +10,73 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Variables +webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" +webInterfaceDir="/var/www/html/admin" +piholeGitUrl="https://github.com/pi-hole/pi-hole.git" +piholeFilesDir="/etc/.pihole" + + if [ ! -d "/etc/.pihole" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + if [ ! -d "/var/www/html/admin" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + + echo "::: Checking for updates..." + 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/",$//') + + 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 "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" + echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" + echo ":::" + + if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then + echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" + echo "::: No need to update!" + echo ":::" + + if [[ ${webVersion} == ${webVersionLatest} ]] ; then + echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" + echo "::: No need to update!" + echo ":::" + else + echo "::: An Update is available for the Web Admin!" + echo ":::" + echo "::: Fetching latest changes from GitHub..." + # Update Git files for Core + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} + echo ":::" + echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" + echo "::: See https://changes.pi-hole.net for details" + fi + else + echo -n "::: An update is available for " + if [[ ${webVersion} == ${webVersionLatest} ]] ; then + echo " Pi-Hole!" + else + echo " Pi-Hole base files and the Web Admin. Both will be updated!" + fi + + echo "::: Fetching latest changes from GitHub..." + # Update Git files for Core + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --unattended + + echo ":::" + echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" + if [[ ${webVersion} != ${webVersionLatest} ]] ; then + echo "::: Web Admin has been updated to version ${webVersionLatest}" + fi + echo ":::" + echo "::: See https://changes.pi-hole.net for details" + fi + + exit 0 \ No newline at end of file diff --git a/pihole b/pihole index c4faad57..0e29b23e 100755 --- a/pihole +++ b/pihole @@ -55,100 +55,8 @@ getGitFiles() { fi } -is_repo() { - # Use git to check if directory is currently under VCS - echo -n "::: Checking $1 is a repo..." - cd "${1}" &> /dev/null || return 1 - git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 -} - -make_repo() { - # Remove the non-repod interface and clone the interface - echo -n "::: Cloning $2 into $1..." - rm -rf "${1}" - git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! - echo " done!" -} - -update_repo() { - # Pull the latest commits - echo -n "::: Updating repo in $1..." - cd "${1}" || exit 1 - git pull -q > /dev/null & spinner $! - echo " done!" -} - updatePiholeFunc() { - - webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" - webInterfaceDir="/var/www/html/admin" - piholeGitUrl="https://github.com/pi-hole/pi-hole.git" - piholeFilesDir="/etc/.pihole" - - if [ ! -d "/etc/.pihole" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - if [ ! -d "/var/www/html/admin" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - - echo "::: Checking for updates..." - 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/",$//') - - 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 "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" - echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" - echo ":::" - - if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then - echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" - echo "::: No need to update!" - echo ":::" - - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" - echo "::: No need to update!" - echo ":::" - else - echo "::: An Update is available for the Web Admin!" - echo ":::" - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} - echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" - echo "::: See https://changes.pi-hole.net for details" - fi - else - echo -n "::: An update is available for " - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo " Pi-Hole!" - else - echo " Pi-Hole base files and the Web Admin. Both will be updated!" - fi - - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --unattended - - echo ":::" - echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" - if [[ ${webVersion} != ${webVersionLatest} ]] ; then - echo "::: Web Admin has been updated to version ${webVersionLatest}" - fi - echo ":::" - echo "::: See https://changes.pi-hole.net for details" - fi - - exit 0 + echo "Not Implemented" } reconfigurePiholeFunc() { @@ -202,7 +110,7 @@ helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer), or -v (version) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains" From ff5d5b97c33d1ec1e1a2d47cd0b81acf9cd1d303 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 13:54:09 +0100 Subject: [PATCH 7/9] stash any changes in local repo --- automated install/basic-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7c26019e..8072f79a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -702,6 +702,7 @@ update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! git pull -q > /dev/null & spinner $! echo " done!" } From 27d6e5d8cf4a47f4eb030cbaf1f729d5eaa5b751 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 14:19:25 +0100 Subject: [PATCH 8/9] Complete overhaul of update logic. Moved to seperate script --- advanced/Scripts/update.sh | 179 +++++++++++++++++++++++++------------ 1 file changed, 121 insertions(+), 58 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index e471ab39..34c12cfd 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -11,72 +11,135 @@ # (at your option) any later version. # Variables + webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" webInterfaceDir="/var/www/html/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeFilesDir="/etc/.pihole" - if [ ! -d "/etc/.pihole" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - if [ ! -d "/var/www/html/admin" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi +spinner() +{ + local pid=$1 + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" +} - echo "::: Checking for updates..." - 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/",$//') +getGitFiles() { + # Setup git repos for directory and repository passed + # as arguments 1 and 2 + echo ":::" + echo "::: Checking for existing repository..." + if is_repo "${1}"; then + update_repo "${1}" + else + make_repo "${1}" "${2}" + fi +} - 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/",$//') +is_repo() { + # Use git to check if directory is currently under VCS + echo -n "::: Checking $1 is a repo..." + cd "${1}" &> /dev/null || return 1 + git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 +} - echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" - echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" +make_repo() { + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" +} + +update_repo() { + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! + echo " done!" +} + +if [ ! -d "/etc/.pihole" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; +fi +if [ ! -d "/var/www/html/admin" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; +fi + +echo "::: Checking for updates..." +piholeVersion=$(pihole -v -p -c) +piholeVersionLatest=$(pihole -v -p -l) + +webVersion=$(pihole -v -a -c) +webVersionLatest=$(pihole -v -a -l) + +echo ":::" +echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" +echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" +echo ":::" + +# Logic +# If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!): +# Update anyway +# If Core up to date AND web up to date: +# Do nothing +# If Core up to date AND web NOT up to date: +# Pull web repo +# If Core NOT up to date AND web up to date: +# pull pihole repo, run install --unattended -- reconfigure +# if Core NOT up to date AND web NOT up to date: +# pull pihole repo run install --unattended + + + +if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then + echo "::: Everything is up to date!" + echo "" + exit 0 + +elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then + echo "::: Pi-hole Web Admin files out of date" + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} echo ":::" + webVersion=$(pihole -v -a -c) + echo "::: Web Admin version is now at ${webVersion}" + echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" + echo "" - if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then - echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" - echo "::: No need to update!" - echo ":::" +elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then + echo "::: Pi-hole core files out of date" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended + echo ":::" + piholeVersion=$(pihole -v -p -c) + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" - echo "::: No need to update!" - echo ":::" - else - echo "::: An Update is available for the Web Admin!" - echo ":::" - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} - echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" - echo "::: See https://changes.pi-hole.net for details" - fi - else - echo -n "::: An update is available for " - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo " Pi-Hole!" - else - echo " Pi-Hole base files and the Web Admin. Both will be updated!" - fi - - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --unattended - - echo ":::" - echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" - if [[ ${webVersion} != ${webVersionLatest} ]] ; then - echo "::: Web Admin has been updated to version ${webVersionLatest}" - fi - echo ":::" - echo "::: See https://changes.pi-hole.net for details" - fi - - exit 0 \ No newline at end of file +elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then + echo "::: Updating Everything" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --unattended + webVersion=$(pihole -v -a -c) + piholeVersion=$(pihole -v -p -c) + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" +fi \ No newline at end of file From b66f23cfd0778d57eb13baa209b4632726ada32f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 14:19:44 +0100 Subject: [PATCH 9/9] account for new update script --- advanced/Scripts/version.sh | 4 ++-- pihole | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e77fdfc2..61ff7502 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -3,7 +3,7 @@ # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi # http://pi-hole.net -# Whitelists domains +# shows version numbers # # Pi-hole is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,6 +44,7 @@ webOutput(){ 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)" fi } @@ -97,6 +98,5 @@ do "-a" | "--admin" ) shift; webOutput "$@";; "-p" | "--pihole" ) shift; coreOutput "$@" ;; "-h" | "--help" ) helpFunc;; - * ) helpFunc;; esac done \ No newline at end of file diff --git a/pihole b/pihole index 0e29b23e..6be32acf 100755 --- a/pihole +++ b/pihole @@ -43,20 +43,10 @@ flushFunc() { exit 0 } -getGitFiles() { - # Setup git repos for directory and repository passed - # as arguments 1 and 2 - echo ":::" - echo "::: Checking for existing repository..." - if is_repo "${1}"; then - update_repo "${1}" - else - make_repo "${1}" "${2}" - fi -} updatePiholeFunc() { - echo "Not Implemented" + /opt/pihole/update.sh + exit 0 } reconfigurePiholeFunc() { @@ -110,7 +100,7 @@ helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer), or -v (version) for more information on usage" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains"