Skip to content

Commit 9d7eba4

Browse files
committed
Improve version handling in the repository and ZBM images
- Track installed version in ${zfsbootmenu_module_root}/zbm-release - Install zbm-release as /etc/zbm-release in ZFSBootMenu images - Add releng/version.sh to manage repository versioning - Mark post-release development versions as part of release tagging - Improve version handling in ZFSBootMenu build containers: * zbm-builder.sh: allow temporary, writable overlays of /zbm * releng/docker/build-init.sh: update ZBM version when possible * releng/docker/image-build.sh: install git in standard images
1 parent 45cbf0f commit 9d7eba4

11 files changed

+240
-24
lines changed

Makefile

+21-15
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@ MANDIR=$(PREFIX)/share/man
88
BINDIR=$(PREFIX)/bin
99
EXAMPLES=$(PREFIX)/share/examples/zfsbootmenu
1010

11-
.PHONY: install core dracut initcpio
11+
.PHONY: install core dracut initcpio zbm-release show-version
1212

13-
install: core dracut initcpio
13+
install: core dracut initcpio zbm-release
1414

15-
core:
16-
./install-tree.sh zfsbootmenu "$(DESTDIR)$(MODDIR)/zfsbootmenu"
17-
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
18-
install -m 0755 -t "$(DESTDIR)$(BINDIR)" -D bin/*
19-
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man5" -D docs/man/dist/man5/*.5
20-
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man7" -D docs/man/dist/man7/*.7
21-
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man8" -D docs/man/dist/man8/*.8
22-
install -m 0755 -t "$(DESTDIR)$(EXAMPLES)/hooks" -D contrib/*
23-
install -m 0755 -t "$(DESTDIR)$(EXAMPLES)" -D examples/*
15+
core: zbm-release
16+
./install-tree.sh zfsbootmenu "$(DESTDIR)/$(MODDIR)/zfsbootmenu"
17+
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
18+
install -m 0755 -t "$(DESTDIR)/$(BINDIR)" -D bin/*
19+
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man5" -D docs/man/dist/man5/*.5
20+
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man7" -D docs/man/dist/man7/*.7
21+
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man8" -D docs/man/dist/man8/*.8
22+
install -m 0755 -t "$(DESTDIR)/$(EXAMPLES)/hooks" -D contrib/*
23+
install -m 0755 -t "$(DESTDIR)/$(EXAMPLES)" -D examples/*
2424

2525
dracut:
26-
./install-tree.sh dracut "$(DESTDIR)$(DRACUTDIR)/90zfsbootmenu"
26+
./install-tree.sh dracut "$(DESTDIR)/$(DRACUTDIR)/90zfsbootmenu"
2727
install -m 0644 -t \
28-
"$(DESTDIR)$(CONFDIR)/dracut.conf.d/" \
28+
"$(DESTDIR)/$(CONFDIR)/dracut.conf.d/" \
2929
-D etc/zfsbootmenu/dracut.conf.d/*
3030

3131
initcpio:
32-
./install-tree.sh initcpio "$(DESTDIR)$(INITCPIODIR)"
33-
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf
32+
./install-tree.sh initcpio "$(DESTDIR)/$(INITCPIODIR)"
33+
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf
34+
35+
zbm-release:
36+
./releng/version.sh -u
37+
38+
show-version:
39+
@ ./releng/version.sh

bin/generate-zbm

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use strict;
55
use warnings;
66

7-
our $VERSION = '2.2.2';
7+
our $VERSION = '2.2.2+dev';
88

99
use Getopt::Long qw(:config no_ignore_case auto_version);
1010
use Pod::Usage qw(pod2usage);

dracut/module-setup.sh

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ install() {
118118
# Install online documentation if possible
119119
install_zbm_docs
120120

121+
# Install an os-release, if one is available
122+
install_zbm_osver
123+
121124
# optionally enable early Dracut profiling
122125
if [ -n "${dracut_trace_enable}" ]; then
123126
inst_hook cmdline 00 "${zfsbootmenu_module_root}/profiling/profiling-lib.sh"

initcpio/install/zfsbootmenu

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ build() {
170170
# Install online documentation if possible
171171
install_zbm_docs
172172

173+
# Install an os-release, if one is available
174+
install_zbm_osver
175+
173176
# Install pre-init scripts
174177
for _file in "${zfsbootmenu_module_root}"/pre-init/*; do
175178
add_file "${_file}" "/lib/${_file##*/}" && continue;

releng/docker/build-init.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Usage: $0 [options]
3838
Specify specific tag or commit hash to fetch
3939
(Ignored if /zbm already contains a ZFSBootMenu tree)
4040
41+
-V
42+
Do not attempt to update the version recorded in the source tree
43+
4144
-e <statement>
4245
Specify a yq-go statement that will be evaluated as
4346
@@ -54,7 +57,10 @@ EOF
5457
PACKAGES=()
5558
CONFIGEVALS=()
5659
GENARGS=()
57-
while getopts "hb:o:t:e:p:" opt; do
60+
61+
SKIP_VERSIONING=
62+
63+
while getopts "hb:o:t:e:p:V" opt; do
5864
case "${opt}" in
5965
b)
6066
BUILDROOT="${OPTARG}"
@@ -71,6 +77,9 @@ while getopts "hb:o:t:e:p:" opt; do
7177
e)
7278
CONFIGEVALS+=( "${OPTARG}" )
7379
;;
80+
V)
81+
SKIP_VERSIONING="yes"
82+
;;
7483
h)
7584
usage
7685
exit 0
@@ -228,4 +237,9 @@ for ceval in "${CONFIGEVALS[@]}"; do
228237
|| error "failed to apply '${ceval}' to config"
229238
done
230239

240+
# If possible, update the version recorded in the ZFSBootMenu repository
241+
if [ "${SKIP_VERSIONING,,}" != "yes" ] && [ -x /zbm/releng/version.sh ]; then
242+
( cd /zbm && ./releng/version.sh -u ) || true
243+
fi
244+
231245
exec /zbm/bin/generate-zbm "${GENARGS[@]}"

releng/docker/image-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ buildah run "${host_mounts[@]}" "${container}" \
182182

183183
buildah run "${host_mounts[@]}" "${container}" \
184184
xbps-install -y "${kern_series[@]}" "${kern_headers[@]}" \
185-
zstd gummiboot-efistub curl yq-go bash kbd \
185+
git zstd gummiboot-efistub curl yq-go bash kbd \
186186
dracut mkinitcpio dracut-network gptfdisk iproute2 iputils parted \
187187
curl dosfstools e2fsprogs efibootmgr cryptsetup openssh util-linux kpartx
188188

releng/tag-release.sh

+19-2
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ if ! (head -n 1 "${relnotes}" | grep -q "ZFSBootMenu ${tag}\b"); then
113113
fi
114114

115115
# Update version in generate-zbm
116-
sed -i bin/generate-zbm -e "s/our \$VERSION.*/our \$VERSION = '${release}';/"
116+
if [ -x releng/version.sh ]; then
117+
error "ERROR: unable to update release version"
118+
fi
119+
120+
if ! out="$( releng/version.sh -v "${release}" -u )"; then
121+
error "ERROR: ${out}"
122+
fi
117123

118124
# Push updates for the release
119-
git add bin/generate-zbm docs/ zfsbootmenu/help-files/
125+
git add bin/generate-zbm docs/ zfsbootmenu/zbm-release zfsbootmenu/help-files/
120126
git commit -m "Bump to version ${release}"
121127

122128
# Publish release, as prerelease if version contains alphabetics
@@ -197,3 +203,14 @@ if ! gh release create "${tag}" "${prerelease[@]}" \
197203
fi
198204

199205
echo "Pushed and tagged release ${release}"
206+
207+
# Bump the verson to a development tag
208+
dver="${release}+dev"
209+
if ! (
210+
releng/version.sh -v "${dver}" -u || exit 1
211+
git add bin/generate-zbm zfsbootmenu/zbm-release || exit 1
212+
git commit -m "Bump to version ${dver}" || exit 1
213+
git push
214+
); then
215+
error "ERROR: failed to update to development version"
216+
fi

releng/version.sh

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/sh
2+
# vim: softtabstop=2 shiftwidth=2 expandtab
3+
4+
usage() {
5+
cat <<-EOF
6+
USAGE: $0 [options]
7+
8+
OPTIONS
9+
-h
10+
Display this message and exit
11+
12+
-u
13+
Update zbm-release and generate-zbm version information
14+
15+
-v <version>
16+
Specify a particular version to use
17+
18+
EOF
19+
}
20+
21+
detect_version() {
22+
# If git-describe does the job, the job is done
23+
version="$(git describe --tags HEAD 2>/dev/null)" || version=""
24+
25+
case "${version}" in
26+
v[0-9]*) version="${version#v}"
27+
esac
28+
29+
if [ -n "${version}" ]; then
30+
echo "${version}"
31+
return 0
32+
fi
33+
34+
# Otherwise, use git-rev-parse if possible
35+
if branch="$(git rev-parse --abbrev-rev HEAD 2>/dev/null)"; then
36+
case "${branch}" in
37+
v[0-9]*) branch="${branch#v}"
38+
esac
39+
40+
hash="$(git rev-parse --short HEAD 2>/dev/null)" || hash=""
41+
[ -n "${hash}" ] && version="${branch:-UNKNOWN} (${hash})"
42+
43+
if [ -n "${version}" ]; then
44+
echo "${version}"
45+
return 0
46+
fi
47+
fi
48+
49+
# Everything fell apart, so just try reading zbm-release
50+
relfile="zfsbootmenu/zbm-release"
51+
if [ -r "${relfile}" ]; then
52+
# shellcheck disable=SC2153
53+
# shellcheck disable=SC1090
54+
version="$( . "${relfile}" 2>/dev/null && echo "${VERSION}" )" || version=""
55+
56+
if [ -n "${version}" ]; then
57+
echo "${version}"
58+
return 0
59+
fi
60+
fi
61+
62+
# If there is no zbm-release, look to generate-zbm
63+
genzbm="bin/generate-zbm"
64+
if [ -r "${genzbm}" ]; then
65+
# shellcheck disable=SC2016
66+
if verline="$(grep 'our $VERSION[[:space:]]*=' "${genzbm}")"; then
67+
version="$(echo "${verline}" | head -n1 | sed -e "s/.*=[[:space:]]*['\"]//" -e "s/['\"].*//")" || version=""
68+
if [ -n "${version}" ]; then
69+
echo "${version}"
70+
return 0
71+
fi
72+
fi
73+
fi
74+
75+
# There is apparently no version
76+
echo "UNKNOWN"
77+
return 1
78+
}
79+
80+
update_version() {
81+
version="${1?a version is required}"
82+
83+
# Write zbm-release
84+
if [ -d zfsbootmenu ] && [ -w zfsbootmenu ]; then
85+
echo "Updating zfsbootmenu/zbm-release"
86+
cat > zfsbootmenu/zbm-release <<-EOF
87+
NAME="ZFSBootMenu"
88+
PRETTY_NAME="ZFSBootMenu"
89+
ID="zfsbootmenu"
90+
ID_LIKE="void"
91+
HOME_URL="https://zfsbootmenu.org"
92+
DOCUMENTATION_URL="https://docs.zfsbootmenu.org"
93+
BUG_REPORT_URL="https://github.com/zbm-dev/zfsbootmenu/issues"
94+
SUPPORT_URL="https://github.com/zbm-dev/zfsbootmenu/discussions"
95+
VERSION="${version}"
96+
EOF
97+
fi
98+
99+
# Update generate-zbm
100+
if [ -w bin/generate-zbm ]; then
101+
echo "Updating bin/generate-zbm"
102+
sed -e "s/our \$VERSION.*/our \$VERSION = '${version}';/" -i bin/generate-zbm
103+
fi
104+
}
105+
106+
version=
107+
update=
108+
while getopts "huv:" opt; do
109+
case "${opt}" in
110+
u)
111+
update="yes"
112+
;;
113+
v)
114+
version="${OPTARG}"
115+
;;
116+
h)
117+
usage
118+
exit 0
119+
;;
120+
*)
121+
usage >&2
122+
exit 1
123+
;;
124+
esac
125+
done
126+
127+
[ -n "${version}" ] || version="$(detect_version)"
128+
129+
if [ "${update}" = yes ]; then
130+
update_version "${version}"
131+
else
132+
echo "ZFSBootMenu version: ${version}"
133+
fi

zbm-builder.sh

+22-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ OPTIONS:
6868
(Default: ghcr.io/zbm-dev/zbm-builder:latest)
6969
7070
-l <path>
71-
Build from ZFSBootMenu source tree at <path>
71+
Build from ZFSBootMenu source tree at <path>, mounted read-only
72+
(Default: fetch upstream source tree inside container)
73+
74+
-L <path>
75+
Build from ZFSBootMenu source tree at <path>, with a temporary
76+
read-write overlay atop the tree
7277
(Default: fetch upstream source tree inside container)
7378
7479
-R Remove any existing hostid in the build directory
@@ -96,8 +101,9 @@ BUILD_IMG="ghcr.io/zbm-dev/zbm-builder:latest"
96101
# By default, build from the current directory
97102
BUILD_DIRECTORY="${PWD}"
98103

99-
# By default, there is no local repo
104+
# By default, there is no local repo and it is not overlaid
100105
BUILD_REPO=
106+
BUILD_OVERLAY=
101107

102108
# Arguments to the build script
103109
BUILD_ARGS=()
@@ -114,7 +120,7 @@ else
114120
PODMAN="docker"
115121
fi
116122

117-
CMDOPTS="b:dhi:l:c:M:O:HR"
123+
CMDOPTS="b:dhi:l:L:c:M:O:HR"
118124

119125
# First pass to get build directory and configuration file
120126
while getopts "${CMDOPTS}" opt; do
@@ -168,6 +174,11 @@ while getopts "${CMDOPTS}" opt; do
168174
;;
169175
l)
170176
BUILD_REPO="${OPTARG}"
177+
BUILD_OVERLAY=""
178+
;;
179+
L)
180+
BUILD_REPO="${OPTARG}"
181+
BUILD_OVERLAY="yes"
171182
;;
172183
M)
173184
MOUNT_FLAGS="${OPTARG}"
@@ -206,7 +217,14 @@ if [ -n "${BUILD_REPO}" ]; then
206217
exit 1
207218
fi
208219

209-
RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:ro${MOUNT_FLAGS:+,${MOUNT_FLAGS}}" )
220+
mntopt=""
221+
case "${BUILD_OVERLAY,,}" in
222+
yes) mntopt="O" ;;
223+
*) mntopt="ro" ;;
224+
esac
225+
226+
RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:${mntopt}${MOUNT_FLAGS:+,${MOUNT_FLAGS}}" )
227+
unset mntopt
210228
fi
211229

212230
# Remove existing hostid

zfsbootmenu/install-helpers.sh

+13
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ install_zbm_fonts() {
256256
done
257257
}
258258

259+
install_zbm_osver() {
260+
local build_date
261+
[ -r "${zfsbootmenu_module_root}/zbm-release" ] || return 0
262+
zbm_install_file "${zfsbootmenu_module_root}/zbm-release" "/etc/zbm-release"
263+
if build_date="$(date %Y-%m-%d)"; then
264+
cat >> "${BUILDROOT}/etc/zbm-release" <<-EOF
265+
BUILD_ID="${build_date}"
266+
EOF
267+
fi
268+
269+
ln -Tsf zbm-release "${BUILDROOT}/etc/os-release"
270+
}
271+
259272
populate_hook_dir() {
260273
local hfile ret hlev
261274

zfsbootmenu/zbm-release

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
NAME="ZFSBootMenu"
2+
PRETTY_NAME="ZFSBootMenu"
3+
ID="zfsbootmenu"
4+
ID_LIKE="void"
5+
HOME_URL="https://zfsbootmenu.org"
6+
DOCUMENTATION_URL="https://docs.zfsbootmenu.org"
7+
BUG_REPORT_URL="https://github.com/zbm-dev/zfsbootmenu/issues"
8+
SUPPORT_URL="https://github.com/zbm-dev/zfsbootmenu/discussions"
9+
VERSION="2.2.2+dev"

0 commit comments

Comments
 (0)