Skip to content

Commit 0e1480c

Browse files
committed
Stamp git info and build ID into the image
Capture this image build's git state and a BUILD_ID (CI-provided, or a UTC timestamp fallback) and write both into /etc/os-release of @minimal before it is snapshotted to @Minimal_stock, so every profile inherits them via COW. Resolve the os-release symlink so the real file is edited in place. The MOTD and login banner now report the build ID instead of a decoded timestamp.
1 parent b78ed2f commit 0e1480c

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

build-rootfs-img.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
set -e
77

8+
# Capture Git information
9+
[ -n "${GIT_HASH}" ] || GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
10+
[ -n "${GIT_BRANCH}" ] || GIT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null || echo "detached")
11+
[ -n "${GIT_MSG}" ] || GIT_MSG=$(git log -1 --pretty=format:"%s" 2>/dev/null | sed 's/[\"()]/\\&/g; s/'"'"'/\\&/g' || echo "unknown")
12+
[ -n "${GIT_INFO}" ] || GIT_INFO="${GIT_BRANCH}@${GIT_HASH}: ${GIT_MSG}"
13+
GIT_INFO=$(echo "$GIT_INFO" | tr -dc '[:alnum:][:space:]')
14+
15+
# Build identifier: CI sets BUILD_ID in the environment (e.g. "build-1419"); otherwise
16+
# fall back to a UTC timestamp, same default/format as build-images.sh.
17+
: "${BUILD_ID:=$(date -u '+%Y%m%d-%H%M')}"
18+
819
if [ -c /dev/kvm -a -w /dev/kvm ]; then
920
# Have virtualization support, can use fakemachine (default, fast, safe)
1021
DEBOS="debos -c $(nproc) -m 6Gb"
@@ -29,7 +40,7 @@ mkdir -p "$IMG_OUT"/linux_tmp
2940
cp -r "$LINUX_OUT"/* "$IMG_OUT"/linux_tmp
3041

3142
echo "Creating the root FS image"
32-
$DEBOS --artifactdir="$IMG_OUT" -t imagesize:"$IMGSIZE" -t kerneldir:linux_tmp debian-rk3576-img.yaml
43+
$DEBOS --artifactdir="$IMG_OUT" -t imagesize:"$IMGSIZE" -t kerneldir:linux_tmp -t gitinfo:"$GIT_INFO" -t buildid:"$BUILD_ID" debian-rk3576-img.yaml
3344
sync "$IMG_OUT"/debian-nobootloader.img
3445

3546
owner=$(stat -c %u "$IMG_OUT"/debian-nobootloader.img)

debian-rk3576-img.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{{ $kerneldir := or .kerneldir "prebuilt/linux" }}
44
{{ $cmdline := or .cmdline "audit=0 console=tty1 console=ttyS0,1500000n8" }}
55
{{ $fslabel := or .fslabel "flipperos" }}
6+
{{ $gitinfo := or .gitinfo "unknown" }}
7+
{{ $buildid := or .buildid "unknown" }}
68
{{- /* fs-wide btrfs mount options. ssd is FORCED (loopback/eMMC isn't reliably
79
detected as non-rotational). */ -}}
810
{{ $btrfsopts := or .btrfsopts "compress=zstd,noatime,ssd,discard=async" }}
@@ -130,6 +132,21 @@ actions:
130132
chroot: true
131133
command: systemctl set-default multi-user.target
132134

135+
# The ospack tarball already carries a BUILD_GIT (the ospack build's git state), and the
136+
# ospack is cached/reused across image builds. Replace it with THIS image build's git
137+
# state so the stamp reflects the actual image. Stamped into @Minimal before it is snapshotted
138+
# to @Minimal_stock, so every profile inherits it via COW. Both are consumed by the MOTD/banner.
139+
- action: run
140+
description: Save GIT info
141+
chroot: true
142+
command: |
143+
# /etc/os-release is normally a symlink to /usr/lib/os-release; resolve it so
144+
# sed edits the real file in place instead of replacing the symlink.
145+
osr="$(readlink -f /etc/os-release)"
146+
sed -i '/^BUILD_GIT=/d; /^BUILD_ID=/d' "$osr"
147+
echo 'BUILD_GIT="{{ $gitinfo }}"' >> "$osr"
148+
echo 'BUILD_ID={{ $buildid }}' >> "$osr"
149+
133150
# ===========================================================================
134151
# Stock (RO) bases + per-profile bootable roots.
135152
#

overlays/configs/update-motd.d/00-flipperone

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ serial=$(tr -d '\0' < /sys/firmware/devicetree/base/serial-number 2>/dev/null ||
1010
. /etc/os-release
1111

1212
# Get build info
13-
build_id=${BUILD_ID:-0}
13+
build_id=${BUILD_ID:-unknown}
1414
build_git=${BUILD_GIT:-unknown}
15-
build_date=$(date -d "@$build_id" "+%Y-%m-%d %H:%M:%S %Z" 2>/dev/null || echo "$build_id")
1615

1716
total_mem=$(awk '/MemTotal/ {printf "%.1f GB", $2/1024/1024}' /proc/meminfo)
1817

@@ -25,7 +24,7 @@ cat <<EOF
2524
Board: $board
2625
CPU Serial: $serial
2726
Memory: $total_mem
28-
Build Date: $build_date
27+
Build ID: $build_id
2928
3029
Memory Status:
3130
$(free -hv)

overlays/usr/local/bin/set-hostname-and-banner.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ new_hostname="${device}-${serial_prefix}-${BUILD_ID}"
2525
hostnamectl set-hostname "${new_hostname}"
2626

2727
# Get build info
28-
build_id=${BUILD_ID:-0}
28+
build_id=${BUILD_ID:-unknown}
2929
build_git=${BUILD_GIT:-unknown}
30-
build_date=$(date -d "@$build_id" "+%Y-%m-%d %H:%M:%S %Z" 2>/dev/null || echo "$build_id")
3130

3231
total_mem=$(awk '/MemTotal/ {printf "%.1f GB", $2/1024/1024}' /proc/meminfo)
3332

@@ -38,7 +37,7 @@ Git: $build_git
3837
Board: $board
3938
CPU Serial: $serial
4039
Memory: $total_mem
41-
Build Date: $build_date
40+
Build ID: $build_id
4241
Default credentials: user / user
4342
=============================================================
4443
EOF

0 commit comments

Comments
 (0)