mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 13:50:17 +00:00
complete overhaul of version script. Now with optional arguments!
This commit is contained in:
parent
29ad2496b6
commit
013d77488a
1 changed files with 79 additions and 12 deletions
|
@ -10,26 +10,93 @@
|
||||||
# the Free Software Foundation, either version 2 of the License, or
|
# the Free Software Foundation, either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# Flags:
|
||||||
|
latest=false
|
||||||
|
current=false
|
||||||
|
|
||||||
normalOutput(){
|
normalOutput(){
|
||||||
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||||
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
||||||
|
|
||||||
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/",$//')
|
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/",$//')
|
||||||
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
||||||
|
|
||||||
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
|
||||||
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
|
|
||||||
|
|
||||||
|
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||||
|
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webOutput(){
|
||||||
|
for var in "$@"
|
||||||
|
do
|
||||||
|
case "$var" in
|
||||||
|
"-l" | "--latest" ) latest=true;;
|
||||||
|
"-c" | "--current" ) current=true;;
|
||||||
|
* ) echo "::: Invalid Option!"; exit 1;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "${latest}" == true && "${current}" == false ]]; then
|
||||||
|
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
||||||
|
echo ${webVersionLatest}
|
||||||
|
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||||
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
||||||
|
echo ${webVersion}
|
||||||
|
else
|
||||||
|
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
||||||
|
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
coreOutput(){
|
||||||
|
for var in "$@"
|
||||||
|
do
|
||||||
|
case "$var" in
|
||||||
|
"-l" | "--latest" ) latest=true;;
|
||||||
|
"-c" | "--current" ) current=true;;
|
||||||
|
* ) echo "::: Invalid Option!"; exit 1;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "${latest}" == true && "${current}" == false ]]; then
|
||||||
|
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/",$//')
|
||||||
|
echo ${piholeVersionLatest}
|
||||||
|
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||||
|
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||||
|
echo ${piholeVersion}
|
||||||
|
else
|
||||||
|
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||||
|
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/",$//')
|
||||||
|
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
helpFunc()
|
||||||
|
{
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Show Pi-hole/Web Admin versions"
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Usage: pihole -v [ -a | -p ] [ -l | -c ]"
|
||||||
|
echo ":::"
|
||||||
|
echo "::: Options:"
|
||||||
|
echo "::: -a, --admin Show both current and latest versions of web admin"
|
||||||
|
echo "::: -p, --pihole Show both current and latest versions of Pi-hole core files"
|
||||||
|
echo "::: -l, --latest (Only after -a | -p) Return only latest version"
|
||||||
|
echo "::: -c, --current (Only after -a | -p) Return only current version"
|
||||||
|
echo "::: -h, --help Show this help dialog"
|
||||||
|
echo ":::"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $# = 0 ]]; then
|
||||||
|
normalOutput
|
||||||
|
fi
|
||||||
|
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
"-j" | "--json" ) outputJSON;;
|
"-a" | "--admin" ) shift; webOutput "$@";;
|
||||||
"-h" | "--help" ) displayHelp;;
|
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
||||||
* ) normalOutput;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
Loading…
Reference in a new issue