Skip to content

Commit

Permalink
fix: compare prebuild image version before cp poa scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu committed May 28, 2021
1 parent 2a15b8e commit a919982
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ install:
# if manual build clerkb for POA
if [ "$(MANUAL_BUILD_CLERKB)" = true ] ; then \
make rebuild-poa-scripts ; \
elif [ "$(DOCKER_PREBUILD_IMAGE_TAG)" > "v0.2.4" ]; then \
make copy-poa-scripts-from-docker ; \
else "prebuild image version is lower than v0.2.5, there is no poa scripts in docker. use poa scripts in config folder. do nothing." ; \
else \
source ./gw_util.sh && copy_poa_scripts_from_docker_or_abort ;\
fi

init:
Expand Down
60 changes: 60 additions & 0 deletions gw_util.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# if docker-prebuild-image version is lower than this, then it is legacy
# which doesnt have poa scripts built-in.
LEGACY_PREBUILD_IMAGE_VERSION=0.2.4

# how to use:
# parese_toml_with_section file_path section_name key_name
Expand Down Expand Up @@ -262,3 +265,60 @@ isGodwokenRpcRunning(){
return 1
fi
}

version_comp () {
if [[ $1 == $2 ]]
then
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
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

test_version_comp () {
verion_comp $1 $2
case $? in
0) op='=';;
1) op='>';;
2) op='<';;
esac
if [[ $op != $3 ]]
then
echo "FAIL: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'"
else
echo "Pass: '$1 $op $2'"
fi
}

copy_poa_scripts_from_docker_or_abort(){
version_comp "${DOCKER_PREBUILD_IMAGE_TAG//v}" $LEGACY_PREBUILD_IMAGE_VERSION
# if version large than legacy_version
if [ "$?" = 1 ]; then
echo "copy poa scripts from docker image..."
make copy-poa-scripts-from-docker
else
echo "prebuild image version is lower than v0.2.5, there is no poa scripts in docker. instead, use poa scripts in config folder. do nothing."
fi
}

0 comments on commit a919982

Please sign in to comment.