-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,107 @@ | ||
#!/usr/bin/env bash | ||
|
||
# https://github.com/cloudflare/semver_bash/blob/master/semver.sh | ||
# Source: https://github.com/cloudflare/semver_bash/blob/master/semver.sh | ||
|
||
function semverParseInto() { | ||
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' | ||
#MAJOR | ||
eval $2=`echo $1 | sed -e "s#$RE#\1#"` | ||
#MINOR | ||
eval $3=`echo $1 | sed -e "s#$RE#\2#"` | ||
#MINOR | ||
eval $4=`echo $1 | sed -e "s#$RE#\3#"` | ||
#SPECIAL | ||
eval $5=`echo $1 | sed -e "s#$RE#\4#"` | ||
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' | ||
#MAJOR | ||
eval $2=$(echo $1 | sed -e "s#$RE#\1#") | ||
#MINOR | ||
eval $3=$(echo $1 | sed -e "s#$RE#\2#") | ||
#MINOR | ||
eval $4=$(echo $1 | sed -e "s#$RE#\3#") | ||
#SPECIAL | ||
eval $5=$(echo $1 | sed -e "s#$RE#\4#") | ||
} | ||
|
||
function semverEQ() { | ||
local MAJOR_A=0 | ||
local MINOR_A=0 | ||
local PATCH_A=0 | ||
local SPECIAL_A=0 | ||
local MAJOR_A=0 | ||
local MINOR_A=0 | ||
local PATCH_A=0 | ||
local SPECIAL_A=0 | ||
|
||
local MAJOR_B=0 | ||
local MINOR_B=0 | ||
local PATCH_B=0 | ||
local SPECIAL_B=0 | ||
local MAJOR_B=0 | ||
local MINOR_B=0 | ||
local PATCH_B=0 | ||
local SPECIAL_B=0 | ||
|
||
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A | ||
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B | ||
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A | ||
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B | ||
|
||
if [ $MAJOR_A -ne $MAJOR_B ]; then | ||
return 1 | ||
fi | ||
|
||
if [ $MINOR_A -ne $MINOR_B ]; then | ||
return 1 | ||
fi | ||
if [ $MAJOR_A -ne $MAJOR_B ]; then | ||
return 1 | ||
fi | ||
|
||
if [ $PATCH_A -ne $PATCH_B ]; then | ||
return 1 | ||
fi | ||
if [ $MINOR_A -ne $MINOR_B ]; then | ||
return 1 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then | ||
return 1 | ||
fi | ||
if [ $PATCH_A -ne $PATCH_B ]; then | ||
return 1 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then | ||
return 1 | ||
fi | ||
|
||
return 0 | ||
return 0 | ||
|
||
} | ||
|
||
function semverLT() { | ||
local MAJOR_A=0 | ||
local MINOR_A=0 | ||
local PATCH_A=0 | ||
local SPECIAL_A=0 | ||
|
||
local MAJOR_B=0 | ||
local MINOR_B=0 | ||
local PATCH_B=0 | ||
local SPECIAL_B=0 | ||
|
||
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A | ||
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B | ||
|
||
if [ $MAJOR_A -lt $MAJOR_B ]; then | ||
return 0 | ||
fi | ||
|
||
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then | ||
return 0 | ||
fi | ||
|
||
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then | ||
return 0 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then | ||
return 1 | ||
fi | ||
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then | ||
return 1 | ||
fi | ||
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then | ||
return 0 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then | ||
return 0 | ||
fi | ||
local MAJOR_A=0 | ||
local MINOR_A=0 | ||
local PATCH_A=0 | ||
local SPECIAL_A=0 | ||
|
||
local MAJOR_B=0 | ||
local MINOR_B=0 | ||
local PATCH_B=0 | ||
local SPECIAL_B=0 | ||
|
||
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A | ||
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B | ||
|
||
if [ $MAJOR_A -lt $MAJOR_B ]; then | ||
return 0 | ||
fi | ||
|
||
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then | ||
return 0 | ||
fi | ||
|
||
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then | ||
return 0 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then | ||
return 1 | ||
fi | ||
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]]; then | ||
return 1 | ||
fi | ||
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then | ||
return 0 | ||
fi | ||
|
||
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then | ||
return 0 | ||
fi | ||
|
||
return 1 | ||
|
||
} | ||
|
||
function semverGT() { | ||
semverEQ $1 $2 | ||
local EQ=$? | ||
semverEQ $1 $2 | ||
local EQ=$? | ||
|
||
semverLT $1 $2 | ||
local LT=$? | ||
semverLT $1 $2 | ||
local LT=$? | ||
|
||
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} |