unified comparison with '=='

master
Martin Scheidt 2022-03-07 11:40:23 +01:00
parent b970ff7357
commit 4d6d5a2cdd
1 changed files with 53 additions and 53 deletions

106
build.sh
View File

@ -71,7 +71,7 @@ process_arguments() {
print_usage print_usage
exit 1 exit 1
fi fi
if [ ${1:0:1} = "-" ]; then if [ ${1:0:1} == "-" ]; then
print_usage print_usage
exit 1 exit 1
fi fi
@ -93,7 +93,7 @@ COLOR_RESET="\033[0;m"
## -- cross platform helpers ## -- cross platform helpers
if [ "`echo -n`" = "-n" ]; then if [ "`echo -n`" == "-n" ]; then
n=""; c="\c" n=""; c="\c"
else else
n="-n"; c="" n="-n"; c=""
@ -117,8 +117,8 @@ check_zip() {
# check for zip # check for zip
STATUS=0 STATUS=0
command -v zip >/dev/null 2>&1 || STATUS=1 command -v zip >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "zip found" echo "zip found"
fi fi
return 0 return 0
@ -134,7 +134,7 @@ check_version_number() {
# loop condition - test format of $VERSION_STR: # loop condition - test format of $VERSION_STR:
echo "$VERSION_STR" | egrep -q "v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)?" && break; echo "$VERSION_STR" | egrep -q "v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)?" && break;
# loop test # loop test
if [ "$BATCHMODE" = 0 ]; then if [ "$BATCHMODE" == 0 ]; then
echo "${RED}Your version '$VERSION_STR' has not the correct format!${COLOR_RESET}" echo "${RED}Your version '$VERSION_STR' has not the correct format!${COLOR_RESET}"
echo $n "Please specify as Semantic Versioning ( e.g. v1.0.0 ): $c" echo $n "Please specify as Semantic Versioning ( e.g. v1.0.0 ): $c"
read VERSION_STR read VERSION_STR
@ -152,8 +152,8 @@ check_versionhistory() {
# check if $VERSION is present in doc/versionhistory.tex # check if $VERSION is present in doc/versionhistory.tex
STATUS=0 STATUS=0
grep -qs "vhEntry{$VERSION_NUM" doc/versionhistory.tex || STATUS=1 grep -qs "vhEntry{$VERSION_NUM" doc/versionhistory.tex || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM is present in versionhistory.tex." echo "Version $VERSION_NUM is present in versionhistory.tex."
fi fi
return 0 return 0
@ -168,8 +168,8 @@ check_changelog() {
# check if $VERSION is present in CHANGELOG.md # check if $VERSION is present in CHANGELOG.md
STATUS=0 STATUS=0
grep -qs "Version \[$VERSION_NUM\]" CHANGELOG.md || STATUS=1 grep -qs "Version \[$VERSION_NUM\]" CHANGELOG.md || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM is present in CHANGELOG.md." echo "Version $VERSION_NUM is present in CHANGELOG.md."
fi fi
return 0 return 0
@ -187,10 +187,10 @@ check_date() {
DATEISO_1=$(echo $LINE_1 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])') DATEISO_1=$(echo $LINE_1 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
DATEISO_2=$(echo $LINE_2 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])') DATEISO_2=$(echo $LINE_2 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
if [ $DATEISO_1 = $DATEISO_2 ]; then if [ $DATEISO_1 == $DATEISO_2 ]; then
# DATE=$(date "+%Y-%m-%d") # DATE=$(date "+%Y-%m-%d")
DATE="$DATEISO_1" DATE="$DATEISO_1"
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "The date $DATE was extracted from versionhistory.tex and CHANGELOG.md." echo "The date $DATE was extracted from versionhistory.tex and CHANGELOG.md."
fi fi
return 0 return 0
@ -206,8 +206,8 @@ check_url1() {
STATUS=0 STATUS=0
LINE=$(grep "\[$VERSION_NUM\]: https://" CHANGELOG.md) LINE=$(grep "\[$VERSION_NUM\]: https://" CHANGELOG.md)
echo $LINE | grep -qs "...$VERSION_STR" || STATUS=1 echo $LINE | grep -qs "...$VERSION_STR" || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM URL is present in CHANGELOG.md." echo "Version $VERSION_NUM URL is present in CHANGELOG.md."
fi fi
return 0 return 0
@ -223,8 +223,8 @@ check_url2() {
STATUS=0 STATUS=0
LINE=$(grep "\[Unreleased\]: https://" CHANGELOG.md) LINE=$(grep "\[Unreleased\]: https://" CHANGELOG.md)
echo $LINE | grep -qs "/$VERSION_STR..." || STATUS=1 echo $LINE | grep -qs "/$VERSION_STR..." || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "The URL for [Unreleased] was also updated in CHANGELOG.md! Thx!" echo "The URL for [Unreleased] was also updated in CHANGELOG.md! Thx!"
fi fi
return 0 return 0
@ -251,7 +251,7 @@ check_url2() {
} }
create_release() { create_release() {
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to create a release for the version $VERSION_NUM?" echo "Do you wish to create a release for the version $VERSION_NUM?"
echo $n "(y/n) $c" echo $n "(y/n) $c"
@ -268,7 +268,7 @@ create_release() {
## create backup-file und update VERSIONDATE in tikz-trackschematic.sty ## create backup-file und update VERSIONDATE in tikz-trackschematic.sty
sed -i".backup" -e"s/%\[VERSIONDATE/\[$DATE $VERSION_STR/g" src/tikz-trackschematic.sty sed -i".backup" -e"s/%\[VERSIONDATE/\[$DATE $VERSION_STR/g" src/tikz-trackschematic.sty
sedi "/%%\[SCRIPT\]/d" src/tikz-trackschematic.sty sedi "/%%\[SCRIPT\]/d" src/tikz-trackschematic.sty
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Updated version in src/tikz-trackschematic.sty" echo "Updated version in src/tikz-trackschematic.sty"
fi fi
@ -295,7 +295,7 @@ create_release() {
mkdir $TMP/tikz-trackschematic-snippets mkdir $TMP/tikz-trackschematic-snippets
cp -R doc/examples/* $TMP/tikz-trackschematic-examples/ cp -R doc/examples/* $TMP/tikz-trackschematic-examples/
cp -R doc/snippets/* $TMP/tikz-trackschematic-snippets/ cp -R doc/snippets/* $TMP/tikz-trackschematic-snippets/
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "copied documentation" echo "copied documentation"
fi fi
@ -307,12 +307,12 @@ create_release() {
cp $SRC $TMP/ cp $SRC $TMP/
fi fi
done done
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "copied src-files" echo "copied src-files"
fi fi
# zip package # zip package
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
zip -r $RELEASE.zip $TMP/* zip -r $RELEASE.zip $TMP/*
echo "compressed the release in $RELEASE.zip" echo "compressed the release in $RELEASE.zip"
else else
@ -324,13 +324,13 @@ create_release() {
rm -rf $TMP rm -rf $TMP
# undo changes to tikz-trackschematic.sty by sed # undo changes to tikz-trackschematic.sty by sed
mv src/tikz-trackschematic.sty.backup src/tikz-trackschematic.sty mv src/tikz-trackschematic.sty.backup src/tikz-trackschematic.sty
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "clean up done!" echo "clean up done!"
fi fi
} }
create_release_notes() { create_release_notes() {
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to create a release notes for the version $VERSION_NUM?" echo "Do you wish to create a release notes for the version $VERSION_NUM?"
echo $n "(y/n) $c" echo $n "(y/n) $c"
@ -365,22 +365,22 @@ check_sudo() {
# checks if sudo is available # checks if sudo is available
rootrun="" rootrun=""
# If we are root, we do note require sudo # If we are root, we do note require sudo
if [ "$EUID" = 0 ]; then if [ "$EUID" == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "you are root" echo "you are root"
fi fi
return 0 return 0
fi fi
if sudo -v >/dev/null 2>&1; then if sudo -v >/dev/null 2>&1; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "sudo ok" echo "sudo ok"
fi fi
rootrun="sudo" rootrun="sudo"
else else
echo "sudo failed" echo "sudo failed"
# Check if user is root (might be unnecessary) # Check if user is root (might be unnecessary)
if ! [ $(id -u) = 0 ]; then if ! [ $(id -u) == 0 ]; then
echo "This script must be run as root" 1>&2 echo "This script must be run as root" 1>&2
exit 1 exit 1
fi fi
@ -392,8 +392,8 @@ check_texlive() {
STATUS=0 STATUS=0
command -v kpsewhich >/dev/null 2>&1 || STATUS=1 command -v kpsewhich >/dev/null 2>&1 || STATUS=1
command -v mktexlsr >/dev/null 2>&1 || STATUS=1 command -v mktexlsr >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "kpsewhich and mktexlsr found" echo "kpsewhich and mktexlsr found"
fi fi
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL) TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
@ -409,8 +409,8 @@ check_pdflatex() {
# check for pdflatex # check for pdflatex
STATUS=0 STATUS=0
command -v pdflatex >/dev/null 2>&1 || STATUS=1 command -v pdflatex >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "pdflatex found" echo "pdflatex found"
fi fi
return 0 return 0
@ -428,8 +428,8 @@ check_trackschematic() {
DEVDIR="tex/latex/local/tikz-trackschematic-dev" DEVDIR="tex/latex/local/tikz-trackschematic-dev"
ls $TEXMFLOCAL/$DEVDIR/tikz-trackschematic-dev.sty >> /dev/null 2>&1 || STATUS=1 ls $TEXMFLOCAL/$DEVDIR/tikz-trackschematic-dev.sty >> /dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "tikz-trackschematic-dev found" echo "tikz-trackschematic-dev found"
fi fi
return 0 return 0
@ -444,8 +444,8 @@ check_imagemagick() {
# check for ImageMagick/compare # check for ImageMagick/compare
STATUS=0 STATUS=0
command -v compare >/dev/null 2>&1 || STATUS=1 command -v compare >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "compare found" echo "compare found"
fi fi
return 0 return 0
@ -467,7 +467,7 @@ run_test_cases() {
# Start with an empty List: # Start with an empty List:
FAILED="" FAILED=""
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "===========" echo "==========="
echo "Comparison of the expected appearance with the freshly created." echo "Comparison of the expected appearance with the freshly created."
echo "-----------" echo "-----------"
@ -479,7 +479,7 @@ run_test_cases() {
NAME=${FILE%.*} # remove extension NAME=${FILE%.*} # remove extension
ADD_TO_LIST=0 ADD_TO_LIST=0
# #
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "$NAME test:" echo "$NAME test:"
fi fi
# #
@ -495,8 +495,8 @@ run_test_cases() {
# awk "NR>$TOP&&NR<$BOTTOM" .tex/${NAME}.log > .tex/${NAME}.statistics.log # awk "NR>$TOP&&NR<$BOTTOM" .tex/${NAME}.log > .tex/${NAME}.statistics.log
memory_usage=$(grep "words of memory out of" .tex/${NAME}.log | cut -d " " -f2) memory_usage=$(grep "words of memory out of" .tex/${NAME}.log | cut -d " " -f2)
memory_usage=$(($memory_usage/1000)) memory_usage=$(($memory_usage/1000))
if [ $exit_code_pdflatex = 0 ]; then if [ $exit_code_pdflatex == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo $n " - ${GREEN}build succesful${COLOR_RESET}: $c" echo $n " - ${GREEN}build succesful${COLOR_RESET}: $c"
echo "${memory_usage}k of memory used." echo "${memory_usage}k of memory used."
# cat .tex/${NAME}.statistics.log # cat .tex/${NAME}.statistics.log
@ -504,7 +504,7 @@ run_test_cases() {
else else
STATUS=1 STATUS=1
ADD_TO_LIST=1 ADD_TO_LIST=1
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${RED}build failed${COLOR_RESET}." echo " - ${RED}build failed${COLOR_RESET}."
fi fi
fi fi
@ -526,19 +526,19 @@ run_test_cases() {
# #
EXIT_CODE=0 EXIT_CODE=0
compare -metric RMSE -colorspace RGB .tex/${NAME}.pdf ${NAME}_expected.pdf NULL: >> /dev/null 2>&1 || EXIT_CODE=1 compare -metric RMSE -colorspace RGB .tex/${NAME}.pdf ${NAME}_expected.pdf NULL: >> /dev/null 2>&1 || EXIT_CODE=1
if [ $EXIT_CODE = 0 ]; then if [ $EXIT_CODE == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${GREEN}comparison succesful${COLOR_RESET}." echo " - ${GREEN}comparison succesful${COLOR_RESET}."
fi fi
else else
STATUS=1 STATUS=1
ADD_TO_LIST=1 ADD_TO_LIST=1
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${RED}comparison failed${COLOR_RESET}." echo " - ${RED}comparison failed${COLOR_RESET}."
fi fi
fi fi
## if a test failed add to list ## if a test failed add to list
if [ $ADD_TO_LIST = 1 ]; then if [ $ADD_TO_LIST == 1 ]; then
if [ -z "$FAILED" ]; then if [ -z "$FAILED" ]; then
# first item # first item
FAILED="$NAME" FAILED="$NAME"
@ -548,14 +548,14 @@ run_test_cases() {
fi fi
done done
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "-----------" echo "-----------"
echo "${GREEN}All tests passed!${COLOR_RESET}" echo "${GREEN}All tests passed!${COLOR_RESET}"
fi fi
exit 0 exit 0
else else
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "-----------" echo "-----------"
echo "${RED}The following tests failed: ${FAILED}!${COLOR_RESET}" echo "${RED}The following tests failed: ${FAILED}!${COLOR_RESET}"
else else
@ -569,7 +569,7 @@ link_dev_files() {
# destination folder inside the TeX Live installation # destination folder inside the TeX Live installation
DEVDIR="tex/latex/local/tikz-trackschematic-dev" DEVDIR="tex/latex/local/tikz-trackschematic-dev"
PROJECTDIR=$(pwd -P) PROJECTDIR=$(pwd -P)
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to link this package from" echo "Do you wish to link this package from"
echo "$PROJECTDIR/src to" echo "$PROJECTDIR/src to"
@ -598,7 +598,7 @@ link_dev_files() {
POSTFIX=${NAME#*.} POSTFIX=${NAME#*.}
EXT=${SRC##*.} EXT=${SRC##*.}
if [ "$PREFIX" = "$POSTFIX" ]; then if [ "$PREFIX" == "$POSTFIX" ]; then
DST="$PREFIX-dev.$EXT" DST="$PREFIX-dev.$EXT"
else else
DST="$PREFIX-dev.$POSTFIX.$EXT" DST="$PREFIX-dev.$POSTFIX.$EXT"
@ -606,14 +606,14 @@ link_dev_files() {
$rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/$DST $rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/$DST
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "linked '$DST'" echo "linked '$DST'"
fi fi
done done
# update TeX Live installation # update TeX Live installation
TEXlsr=`which mktexlsr` TEXlsr=`which mktexlsr`
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
$rootrun $TEXlsr $rootrun $TEXlsr
else else
$rootrun $TEXlsr --quiet $rootrun $TEXlsr --quiet
@ -625,7 +625,7 @@ link_dev_files() {
process_arguments $@ process_arguments $@
## do what is requested ## do what is requested
if [ $INSTALL = 1 ]; then if [ $INSTALL == 1 ]; then
## ##
check_path check_path
check_texlive check_texlive
@ -636,7 +636,7 @@ if [ $INSTALL = 1 ]; then
fi fi
if [ $TESTING = 1 ]; then if [ $TESTING == 1 ]; then
## ##
check_path check_path
check_pdflatex check_pdflatex
@ -652,7 +652,7 @@ if [ $TESTING = 1 ]; then
fi fi
if [ $RELEASE = 1 ]; then if [ $RELEASE == 1 ]; then
#### ####
# This script produces a .zip-file in accordance to the requirements for CTAN. # This script produces a .zip-file in accordance to the requirements for CTAN.
# For more information see https://ctan.org/help/upload-pkg. # For more information see https://ctan.org/help/upload-pkg.