snapraid/autover.sh

34 lines
880 B
Bash
Raw Normal View History

#!/bin/sh
#
2026-08-12 00:33:14 +02:00
SRCDIR="${srcdir:-$(dirname "$0")}"
if [ -f "$SRCDIR/.version" ]; then
# Get version from the .version file
2026-08-12 00:33:14 +02:00
VERSION=$(cat "$SRCDIR/.version")
fi
2026-08-12 00:33:14 +02:00
if [ -z "$VERSION" ] && [ -e "$SRCDIR/.git" ]; then
2026-02-24 11:34:31 +01:00
# Get version from git tags, removing the 'v' prefix
2026-08-12 00:33:14 +02:00
VERSION=$(git -C "$SRCDIR" describe --match 'v*' 2>/dev/null | sed 's/^v//')
2026-02-24 11:34:31 +01:00
fi
2026-08-12 00:33:14 +02:00
if [ -z "$VERSION" ] && [ -e "$SRCDIR/.git" ]; then
# Fall back to short commit hash
2026-08-12 00:33:14 +02:00
VERSION=0-$(git -C "$SRCDIR" rev-parse --short HEAD 2>/dev/null)
fi
2026-02-24 11:34:31 +01:00
if [ -z "$VERSION" ]; then
# No version, but still use a number
VERSION="0"
fi
2026-02-24 11:34:31 +01:00
# Apply common rules to all outputs:
# - Remove "-" at the end
# - Replace "rc-" with "rc"
# - Replace "beta-" with "beta"
# - Replace all remaining dashes with "."
VERSION=$(echo "$VERSION" | sed 's/-$//; s/rc-/rc/g; s/beta-/beta/g; s/-/./g')
2026-02-24 11:34:31 +01:00
printf '%s' "$VERSION"