Skip to content

Commit

Permalink
Merge pull request #4875 from pi-hole/tweak/version-file
Browse files Browse the repository at this point in the history
Store versions as key/value pairs rather than space delimeted values
  • Loading branch information
PromoFaux committed Aug 23, 2022
2 parents 4cf3280 + a4b899c commit 597c045
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
46 changes: 28 additions & 18 deletions advanced/Scripts/updatecheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,64 @@ function get_local_version() {
# shellcheck disable=SC1091
. /etc/pihole/setupVars.conf

# Source the utils file
# shellcheck disable=SC1091
. /opt/pihole/utils.sh

# Remove the below three legacy files if they exist
rm -f "/etc/pihole/GitHubVersions"
rm -f "/etc/pihole/localbranches"
rm -f "/etc/pihole/localversions"

# Create new versions file if it does not exist
VERSION_FILE="/etc/pihole/versions"
touch "${VERSION_FILE}"
chmod 644 "${VERSION_FILE}"

if [[ "$2" == "remote" ]]; then

if [[ "$3" == "reboot" ]]; then
sleep 30
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)")"
echo -n "${GITHUB_CORE_VERSION}" > "${GITHUB_VERSION_FILE}"
chmod 644 "${GITHUB_VERSION_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"

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)")"
echo -n " ${GITHUB_WEB_VERSION}" >> "${GITHUB_VERSION_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
fi

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}"

else
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

LOCAL_BRANCH_FILE="/etc/pihole/localbranches"
else

CORE_BRANCH="$(get_local_branch /etc/.pihole)"
echo -n "${CORE_BRANCH}" > "${LOCAL_BRANCH_FILE}"
chmod 644 "${LOCAL_BRANCH_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}"

if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
echo -n " ${WEB_BRANCH}" >> "${LOCAL_BRANCH_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
fi

FTL_BRANCH="$(pihole-FTL branch)"
echo -n " ${FTL_BRANCH}" >> "${LOCAL_BRANCH_FILE}"

LOCAL_VERSION_FILE="/etc/pihole/localversions"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"

CORE_VERSION="$(get_local_version /etc/.pihole)"
echo -n "${CORE_VERSION}" > "${LOCAL_VERSION_FILE}"
chmod 644 "${LOCAL_VERSION_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"

if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
WEB_VERSION="$(get_local_version /var/www/html/admin)"
echo -n " ${WEB_VERSION}" >> "${LOCAL_VERSION_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
fi

FTL_VERSION="$(pihole-FTL version)"
echo -n " ${FTL_VERSION}" >> "${LOCAL_VERSION_FILE}"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}"

fi
13 changes: 7 additions & 6 deletions advanced/Scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ getRemoteVersion(){
local daemon="${1}"
local version
local cachedVersions
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 [[ -f "$cachedVersions" ]]; then
IFS=' ' read -r -a arrCache < "$cachedVersions"

# shellcheck disable=SC1090
. "$cachedVersions"

case $daemon in
"pi-hole" ) echo "${arrCache[0]}";;
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[1]}";;
"FTL" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[2]}" || echo "${arrCache[1]}";;
"pi-hole" ) echo "${GITHUB_CORE_VERSION}";;
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";;
"FTL" ) echo "${GITHUB_FTL_VERSION}";;
esac

return 0
Expand Down
14 changes: 2 additions & 12 deletions test/test_any_automated_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,14 @@ def test_installPihole_fresh_install_readableFiles(host):
'r', '/etc/pihole/dns-servers.conf', piholeuser)
actual_rc = host.run(check_servers).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
check_install = test_cmd.format(
'r', '/etc/pihole/install.log', piholeuser)
actual_rc = host.run(check_install).rc
assert exit_status_success == actual_rc
# readable localbranches
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
# readable versions
check_localversion = test_cmd.format(
'r', '/etc/pihole/localversions', piholeuser)
'r', '/etc/pihole/versions', piholeuser)
actual_rc = host.run(check_localversion).rc
assert exit_status_success == actual_rc
# readable logrotate
Expand Down

0 comments on commit 597c045

Please sign in to comment.