2017-10-28 11:20:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2017-12-09 18:00:46 +00:00
|
|
|
# Checks for local or remote versions and branches
|
2017-10-28 11:20:02 +00:00
|
|
|
#
|
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
|
|
|
function get_local_branch() {
|
2018-07-20 20:24:05 +00:00
|
|
|
# Return active branch
|
|
|
|
cd "${1}" 2> /dev/null || return 1
|
|
|
|
git rev-parse --abbrev-ref HEAD || return 1
|
2017-10-28 11:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_local_version() {
|
2018-07-20 20:24:05 +00:00
|
|
|
# Return active branch
|
|
|
|
cd "${1}" 2> /dev/null || return 1
|
2019-05-07 12:54:25 +00:00
|
|
|
git describe --long --dirty --tags 2> /dev/null || return 1
|
2017-10-28 11:20:02 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 18:41:04 +00:00
|
|
|
# Source the setupvars config file
|
2018-09-30 18:45:04 +00:00
|
|
|
# shellcheck disable=SC1091
|
2018-09-30 18:41:04 +00:00
|
|
|
. /etc/pihole/setupVars.conf
|
|
|
|
|
2022-08-23 18:10:12 +00:00
|
|
|
# Source the utils file
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. /opt/pihole/utils.sh
|
2022-08-22 17:53:46 +00:00
|
|
|
|
|
|
|
# Remove the below three legacy files if they exist
|
2022-08-23 18:10:12 +00:00
|
|
|
rm -f "/etc/pihole/GitHubVersions"
|
|
|
|
rm -f "/etc/pihole/localbranches"
|
|
|
|
rm -f "/etc/pihole/localversions"
|
2022-08-22 17:53:46 +00:00
|
|
|
|
|
|
|
# Create new versions file if it does not exist
|
|
|
|
VERSION_FILE="/etc/pihole/versions"
|
2022-08-23 18:10:12 +00:00
|
|
|
touch "${VERSION_FILE}"
|
|
|
|
chmod 644 "${VERSION_FILE}"
|
2022-08-22 17:53:46 +00:00
|
|
|
|
2017-12-09 18:00:46 +00:00
|
|
|
if [[ "$2" == "remote" ]]; then
|
|
|
|
|
2018-07-20 20:24:05 +00:00
|
|
|
if [[ "$3" == "reboot" ]]; then
|
|
|
|
sleep 30
|
|
|
|
fi
|
2017-12-21 11:37:09 +00:00
|
|
|
|
2022-08-24 19:44:29 +00:00
|
|
|
GITHUB_CORE_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2018-09-30 18:41:04 +00:00
|
|
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
2022-08-24 19:44:29 +00:00
|
|
|
GITHUB_WEB_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
|
2018-09-30 18:41:04 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-24 19:44:29 +00:00
|
|
|
GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2022-08-22 17:53:46 +00:00
|
|
|
if [[ "${PIHOLE_DOCKER_TAG}" ]]; then
|
2022-08-24 19:44:29 +00:00
|
|
|
GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}"
|
|
|
|
fi
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2022-08-22 17:53:46 +00:00
|
|
|
else
|
2018-09-30 18:41:04 +00:00
|
|
|
|
2018-07-20 20:24:05 +00:00
|
|
|
CORE_BRANCH="$(get_local_branch /etc/.pihole)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}"
|
2018-09-30 18:41:04 +00:00
|
|
|
|
|
|
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
|
|
|
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
|
2018-09-30 18:41:04 +00:00
|
|
|
fi
|
|
|
|
|
2018-07-20 20:24:05 +00:00
|
|
|
FTL_BRANCH="$(pihole-FTL branch)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2018-07-20 20:24:05 +00:00
|
|
|
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2018-09-30 18:41:04 +00:00
|
|
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
|
|
|
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
|
2018-09-30 18:41:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
FTL_VERSION="$(pihole-FTL version)"
|
2022-08-22 17:53:46 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}"
|
2017-10-28 11:20:02 +00:00
|
|
|
|
2017-12-09 18:00:46 +00:00
|
|
|
fi
|