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() {
|
2022-10-06 12:17:28 +00:00
|
|
|
# Return active version
|
2018-07-20 20:24:05 +00:00
|
|
|
cd "${1}" 2> /dev/null || return 1
|
2022-11-14 20:39:34 +00:00
|
|
|
git describe --tags --always 2> /dev/null || return 1
|
2017-10-28 11:20:02 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:17:28 +00:00
|
|
|
function get_local_hash() {
|
|
|
|
cd "${1}" 2> /dev/null || return 1
|
2022-11-14 22:51:39 +00:00
|
|
|
git rev-parse --short=8 HEAD || return 1
|
2022-10-06 12:17:28 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 21:13:25 +00:00
|
|
|
function get_remote_version() {
|
|
|
|
curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:17:28 +00:00
|
|
|
|
|
|
|
function get_remote_hash(){
|
2022-11-14 22:09:26 +00:00
|
|
|
git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1
|
2022-10-06 12:17:28 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
# Source the utils file for addOrEditKeyValPair()
|
2022-08-23 18:10:12 +00:00
|
|
|
# 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-10-14 11:18:12 +00:00
|
|
|
touch "${VERSION_FILE}"
|
|
|
|
chmod 644 "${VERSION_FILE}"
|
2022-09-25 14:51:09 +00:00
|
|
|
|
2022-09-19 21:01:05 +00:00
|
|
|
# if /pihole.docker.tag file exists, we will use it's value later in this script
|
2022-09-25 14:51:09 +00:00
|
|
|
DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null)
|
|
|
|
regex='^([0-9]+\.){1,2}(\*|[0-9]+)(-.*)?$|(^nightly$)|(^dev.*$)'
|
|
|
|
if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then
|
|
|
|
# DOCKER_TAG does not match the pattern (see https://regex101.com/r/RsENuz/1), so unset it.
|
|
|
|
unset DOCKER_TAG
|
|
|
|
fi
|
2022-08-22 17:53:46 +00:00
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
# used in cronjob
|
|
|
|
if [[ "$1" == "reboot" ]]; then
|
2018-07-20 20:24:05 +00:00
|
|
|
sleep 30
|
2022-10-06 10:36:17 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
# get Core versions
|
|
|
|
|
|
|
|
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"
|
2017-12-21 11:37:09 +00:00
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
CORE_BRANCH="$(get_local_branch /etc/.pihole)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2022-10-06 12:17:28 +00:00
|
|
|
CORE_HASH="$(get_local_hash /etc/.pihole)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}"
|
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
GITHUB_CORE_VERSION="$(get_remote_version pi-hole)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"
|
2018-09-30 18:41:04 +00:00
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2022-10-06 12:17:28 +00:00
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
# get Web versions
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2023-02-05 18:39:48 +00:00
|
|
|
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
|
2017-12-09 18:00:46 +00:00
|
|
|
|
2023-02-05 18:39:48 +00:00
|
|
|
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
|
2018-09-30 18:41:04 +00:00
|
|
|
|
2023-02-05 18:39:48 +00:00
|
|
|
WEB_HASH="$(get_local_hash /var/www/html/admin)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}"
|
2022-10-06 12:17:28 +00:00
|
|
|
|
2023-10-08 13:09:47 +00:00
|
|
|
GITHUB_WEB_VERSION="$(get_remote_version web)"
|
2023-02-05 18:39:48 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
|
2022-10-06 12:17:28 +00:00
|
|
|
|
2023-10-08 13:09:47 +00:00
|
|
|
GITHUB_WEB_HASH="$(get_remote_hash web "${WEB_BRANCH}")"
|
2023-02-05 18:39:48 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}"
|
2017-10-28 11:20:02 +00:00
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
# get FTL versions
|
|
|
|
|
|
|
|
FTL_VERSION="$(pihole-FTL version)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}"
|
|
|
|
|
|
|
|
FTL_BRANCH="$(pihole-FTL branch)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"
|
|
|
|
|
2022-11-14 22:09:26 +00:00
|
|
|
FTL_HASH="$(pihole-FTL --hash)"
|
2022-10-14 11:18:12 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}"
|
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
GITHUB_FTL_VERSION="$(get_remote_version FTL)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}"
|
2022-09-14 21:38:41 +00:00
|
|
|
|
2022-10-06 12:17:28 +00:00
|
|
|
GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}"
|
|
|
|
|
2022-10-14 11:18:12 +00:00
|
|
|
|
|
|
|
# get Docker versions
|
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
if [[ "${DOCKER_TAG}" ]]; then
|
2022-10-14 11:18:12 +00:00
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}"
|
|
|
|
|
2022-10-06 10:36:17 +00:00
|
|
|
GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)"
|
|
|
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}"
|
2017-12-09 18:00:46 +00:00
|
|
|
fi
|