From 29ad2496b63a0a838e11873eaa4e089d232d3de7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:05:48 +0100 Subject: [PATCH] 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 ":::"