mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 22:00:17 +00:00
Complete overhaul of update logic. Moved to seperate script
This commit is contained in:
parent
ff5d5b97c3
commit
27d6e5d8cf
1 changed files with 121 additions and 58 deletions
|
@ -11,72 +11,135 @@
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
||||||
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
|
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
|
||||||
webInterfaceDir="/var/www/html/admin"
|
webInterfaceDir="/var/www/html/admin"
|
||||||
piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
|
piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
|
||||||
piholeFilesDir="/etc/.pihole"
|
piholeFilesDir="/etc/.pihole"
|
||||||
|
|
||||||
if [ ! -d "/etc/.pihole" ]; then #This is unlikely
|
spinner()
|
||||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
{
|
||||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
local pid=$1
|
||||||
exit 1;
|
local delay=0.50
|
||||||
fi
|
local spinstr='/-\|'
|
||||||
if [ ! -d "/var/www/html/admin" ]; then #This is unlikely
|
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
local temp=${spinstr#?}
|
||||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
printf " [%c] " "$spinstr"
|
||||||
exit 1;
|
local spinstr=${temp}${spinstr%"$temp"}
|
||||||
fi
|
sleep ${delay}
|
||||||
|
printf "\b\b\b\b\b\b"
|
||||||
|
done
|
||||||
|
printf " \b\b\b\b"
|
||||||
|
}
|
||||||
|
|
||||||
echo "::: Checking for updates..."
|
getGitFiles() {
|
||||||
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
# Setup git repos for directory and repository passed
|
||||||
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
# as arguments 1 and 2
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Checking for existing repository..."
|
||||||
|
if is_repo "${1}"; then
|
||||||
|
update_repo "${1}"
|
||||||
|
else
|
||||||
|
make_repo "${1}" "${2}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
is_repo() {
|
||||||
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
# Use git to check if directory is currently under VCS
|
||||||
|
echo -n "::: Checking $1 is a repo..."
|
||||||
|
cd "${1}" &> /dev/null || return 1
|
||||||
|
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1
|
||||||
|
}
|
||||||
|
|
||||||
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
make_repo() {
|
||||||
echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)"
|
# Remove the non-repod interface and clone the interface
|
||||||
echo ":::"
|
echo -n "::: Cloning $2 into $1..."
|
||||||
|
rm -rf "${1}"
|
||||||
|
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
|
||||||
|
echo " done!"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then
|
update_repo() {
|
||||||
echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}"
|
# Pull the latest commits
|
||||||
echo "::: No need to update!"
|
echo -n "::: Updating repo in $1..."
|
||||||
echo ":::"
|
cd "${1}" || exit 1
|
||||||
|
git stash -q > /dev/null & spinner $!
|
||||||
|
git pull -q > /dev/null & spinner $!
|
||||||
|
echo " done!"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ ${webVersion} == ${webVersionLatest} ]] ; then
|
if [ ! -d "/etc/.pihole" ]; then #This is unlikely
|
||||||
echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}"
|
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||||
echo "::: No need to update!"
|
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||||
echo ":::"
|
exit 1;
|
||||||
else
|
fi
|
||||||
echo "::: An Update is available for the Web Admin!"
|
if [ ! -d "/var/www/html/admin" ]; then #This is unlikely
|
||||||
echo ":::"
|
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||||
echo "::: Fetching latest changes from GitHub..."
|
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||||
# Update Git files for Core
|
exit 1;
|
||||||
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
|
fi
|
||||||
echo ":::"
|
|
||||||
echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}"
|
|
||||||
echo "::: See https://changes.pi-hole.net for details"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -n "::: An update is available for "
|
|
||||||
if [[ ${webVersion} == ${webVersionLatest} ]] ; then
|
|
||||||
echo " Pi-Hole!"
|
|
||||||
else
|
|
||||||
echo " Pi-Hole base files and the Web Admin. Both will be updated!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "::: Fetching latest changes from GitHub..."
|
echo "::: Checking for updates..."
|
||||||
# Update Git files for Core
|
piholeVersion=$(pihole -v -p -c)
|
||||||
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
piholeVersionLatest=$(pihole -v -p -l)
|
||||||
/etc/.pihole/automated\ install/basic-install.sh --unattended
|
|
||||||
|
|
||||||
echo ":::"
|
webVersion=$(pihole -v -a -c)
|
||||||
echo "::: Pi-hole has been updated to version ${piholeVersionLatest}"
|
webVersionLatest=$(pihole -v -a -l)
|
||||||
if [[ ${webVersion} != ${webVersionLatest} ]] ; then
|
|
||||||
echo "::: Web Admin has been updated to version ${webVersionLatest}"
|
|
||||||
fi
|
|
||||||
echo ":::"
|
|
||||||
echo "::: See https://changes.pi-hole.net for details"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||||
|
echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)"
|
||||||
|
echo ":::"
|
||||||
|
|
||||||
|
# Logic
|
||||||
|
# If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!):
|
||||||
|
# Update anyway
|
||||||
|
# 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 [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
|
||||||
|
echo "::: Everything is up to date!"
|
||||||
|
echo ""
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
|
||||||
|
echo "::: Pi-hole Web Admin files out of date"
|
||||||
|
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
|
||||||
|
echo ":::"
|
||||||
|
webVersion=$(pihole -v -a -c)
|
||||||
|
echo "::: Web Admin version is now at ${webVersion}"
|
||||||
|
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
|
||||||
|
echo "::: Pi-hole core files out of date"
|
||||||
|
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||||
|
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended
|
||||||
|
echo ":::"
|
||||||
|
piholeVersion=$(pihole -v -p -c)
|
||||||
|
echo "::: Pi-hole version is now at ${piholeVersion}"
|
||||||
|
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
|
||||||
|
echo "::: Updating Everything"
|
||||||
|
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||||
|
/etc/.pihole/automated\ install/basic-install.sh --unattended
|
||||||
|
webVersion=$(pihole -v -a -c)
|
||||||
|
piholeVersion=$(pihole -v -p -c)
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Pi-hole version is now at ${piholeVersion}"
|
||||||
|
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Pi-hole version is now at ${piholeVersion}"
|
||||||
|
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
|
||||||
|
echo ""
|
||||||
|
fi
|
Loading…
Reference in a new issue