Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Warner <me@adamwarner.co.uk>2020-05-10 21:07:53 +0300
committerGitHub <noreply@github.com>2020-05-10 21:07:53 +0300
commit4d25f695267590b61a4061f9bb43448005d99b85 (patch)
treeee8bbc96efe66313c92e06b1a3376599fbf909a7 /advanced/Scripts/version.sh
parent9e490775ff3b20f378acc9db7cec2ae6023fff7f (diff)
parente728d7f76199df35377c06547b1842101db7e0db (diff)
Merge pull request #3321 from pi-hole/release/v5.0v5.0
Pi-hole core v5.0
Diffstat (limited to 'advanced/Scripts/version.sh')
-rwxr-xr-xadvanced/Scripts/version.sh51
1 files changed, 46 insertions, 5 deletions
diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh
index f6d4d344..d2c41cba 100755
--- a/advanced/Scripts/version.sh
+++ b/advanced/Scripts/version.sh
@@ -84,6 +84,21 @@ getRemoteVersion(){
# Get the version from the remote origin
local daemon="${1}"
local version
+ local cachedVersions
+ local arrCache
+ cachedVersions="/etc/pihole/GitHubVersions"
+
+ #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"
+ case $daemon in
+ "pi-hole" ) echo "${arrCache[0]}";;
+ "AdminLTE" ) echo "${arrCache[1]}";;
+ "FTL" ) echo "${arrCache[2]}";;
+ esac
+
+ return 0
+ fi
version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \
awk -F: '$1 ~/tag_name/ { print $2 }' | \
@@ -97,22 +112,48 @@ getRemoteVersion(){
return 0
}
+getLocalBranch(){
+ # Get the checked out branch of the local directory
+ local directory="${1}"
+ local branch
+
+ # Local FTL btranch is stored in /etc/pihole/ftlbranch
+ if [[ "$1" == "FTL" ]]; then
+ branch="$(pihole-FTL branch)"
+ else
+ cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
+ branch=$(git rev-parse --abbrev-ref HEAD || echo "$DEFAULT")
+ fi
+ if [[ ! "${branch}" =~ ^v ]]; then
+ if [[ "${branch}" == "master" ]]; then
+ echo ""
+ elif [[ "${branch}" == "HEAD" ]]; then
+ echo "in detached HEAD state at "
+ else
+ echo "${branch} "
+ fi
+ else
+ # Branch started in "v"
+ echo "release "
+ fi
+ return 0
+}
+
versionOutput() {
[[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR
[[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR
[[ "$1" == "FTL" ]] && GITDIR="FTL"
- [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR)
+ [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) && branch=$(getLocalBranch $GITDIR)
[[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1")
if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then
- [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR")
+ [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR") && branch=$(getLocalBranch $GITDIR)
[[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)")
fi
-
if [[ -n "$current" ]] && [[ -n "$latest" ]]; then
- output="${1^} version is $current (Latest: $latest)"
+ output="${1^} version is $branch$current (Latest: $latest)"
elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then
- output="Current ${1^} version is $current"
+ output="Current ${1^} version is $branch$current."
elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then
output="Latest ${1^} version is $latest"
elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then