mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 22:00:17 +00:00
Store versions as key/value pairs rather than space delimeted values
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
4cf3280500
commit
5421aad03e
3 changed files with 50 additions and 35 deletions
|
@ -41,54 +41,78 @@ function get_local_version() {
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
. /etc/pihole/setupVars.conf
|
. /etc/pihole/setupVars.conf
|
||||||
|
|
||||||
|
utilsfile="/opt/pihole/utils.sh"
|
||||||
|
source "${utilsfile}"
|
||||||
|
|
||||||
|
# Remove the below three legacy files if they exist
|
||||||
|
GITHUB_VERSION_FILE="/etc/pihole/GitHubVersions"
|
||||||
|
LOCAL_BRANCH_FILE="/etc/pihole/localbranches"
|
||||||
|
LOCAL_VERSION_FILE="/etc/pihole/localversions"
|
||||||
|
|
||||||
|
if [ -f "${GITHUB_VERSION_FILE}" ]; then
|
||||||
|
rm "${GITHUB_VERSION_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${LOCAL_BRANCH_FILE}" ]; then
|
||||||
|
rm "${LOCAL_BRANCH_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${LOCAL_VERSION_FILE}" ]; then
|
||||||
|
rm "${LOCAL_VERSION_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create new versions file if it does not exist
|
||||||
|
VERSION_FILE="/etc/pihole/versions"
|
||||||
|
|
||||||
|
if [ ! -f "${VERSION_FILE}" ]; then
|
||||||
|
touch "${VERSION_FILE}"
|
||||||
|
chmod 644 "${VERSION_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$2" == "remote" ]]; then
|
if [[ "$2" == "remote" ]]; then
|
||||||
|
|
||||||
if [[ "$3" == "reboot" ]]; then
|
if [[ "$3" == "reboot" ]]; then
|
||||||
sleep 30
|
sleep 30
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GITHUB_VERSION_FILE="/etc/pihole/GitHubVersions"
|
|
||||||
|
|
||||||
GITHUB_CORE_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null)")"
|
GITHUB_CORE_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null)")"
|
||||||
echo -n "${GITHUB_CORE_VERSION}" > "${GITHUB_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"
|
||||||
chmod 644 "${GITHUB_VERSION_FILE}"
|
|
||||||
|
|
||||||
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
||||||
GITHUB_WEB_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null)")"
|
GITHUB_WEB_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null)")"
|
||||||
echo -n " ${GITHUB_WEB_VERSION}" >> "${GITHUB_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GITHUB_FTL_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null)")"
|
GITHUB_FTL_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null)")"
|
||||||
echo -n " ${GITHUB_FTL_VERSION}" >> "${GITHUB_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}"
|
||||||
|
|
||||||
|
if [[ "${PIHOLE_DOCKER_TAG}" ]]; then
|
||||||
|
GITHUB_DOCKER_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null)")"
|
||||||
|
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}"
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
LOCAL_BRANCH_FILE="/etc/pihole/localbranches"
|
|
||||||
|
|
||||||
CORE_BRANCH="$(get_local_branch /etc/.pihole)"
|
CORE_BRANCH="$(get_local_branch /etc/.pihole)"
|
||||||
echo -n "${CORE_BRANCH}" > "${LOCAL_BRANCH_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}"
|
||||||
chmod 644 "${LOCAL_BRANCH_FILE}"
|
|
||||||
|
|
||||||
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
||||||
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
||||||
echo -n " ${WEB_BRANCH}" >> "${LOCAL_BRANCH_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FTL_BRANCH="$(pihole-FTL branch)"
|
FTL_BRANCH="$(pihole-FTL branch)"
|
||||||
echo -n " ${FTL_BRANCH}" >> "${LOCAL_BRANCH_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"
|
||||||
|
|
||||||
LOCAL_VERSION_FILE="/etc/pihole/localversions"
|
|
||||||
|
|
||||||
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
||||||
echo -n "${CORE_VERSION}" > "${LOCAL_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"
|
||||||
chmod 644 "${LOCAL_VERSION_FILE}"
|
|
||||||
|
|
||||||
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
|
||||||
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
||||||
echo -n " ${WEB_VERSION}" >> "${LOCAL_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FTL_VERSION="$(pihole-FTL version)"
|
FTL_VERSION="$(pihole-FTL version)"
|
||||||
echo -n " ${FTL_VERSION}" >> "${LOCAL_VERSION_FILE}"
|
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -90,16 +90,17 @@ getRemoteVersion(){
|
||||||
local version
|
local version
|
||||||
local cachedVersions
|
local cachedVersions
|
||||||
local arrCache
|
local arrCache
|
||||||
cachedVersions="/etc/pihole/GitHubVersions"
|
cachedVersions="/etc/pihole/versions"
|
||||||
|
|
||||||
#If the above file exists, then we can read from that. Prevents overuse of GitHub API
|
#If the above file exists, then we can read from that. Prevents overuse of GitHub API
|
||||||
if [[ -f "$cachedVersions" ]]; then
|
if [[ -f "$cachedVersions" ]]; then
|
||||||
IFS=' ' read -r -a arrCache < "$cachedVersions"
|
|
||||||
|
source "$cachedVersions"
|
||||||
|
|
||||||
case $daemon in
|
case $daemon in
|
||||||
"pi-hole" ) echo "${arrCache[0]}";;
|
"pi-hole" ) echo "${GITHUB_CORE_VERSION}";;
|
||||||
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[1]}";;
|
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";;
|
||||||
"FTL" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[2]}" || echo "${arrCache[1]}";;
|
"FTL" ) echo "${GITHUB_FTL_VERSION}";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -239,24 +239,14 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||||
'r', '/etc/pihole/dns-servers.conf', piholeuser)
|
'r', '/etc/pihole/dns-servers.conf', piholeuser)
|
||||||
actual_rc = host.run(check_servers).rc
|
actual_rc = host.run(check_servers).rc
|
||||||
assert exit_status_success == actual_rc
|
assert exit_status_success == actual_rc
|
||||||
# readable GitHubVersions
|
|
||||||
check_version = test_cmd.format(
|
|
||||||
'r', '/etc/pihole/GitHubVersions', piholeuser)
|
|
||||||
actual_rc = host.run(check_version).rc
|
|
||||||
assert exit_status_success == actual_rc
|
|
||||||
# readable install.log
|
# readable install.log
|
||||||
check_install = test_cmd.format(
|
check_install = test_cmd.format(
|
||||||
'r', '/etc/pihole/install.log', piholeuser)
|
'r', '/etc/pihole/install.log', piholeuser)
|
||||||
actual_rc = host.run(check_install).rc
|
actual_rc = host.run(check_install).rc
|
||||||
assert exit_status_success == actual_rc
|
assert exit_status_success == actual_rc
|
||||||
# readable localbranches
|
# readable versions
|
||||||
check_localbranch = test_cmd.format(
|
|
||||||
'r', '/etc/pihole/localbranches', piholeuser)
|
|
||||||
actual_rc = host.run(check_localbranch).rc
|
|
||||||
assert exit_status_success == actual_rc
|
|
||||||
# readable localversions
|
|
||||||
check_localversion = test_cmd.format(
|
check_localversion = test_cmd.format(
|
||||||
'r', '/etc/pihole/localversions', piholeuser)
|
'r', '/etc/pihole/versions', piholeuser)
|
||||||
actual_rc = host.run(check_localversion).rc
|
actual_rc = host.run(check_localversion).rc
|
||||||
assert exit_status_success == actual_rc
|
assert exit_status_success == actual_rc
|
||||||
# readable logrotate
|
# readable logrotate
|
||||||
|
|
Loading…
Reference in a new issue