Files
homelab-gitops/scripts/update-chart-version.sh
T

34 lines
718 B
Bash

#!/bin/sh
set -eu
if [ "$#" -ne 2 ]; then
echo "usage: $0 APPLICATION CHART_VERSION" >&2
exit 2
fi
application=$1
version=$2
case "$application" in
''|*[!a-z0-9-]*) echo "invalid application name: $application" >&2; exit 2 ;;
esac
case "$version" in
''|*[!0-9A-Za-z.+-]*) echo "invalid chart version: $version" >&2; exit 2 ;;
esac
file="bootstrap/${application}.yaml"
test -f "$file"
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
awk -v version="$version" '
$1 == "chart:" && !chart { chart=1 }
chart && $1 == "targetRevision:" && !updated {
sub(/targetRevision:.*/, "targetRevision: " version)
updated=1
}
{ print }
END { if (!updated) exit 3 }
' "$file" > "$tmp"
mv "$tmp" "$file"
trap - EXIT