diff --git a/check-attrpath-version-test.sh b/check-attrpath-version-test.sh new file mode 100755 index 0000000..83fbe3d --- /dev/null +++ b/check-attrpath-version-test.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +#set -euxo pipefail + +./check-attrpath-version.sh "libgit2_0_25" "0.25.3" + +./check-attrpath-version.sh "owncloud90" "9.0.3" + +if ./check-attrpath-version.sh "owncloud90" "9.1.3" +then + echo "fail" + exit 1 +fi + + +echo "All tests passed" diff --git a/check-attrpath-version.sh b/check-attrpath-version.sh index 0f93349..693fb5d 100755 --- a/check-attrpath-version.sh +++ b/check-attrpath-version.sh @@ -4,35 +4,48 @@ set -euxo pipefail ATTR_PATH=$1 NEW_VERSION=$2 -ATTR_VERSION_PART=$(echo "$ATTR_PATH" | sed -n 's/^[^0-9]*\([0-9_]*\)$/\1/p') +HAS_UNDERSCORES=$(echo "$ATTR_PATH" | grep "_") -# If we don't find version numbers in the attr path, exit success. -if [ -z "$ATTR_VERSION_PART" ] +if [ -n "$HAS_UNDERSCORES" ] then - exit 0 -fi + ATTR_VERSION_PART=$(echo "$ATTR_PATH" | sed -n 's/^[^_]*_\([0-9_]*\)$/\1/p') -# Check assuming version part has underscore separators -ATTR_VERSION_PERIODS=$(echo "$ATTR_VERSION_PART" | sed -n 's/_/\./gp') - -if [ -n "$ATTR_VERSION_PERIODS" ] -then - if [[ "$NEW_VERSION" == $ATTR_VERSION_PERIODS* ]] - then - exit 0 - fi -fi - -# Check assuming version part is the prefix of the version with dots -# removed. For example, 91 => "9.1" -NO_PERIOD_NEW_VERSION=$(echo "$NEW_VERSION" | sed -n 's/\.//gp') - -if [ -n "$NO_PERIOD_NEW_VERSION" ] -then - if [[ "$NO_PERIOD_NEW_VERSION" == $ATTR_VERSION_PART* ]] + # If we don't find version numbers in the attr path, exit success. + if [ -z "$ATTR_VERSION_PART" ] then exit 0 fi + + # Check assuming version part has underscore separators + ATTR_VERSION_PERIODS=$(echo "$ATTR_VERSION_PART" | sed -n 's/_/\./gp') + + if [ -n "$ATTR_VERSION_PERIODS" ] + then + if [[ "$NEW_VERSION" == $ATTR_VERSION_PERIODS* ]] + then + exit 0 + fi + fi +else + ATTR_VERSION_PART=$(echo "$ATTR_PATH" | sed -n 's/^[^0-9]*\([0-9]*\)$/\1/p') + + # If we don't find version numbers in the attr path, exit success. + if [ -z "$ATTR_VERSION_PART" ] + then + exit 0 + fi + + # Check assuming version part is the prefix of the version with dots + # removed. For example, 91 => "9.1" + NO_PERIOD_NEW_VERSION=$(echo "$NEW_VERSION" | sed -n 's/\.//gp') + + if [ -n "$NO_PERIOD_NEW_VERSION" ] + then + if [[ "$NO_PERIOD_NEW_VERSION" == $ATTR_VERSION_PART* ]] + then + exit 0 + fi + fi fi exit 1