don't output "elevating with sudo" in pihole script, just do it.

This commit is contained in:
Adam Warner 2016-10-18 12:05:48 +01:00
parent 97a013b2b7
commit 29ad2496b6
3 changed files with 73 additions and 8 deletions

View file

@ -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.

View file

@ -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)"
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

52
pihole
View file

@ -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 ":::"