2016-10-18 11:05:48 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-11-01 18:33:04 +00: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 11:05:48 +00:00
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
2016-10-18 11:11:02 +00:00
|
|
|
# Variables
|
2016-11-02 05:19:40 +00: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"
|
2017-02-05 19:07:04 +00:00
|
|
|
|
2017-06-25 21:21:41 +00:00
|
|
|
# shellcheck disable=SC2034
|
2017-01-29 01:32:42 +00:00
|
|
|
PH_TEST=true
|
2016-10-18 13:19:25 +00:00
|
|
|
|
2017-06-25 21:21:41 +00:00
|
|
|
# Have to ignore the following rule as spaces in paths are not supported by ShellCheck
|
|
|
|
#shellcheck disable=SC1090
|
|
|
|
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2017-06-25 21:21:41 +00:00
|
|
|
source "/opt/pihole/COL_TABLE"
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2017-01-29 01:32:42 +00:00
|
|
|
# is_repo() sourced from basic-install.sh
|
|
|
|
# make_repo() sourced from basic-install.sh
|
|
|
|
# update_repo() source from basic-install.sh
|
|
|
|
# getGitFiles() sourced from basic-install.sh
|
2016-11-02 05:19:40 +00:00
|
|
|
|
2016-12-24 14:19:39 +00:00
|
|
|
GitCheckUpdateAvail() {
|
|
|
|
local directory="${1}"
|
2017-01-29 01:38:14 +00:00
|
|
|
curdir=$PWD
|
2017-06-25 21:21:41 +00:00
|
|
|
cd "${directory}" || return
|
2016-12-24 14:19:39 +00:00
|
|
|
|
|
|
|
# Fetch latest changes in this repo
|
2016-12-25 00:18:58 +00:00
|
|
|
git fetch --quiet origin
|
2017-01-05 12:10:19 +00:00
|
|
|
|
|
|
|
# @ alone is a shortcut for HEAD. Older versions of git
|
|
|
|
# need @{0}
|
2017-06-25 21:21:41 +00:00
|
|
|
LOCAL="$("git rev-parse @{0}")"
|
2017-01-05 12:10:19 +00:00
|
|
|
|
|
|
|
# The suffix @{upstream} to a branchname
|
|
|
|
# (short form <branchname>@{u}) refers
|
|
|
|
# to the branch that the branch specified
|
|
|
|
# by branchname is set to build on top of#
|
|
|
|
# (configured with branch.<name>.remote and
|
|
|
|
# branch.<name>.merge). A missing branchname
|
|
|
|
# defaults to the current one.
|
2017-06-25 21:21:41 +00:00
|
|
|
REMOTE="$("git rev-parse @{upstream}")"
|
2016-12-24 14:19:39 +00:00
|
|
|
|
2017-01-05 12:10:19 +00:00
|
|
|
if [[ ${#LOCAL} == 0 ]]; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Error: Local revision could not be obtained, ask Pi-hole support."
|
|
|
|
echo -e " Additional debugging output:${COL_NC}"
|
2017-01-05 12:10:19 +00:00
|
|
|
git status
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
if [[ ${#REMOTE} == 0 ]]; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Error: Remote revision could not be obtained, ask Pi-hole support."
|
|
|
|
echo -e " Additional debugging output:${COL_NC}"
|
2017-01-05 12:10:19 +00:00
|
|
|
git status
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2017-01-29 01:00:02 +00:00
|
|
|
# Change back to original directory
|
2017-06-25 21:21:41 +00:00
|
|
|
cd "${curdir}" || exit
|
2017-01-05 12:10:19 +00:00
|
|
|
|
|
|
|
if [[ "${LOCAL}" != "${REMOTE}" ]]; then
|
2016-12-24 14:19:39 +00:00
|
|
|
# Local branch is behind remote branch -> Update
|
|
|
|
return 0
|
2016-12-24 14:32:25 +00:00
|
|
|
else
|
|
|
|
# Local branch is up-to-date or in a situation
|
|
|
|
# where this updater cannot be used (like on a
|
|
|
|
# branch that exists only locally)
|
|
|
|
return 1
|
2016-12-24 14:19:39 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-02-22 09:43:13 +00:00
|
|
|
FTLcheckUpdate() {
|
2017-06-25 21:21:41 +00:00
|
|
|
local FTLversion
|
|
|
|
FTLversion=$(/usr/bin/pihole-FTL tag)
|
|
|
|
local FTLlatesttag
|
|
|
|
FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n')
|
2017-02-22 09:43:13 +00:00
|
|
|
|
|
|
|
if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-11-02 08:12:02 +00:00
|
|
|
main() {
|
2016-11-02 18:01:50 +00:00
|
|
|
local pihole_version_current
|
|
|
|
local web_version_current
|
2017-06-25 21:21:41 +00:00
|
|
|
#shellcheck disable=1090,2154
|
2017-03-21 22:01:51 +00:00
|
|
|
source "${setupVars}"
|
2016-11-02 08:12:02 +00:00
|
|
|
|
2016-12-24 14:19:39 +00:00
|
|
|
#This is unlikely
|
2017-02-05 19:07:04 +00:00
|
|
|
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Critical Error: Core Pi-hole repo is missing from system!"
|
|
|
|
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
2016-11-02 19:09:33 +00:00
|
|
|
exit 1;
|
|
|
|
fi
|
2016-11-02 08:12:02 +00:00
|
|
|
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Checking for updates..."
|
2016-12-24 14:19:39 +00:00
|
|
|
|
2016-12-24 14:32:25 +00:00
|
|
|
if GitCheckUpdateAvail "${PI_HOLE_FILES_DIR}" ; then
|
|
|
|
core_update=true
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Pi-hole Core:\t${COL_YELLOW}update available${COL_NC}"
|
2016-12-24 14:40:31 +00:00
|
|
|
else
|
|
|
|
core_update=false
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Pi-hole Core:\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
2016-12-24 14:32:25 +00:00
|
|
|
fi
|
|
|
|
|
2017-02-22 09:43:13 +00:00
|
|
|
if FTLcheckUpdate ; then
|
|
|
|
FTL_update=true
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} FTL:\t\t${COL_YELLOW}update available${COL_NC}"
|
2017-02-22 09:43:13 +00:00
|
|
|
else
|
|
|
|
FTL_update=false
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} FTL:\t\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
2017-02-22 09:43:13 +00:00
|
|
|
fi
|
2017-06-25 21:21:41 +00:00
|
|
|
|
2017-06-04 10:40:57 +00:00
|
|
|
# Logic: Don't update FTL when there is a core update available
|
|
|
|
# since the core update will run the installer which will itself
|
|
|
|
# re-install (i.e. update) FTL
|
|
|
|
if ${FTL_update} && ! ${core_update}; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
2017-07-01 12:08:17 +00:00
|
|
|
echo -e " ${INFO} FTL out of date"
|
2017-02-22 09:43:13 +00:00
|
|
|
FTLdetect
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
2017-02-22 09:43:13 +00:00
|
|
|
fi
|
|
|
|
|
2017-02-05 19:07:04 +00:00
|
|
|
if [[ ${INSTALL_WEB} == true ]]; then
|
|
|
|
if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Critical Error: Web Admin repo is missing from system!"
|
|
|
|
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
2017-02-05 19:07:04 +00:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then
|
|
|
|
web_update=true
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Web Interface:\t${COL_YELLOW}update available${COL_NC}"
|
2017-02-05 19:07:04 +00:00
|
|
|
else
|
|
|
|
web_update=false
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Web Interface:\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
2017-02-05 19:07:04 +00:00
|
|
|
fi
|
2016-12-24 14:32:25 +00:00
|
|
|
|
2017-02-05 19:12:09 +00:00
|
|
|
# Logic
|
|
|
|
# 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 ! ${core_update} && ! ${web_update} ; then
|
2017-02-22 10:00:45 +00:00
|
|
|
if ! ${FTL_update} ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${TICK} Everything is up to date!"
|
2017-02-22 10:00:45 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2017-02-05 19:12:09 +00:00
|
|
|
|
|
|
|
elif ! ${core_update} && ${web_update} ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Pi-hole Web Admin files out of date"
|
2017-02-05 19:12:09 +00:00
|
|
|
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
|
|
|
|
2017-02-07 23:14:41 +00:00
|
|
|
elif ${core_update} && ! ${web_update} ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Pi-hole core files out of date"
|
2017-02-07 23:14:41 +00:00
|
|
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
2017-06-21 11:49:05 +00:00
|
|
|
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
2017-02-05 19:15:27 +00:00
|
|
|
|
2017-02-07 23:14:41 +00:00
|
|
|
elif ${core_update} && ${web_update} ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Updating Pi-hole core and web admin files"
|
2017-02-07 23:14:41 +00:00
|
|
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
2017-06-21 11:49:05 +00:00
|
|
|
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
2017-02-07 23:14:41 +00:00
|
|
|
else
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Update script has malfunctioned, fallthrough reached. Please contact support${COL_NC}"
|
2017-02-07 23:14:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-02-05 19:15:27 +00:00
|
|
|
else # Web Admin not installed, so only verify if core is up to date
|
2017-02-05 19:12:09 +00:00
|
|
|
if ! ${core_update}; then
|
2017-02-22 10:00:45 +00:00
|
|
|
if ! ${FTL_update} ; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Everything is up to date!"
|
2017-02-22 10:00:45 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2017-02-05 19:12:09 +00:00
|
|
|
else
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Pi-hole core files out of date"
|
2017-02-05 19:12:09 +00:00
|
|
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
2017-06-21 11:49:05 +00:00
|
|
|
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
2017-02-05 19:12:09 +00:00
|
|
|
fi
|
2016-11-02 13:41:51 +00:00
|
|
|
fi
|
2016-11-02 14:29:20 +00:00
|
|
|
|
2016-12-24 14:40:31 +00:00
|
|
|
if [[ "${web_update}" == true ]]; then
|
2017-02-05 19:15:27 +00:00
|
|
|
web_version_current="$(/usr/local/bin/pihole version --admin --current)"
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Web Admin version is now at ${web_version_current/* v/v}"
|
|
|
|
echo -e " ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
2017-02-05 19:15:27 +00:00
|
|
|
fi
|
2016-11-02 14:29:20 +00:00
|
|
|
|
2017-02-05 19:15:27 +00:00
|
|
|
if [[ "${core_update}" == true ]]; then
|
|
|
|
pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)"
|
2017-06-21 11:49:05 +00:00
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} Pi-hole version is now at ${pihole_version_current/* v/v}"
|
|
|
|
echo -e " ${INFO} If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'"
|
2017-02-05 19:15:27 +00:00
|
|
|
fi
|
2016-11-02 14:29:20 +00:00
|
|
|
|
2017-02-22 10:00:45 +00:00
|
|
|
if [[ ${FTL_update} == true ]]; then
|
2017-06-21 11:49:05 +00:00
|
|
|
FTL_version_current="$(/usr/bin/pihole-FTL tag)"
|
|
|
|
echo ""
|
|
|
|
echo -e " ${INFO} FTL version is now at ${FTL_version_current/* v/v}"
|
2017-02-22 10:00:45 +00:00
|
|
|
start_service pihole-FTL
|
|
|
|
enable_service pihole-FTL
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-11-02 14:29:20 +00:00
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
|
2016-11-02 08:12:02 +00:00
|
|
|
}
|
2016-11-02 07:51:38 +00:00
|
|
|
|
2016-11-02 08:12:02 +00:00
|
|
|
main
|