Files

44 lines
1.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
# Compute and apply the Geminux Linux release version and codename.
set -eu
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
VERSION="${GEMINUX_VERSION:-0.1.0}"
CODENAME="${GEMINUX_CODENAME:-helio}"
if [ "${1:-}" = "--print" ] || [ "${1:-}" = "-p" ]; then
printf '%s\n' "$VERSION"
exit 0
fi
if [ "${1:-}" = "--print-codename" ] || [ "${1:-}" = "-c" ]; then
printf '%s\n' "$CODENAME"
exit 0
fi
TARGET_ROOTFS="${1:-${ROOTFS_DIR:-$BASE_DIR/rootfs}}"
apply_template() {
src_tpl="$1"
dst_file="$2"
if [ -f "$src_tpl" ]; then
mkdir -p "$(dirname "$dst_file")"
sed -e "s/@GEMINUX_VERSION@/$VERSION/g" \
-e "s/@GEMINUX_CODENAME@/$CODENAME/g" \
"$src_tpl" > "$dst_file"
elif [ -f "$dst_file" ]; then
sed -i -E \
-e "s/@GEMINUX_VERSION@/$VERSION/g" \
-e "s/@GEMINUX_CODENAME@/$CODENAME/g" \
"$dst_file"
fi
}
if [ -d "$TARGET_ROOTFS" ]; then
for rel in etc/os-release usr/lib/os-release etc/issue etc/motd; do
apply_template "$BASE_DIR/overlay/rootfs/$rel" "$TARGET_ROOTFS/$rel"
done
echo "Applied Geminux version $VERSION ($CODENAME) to $TARGET_ROOTFS"
else
printf '%s\n' "$VERSION"
fi