2016-10-18 13:05:48 +02:00
|
|
|
#!/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
|
2016-11-01 19:33:04 +01:00
|
|
|
# Check Pi-hole core and admin pages versions and determine what
|
|
|
|
# upgrade (if any) is required. Automatically updates and reinstalls
|
|
|
|
# application if update is detected.
|
2016-10-18 13:05:48 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2016-10-18 13:11:02 +02:00
|
|
|
# Variables
|
2016-10-18 15:19:25 +02:00
|
|
|
|
2016-11-02 06:19:40 +01:00
|
|
|
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
|
|
|
|
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
|
|
|
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
|
|
|
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
2016-10-18 15:19:25 +02:00
|
|
|
|
|
|
|
is_repo() {
|
2016-11-02 13:45:29 +01:00
|
|
|
# Use git to check if directory is currently under VCS, do not exit if failed
|
|
|
|
local directory="${1}"
|
|
|
|
cd "${directory}" &> /dev/null || false
|
2016-11-02 13:34:39 +01:00
|
|
|
git status --short &> /dev/null
|
2016-11-02 11:38:35 +01:00
|
|
|
return
|
2016-10-18 15:19:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 13:34:39 +01:00
|
|
|
prep_dirs() {
|
|
|
|
# Prepare directory for local repository building
|
|
|
|
local dir_to_clean="${1}"
|
2016-11-02 13:45:29 +01:00
|
|
|
rm -rf "${dir_to_clean}" &> /dev/null
|
2016-11-02 13:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
make_repo() {
|
|
|
|
# Remove the non-repod interface and clone the interface
|
|
|
|
local source_repo="${2}"
|
|
|
|
local dest_dir="${1}"
|
2016-11-02 13:45:29 +01:00
|
|
|
|
2016-11-02 13:34:39 +01:00
|
|
|
echo -n "::: Cloning ${source_repo} into ${dest_dir}..."
|
2016-11-02 13:45:29 +01:00
|
|
|
prep_dirs "${dest_dir}"
|
|
|
|
git clone -q --depth 1 "${source_repo}" "${dest_dir}" > /dev/null \
|
|
|
|
|| (echo "Unable to clone directory, please contact support"; exit false)
|
2016-11-02 13:34:39 +01:00
|
|
|
echo " done!"
|
2016-10-18 15:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
update_repo() {
|
2016-10-22 19:01:15 +02:00
|
|
|
# Pull the latest commits
|
|
|
|
echo -n "::: Updating repo in $1..."
|
|
|
|
cd "${1}" || exit 1
|
2016-11-01 20:16:46 +01:00
|
|
|
git stash -q > /dev/null || exit 1
|
|
|
|
git pull -q > /dev/null || exit 1
|
2016-10-22 19:01:15 +02:00
|
|
|
echo " done!"
|
2016-10-18 15:19:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 06:19:40 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:12:02 +01:00
|
|
|
main() {
|
|
|
|
|
2016-11-02 13:45:29 +01:00
|
|
|
if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${ADMIN_INTERFACE_DIR}" ; then #This is unlikely
|
2016-11-02 13:34:39 +01:00
|
|
|
echo "::: Critical Error: One or more Pi-Hole repos are missing from system!"
|
2016-11-02 09:12:02 +01:00
|
|
|
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "::: Checking for updates..."
|
|
|
|
# Checks Pi-hole version > pihole only > current local git repo version : returns string in format vX.X.X
|
|
|
|
local -r pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
|
|
|
|
# Checks Pi-hole version > pihole only > remote upstream repo version : returns string in format vX.X.X
|
|
|
|
local -r pihole_version_latest="$(/usr/local/bin/pihole -v -p -l)"
|
|
|
|
|
|
|
|
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
|
|
|
|
local -r web_version_current="$(/usr/local/bin/pihole -v -a -c)"
|
|
|
|
# Checks Pi-hole version > admin only > remote upstream repo version : returns string in format vX.X.X
|
|
|
|
local -r web_version_latest="$(/usr/local/bin/pihole -v -a -l)"
|
|
|
|
|
|
|
|
# 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 [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
|
|
|
|
echo "::: Pi-hole version is $pihole_version_current"
|
|
|
|
echo "::: Web Admin version is $web_version_current"
|
|
|
|
echo "::: Everything is up to date!"
|
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
elif [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
|
|
|
|
echo "::: Pi-hole Web Admin files out of date"
|
|
|
|
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
|
|
|
echo ":::"
|
|
|
|
web_version_current="$(/usr/local/bin/pihole -v -a -c)"
|
|
|
|
echo "::: Web Admin version is now at ${web_version_current}"
|
|
|
|
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
|
|
|
|
echo ""
|
|
|
|
elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
|
|
|
|
echo "::: Pi-hole core files out of date"
|
|
|
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
|
|
|
|
|
|
|
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
|
|
|
|
|
|
|
echo ":::"
|
|
|
|
pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
|
|
|
|
echo "::: Pi-hole version is now at ${pihole_version_current}"
|
|
|
|
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
|
|
|
|
echo ""
|
|
|
|
elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
|
|
|
|
echo "::: Updating Everything"
|
|
|
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
|
|
|
|
|
|
|
/etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
|
|
|
|
|
|
|
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
|
|
|
|
web_version_current="$(/usr/local/bin/pihole -v -a -c)"
|
|
|
|
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
|
|
|
|
pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
|
|
|
|
echo ":::"
|
|
|
|
echo "::: Pi-hole version is now at ${pihole_version_current}"
|
|
|
|
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 ${pihole_version_current}"
|
|
|
|
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
}
|
2016-11-02 08:51:38 +01:00
|
|
|
|
2016-11-02 09:12:02 +01:00
|
|
|
main
|