Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / apple / FindFamily / scripts / stamp-version.sh

stamp-version.sh32 lines · 1.3 KiBRaw
1#!/usr/bin/env bash
2# stamp-version.sh [Info.plist]
3# Writes Modern-Apps version.txt into the app's Info.plist (in place):
4# CFBundleVersion = line 1 (numeric code, e.g. 20261105)
5# CFBundleShortVersionString = line 2 minus leading "v" and trailing letters (v2.6.11b -> 2.6.11),
6# because Apple only accepts dot-separated integers.
7# Run on a throwaway checkout (the release builder clones fresh).
8set -euo pipefail
9
10HERE="$(cd "$(dirname "$0")/.." && pwd)"
11PLIST="${1:-$HERE/FindFamilyiOS/Info.plist}"
12VERSION_FILE="$HERE/../../version.txt"
13
14CODE=$(sed -n '1p' "$VERSION_FILE" | tr -d '[:space:]')
15NAME=$(sed -n '2p' "$VERSION_FILE" | tr -d '[:space:]')
16SHORT=$(printf '%s' "$NAME" | sed -E 's/^v//; s/[^0-9.]+$//')
17
18[[ "$CODE" =~ ^[0-9]+$ ]] || { echo "stamp-version: bad version code '$CODE'" >&2; exit 1; }
19[[ "$SHORT" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]] || { echo "stamp-version: cannot map '$NAME' to an Apple version" >&2; exit 1; }
20
21python3 - "$PLIST" "$SHORT" "$CODE" <<'EOF'
22import plistlib, sys
23path, short, code = sys.argv[1:]
24with open(path, "rb") as f:
25 info = plistlib.load(f)
26info["CFBundleShortVersionString"] = short
27info["CFBundleVersion"] = code
28with open(path, "wb") as f:
29 plistlib.dump(info, f)
30EOF
31
32echo "stamp-version: $SHORT ($CODE) -> $PLIST"