Add version compare function to setup/index.txt

Okay Ivan, you can "I told you so" now.  I didn't see any major gotchas
to changing the version and was SURE there'd be no reason to write the
convoluted comparison function until after everything was nicely redone
and restructured and whatnot.  Fortunately I only need it in the main
script for now, and will hopefully very soon be able to just load it
from a common function file and use it where needed.

I still don't regret doing it, but all the work I had to do in order to
make sure I didn't screw it up (or rather that I fixed it after screwing
it up) are totally on me.
This commit is contained in:
T. Joseph Carter 2016-10-27 10:57:41 -07:00
parent b60fd31d60
commit 85d30152f2
2 changed files with 63 additions and 3 deletions

View File

@ -49,7 +49,7 @@ debianName=$(lsb_release -cs)
if [[ -f /usr/local/etc/A2SERVER-version ]]; then
read a2sVersion </usr/local/etc/A2SERVER-version
fi
if [[ "$a2sVersion" != *.*.* || "$a2sVersion" -lt 101 ]]; then
if [[ "$a2sVersion" != *.*.* && "$a2sVersion" -lt 101 ]]; then
echo "A2SERVER: Installing Netatalk (this will take a while)..."
# stop Netatalk and samba if running (during upgrade)
if [[ $(ps --no-headers -C afpd) ]]; then

View File

@ -53,6 +53,66 @@ fi
echo "A2SERVER version available: $a2serverVersion"
echo "A2SERVER version installed: ${installedVersion:=None}"
function a2sCmpInstalled() {
local iMajor iMinor iRev
local cMajor cMinor cRev
[[ -z "$installedVersion" ]] && return 0 # No, not installed
[[ -z "$1" ]] && return 1
iMajor=${installedVersion%%.*}
iMinor=${installedVersion#*.}
iMinor=${iMinor%%.*}
iRev=${installedVersion##*.}
cMajor=${2%%.*}
cMinor=${2#*.}
cMinor=${cMinor%%.*}
cRev=${2##*.}
case "$1" in
lt|le)
if [[ "$iMajor" -lt "$cMajor" ]]; then
return 0
elif [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -lt "$cMinor" ]]; then
return 0
elif [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -le "$cRev" ]]; then
if [[ "$1" == "le" || "$iRev" -lt "$cRev" ]]; then
return 0
fi
fi
fi
fi
;;
gt|ge)
if [[ "$iMajor" -gt "$cMajor" ]]; then
return 0
elif [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -gt "$cMinor" ]]; then
return 0
elif [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -ge "$cRev" ]]; then
if [[ "$1" == "ge" || "$iRev" -gt "$cRev" ]]; then
return 0
fi
fi
fi
fi
;;
eq)
if [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -eq "$cRev" ]]; then
return 0
fi
fi
fi
;;
esac
return 1
}
echo
[[ $scriptURL != *"ivanx.com"* && $scriptURL != *"raw.githubusercontent.com/RasppleII/a2server"* ]] && echo "Using script URL: $scriptURL"
[[ $binaryURL != *"ivanx.com"* ]] && echo "Using binary URL: $binaryURL"
@ -132,7 +192,7 @@ if [[ $updateRasppleII ]]; then
fi
fi
if [[ -f /usr/local/etc/A2SERVER-version && $(head -c 3 /usr/local/etc/A2SERVER-version) -lt 110 ]]; then
if a2sCmpInstalled lt 1.1.0; then
echo
echo "WARNING: The current A2SERVER installer scripts haven't been tested for"
echo "updating the earlier version of A2SERVER that you have. A fresh install"
@ -143,7 +203,7 @@ fi
a2server_update=0
doSetup=1
if [[ -f /usr/local/etc/A2SERVER-version && $(head -c 3 /usr/local/etc/A2SERVER-version) -lt 150 ]]; then
if a2sCmpInstalled lt 1.5.0; then
a2server_update=1
fi