Merge pull request #50 from wasmerio/fix/make-install-script-posix-compliant

Refactor and remove bash-specific syntax
This commit is contained in:
Steve Akinyemi 2018-12-12 01:41:08 +01:00 committed by GitHub
commit 2c2d21044f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -304,39 +304,56 @@ wasmer_reset() {
# Example taken from # Example taken from
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash # https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
# wasmer_compareversions () {
# if [[ $1 == $2 ]]
# then
# echo "="
# return 0
# fi
# local IFS=.
# local i ver1=($1) ver2=($2)
# # fill empty fields in ver1 with zeros
# for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
# do
# ver1[i]=0
# done
# for ((i=0; i<${#ver1[@]}; i++))
# do
# if [[ -z ${ver2[i]} ]]
# then
# # fill empty fields in ver2 with zeros
# ver2[i]=0
# fi
# if ((10#${ver1[i]} > 10#${ver2[i]}))
# then
# echo ">"
# return 0
# fi
# if ((10#${ver1[i]} < 10#${ver2[i]}))
# then
# echo "<"
# return 0
# fi
# done
# echo "="
# return 0
# }
version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
# TODO: Does not support versions with characters in them yet. Won't work for wasmer_compareversions "1.4.5-rc4" "1.4.5-r5"
wasmer_compareversions () { wasmer_compareversions () {
if [[ $1 == $2 ]] WASMER_VERSION=$(version $1)
then WASMER_COMPARE=$(version $2)
if [ $WASMER_VERSION = $WASMER_COMPARE ]; then
echo "=" echo "="
return 0 elif [ $WASMER_VERSION -gt $WASMER_COMPARE ]; then
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
echo ">" echo ">"
return 0 elif [ $WASMER_VERSION -lt $WASMER_COMPARE ]; then
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
echo "<" echo "<"
return 0
fi fi
done
echo "="
return 0
} }
wasmer_download() { wasmer_download() {