Skip to content

Commit

Permalink
Improve version handling in the repository and ZBM images
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ahesford committed Nov 26, 2023
1 parent 45cbf0f commit 9d7eba4
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 24 deletions.
36 changes: 21 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ MANDIR=$(PREFIX)/share/man
BINDIR=$(PREFIX)/bin
EXAMPLES=$(PREFIX)/share/examples/zfsbootmenu

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

install: core dracut initcpio
install: core dracut initcpio zbm-release

core:
./install-tree.sh zfsbootmenu "$(DESTDIR)$(MODDIR)/zfsbootmenu"
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
install -m 0755 -t "$(DESTDIR)$(BINDIR)" -D bin/*
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man5" -D docs/man/dist/man5/*.5
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man7" -D docs/man/dist/man7/*.7
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man8" -D docs/man/dist/man8/*.8
install -m 0755 -t "$(DESTDIR)$(EXAMPLES)/hooks" -D contrib/*
install -m 0755 -t "$(DESTDIR)$(EXAMPLES)" -D examples/*
core: zbm-release
./install-tree.sh zfsbootmenu "$(DESTDIR)/$(MODDIR)/zfsbootmenu"
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
install -m 0755 -t "$(DESTDIR)/$(BINDIR)" -D bin/*
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man5" -D docs/man/dist/man5/*.5
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man7" -D docs/man/dist/man7/*.7
install -m 0644 -t "$(DESTDIR)/$(MANDIR)/man8" -D docs/man/dist/man8/*.8
install -m 0755 -t "$(DESTDIR)/$(EXAMPLES)/hooks" -D contrib/*
install -m 0755 -t "$(DESTDIR)/$(EXAMPLES)" -D examples/*

dracut:
./install-tree.sh dracut "$(DESTDIR)$(DRACUTDIR)/90zfsbootmenu"
./install-tree.sh dracut "$(DESTDIR)/$(DRACUTDIR)/90zfsbootmenu"
install -m 0644 -t \
"$(DESTDIR)$(CONFDIR)/dracut.conf.d/" \
"$(DESTDIR)/$(CONFDIR)/dracut.conf.d/" \
-D etc/zfsbootmenu/dracut.conf.d/*

initcpio:
./install-tree.sh initcpio "$(DESTDIR)$(INITCPIODIR)"
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf
./install-tree.sh initcpio "$(DESTDIR)/$(INITCPIODIR)"
install -m 0644 -t "$(DESTDIR)/$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf

zbm-release:
./releng/version.sh -u

show-version:
@ ./releng/version.sh
2 changes: 1 addition & 1 deletion bin/generate-zbm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use strict;
use warnings;

our $VERSION = '2.2.2';
our $VERSION = '2.2.2+dev';

use Getopt::Long qw(:config no_ignore_case auto_version);
use Pod::Usage qw(pod2usage);
Expand Down
3 changes: 3 additions & 0 deletions dracut/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ install() {
# Install online documentation if possible
install_zbm_docs

# Install an os-release, if one is available
install_zbm_osver

# optionally enable early Dracut profiling
if [ -n "${dracut_trace_enable}" ]; then
inst_hook cmdline 00 "${zfsbootmenu_module_root}/profiling/profiling-lib.sh"
Expand Down
3 changes: 3 additions & 0 deletions initcpio/install/zfsbootmenu
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ build() {
# Install online documentation if possible
install_zbm_docs

# Install an os-release, if one is available
install_zbm_osver

# Install pre-init scripts
for _file in "${zfsbootmenu_module_root}"/pre-init/*; do
add_file "${_file}" "/lib/${_file##*/}" && continue;
Expand Down
16 changes: 15 additions & 1 deletion releng/docker/build-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Usage: $0 [options]
Specify specific tag or commit hash to fetch
(Ignored if /zbm already contains a ZFSBootMenu tree)
-V
Do not attempt to update the version recorded in the source tree
-e <statement>
Specify a yq-go statement that will be evaluated as
Expand All @@ -54,7 +57,10 @@ EOF
PACKAGES=()
CONFIGEVALS=()
GENARGS=()
while getopts "hb:o:t:e:p:" opt; do

SKIP_VERSIONING=

while getopts "hb:o:t:e:p:V" opt; do
case "${opt}" in
b)
BUILDROOT="${OPTARG}"
Expand All @@ -71,6 +77,9 @@ while getopts "hb:o:t:e:p:" opt; do
e)
CONFIGEVALS+=( "${OPTARG}" )
;;
V)
SKIP_VERSIONING="yes"
;;
h)
usage
exit 0
Expand Down Expand Up @@ -228,4 +237,9 @@ for ceval in "${CONFIGEVALS[@]}"; do
|| error "failed to apply '${ceval}' to config"
done

# If possible, update the version recorded in the ZFSBootMenu repository
if [ "${SKIP_VERSIONING,,}" != "yes" ] && [ -x /zbm/releng/version.sh ]; then
( cd /zbm && ./releng/version.sh -u ) || true
fi

exec /zbm/bin/generate-zbm "${GENARGS[@]}"
2 changes: 1 addition & 1 deletion releng/docker/image-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ buildah run "${host_mounts[@]}" "${container}" \

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

Expand Down
21 changes: 19 additions & 2 deletions releng/tag-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ if ! (head -n 1 "${relnotes}" | grep -q "ZFSBootMenu ${tag}\b"); then
fi

# Update version in generate-zbm
sed -i bin/generate-zbm -e "s/our \$VERSION.*/our \$VERSION = '${release}';/"
if [ -x releng/version.sh ]; then
error "ERROR: unable to update release version"
fi

if ! out="$( releng/version.sh -v "${release}" -u )"; then
error "ERROR: ${out}"
fi

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

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

echo "Pushed and tagged release ${release}"

# Bump the verson to a development tag
dver="${release}+dev"
if ! (
releng/version.sh -v "${dver}" -u || exit 1
git add bin/generate-zbm zfsbootmenu/zbm-release || exit 1
git commit -m "Bump to version ${dver}" || exit 1
git push
); then
error "ERROR: failed to update to development version"
fi
133 changes: 133 additions & 0 deletions releng/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/sh
# vim: softtabstop=2 shiftwidth=2 expandtab

usage() {
cat <<-EOF
USAGE: $0 [options]
OPTIONS
-h
Display this message and exit
-u
Update zbm-release and generate-zbm version information
-v <version>
Specify a particular version to use
EOF
}

detect_version() {
# If git-describe does the job, the job is done
version="$(git describe --tags HEAD 2>/dev/null)" || version=""

case "${version}" in
v[0-9]*) version="${version#v}"
esac

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi

# Otherwise, use git-rev-parse if possible
if branch="$(git rev-parse --abbrev-rev HEAD 2>/dev/null)"; then
case "${branch}" in
v[0-9]*) branch="${branch#v}"
esac

hash="$(git rev-parse --short HEAD 2>/dev/null)" || hash=""
[ -n "${hash}" ] && version="${branch:-UNKNOWN} (${hash})"

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi

# Everything fell apart, so just try reading zbm-release
relfile="zfsbootmenu/zbm-release"
if [ -r "${relfile}" ]; then
# shellcheck disable=SC2153
# shellcheck disable=SC1090
version="$( . "${relfile}" 2>/dev/null && echo "${VERSION}" )" || version=""

if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi

# If there is no zbm-release, look to generate-zbm
genzbm="bin/generate-zbm"
if [ -r "${genzbm}" ]; then
# shellcheck disable=SC2016
if verline="$(grep 'our $VERSION[[:space:]]*=' "${genzbm}")"; then
version="$(echo "${verline}" | head -n1 | sed -e "s/.*=[[:space:]]*['\"]//" -e "s/['\"].*//")" || version=""
if [ -n "${version}" ]; then
echo "${version}"
return 0
fi
fi
fi

# There is apparently no version
echo "UNKNOWN"
return 1
}

update_version() {
version="${1?a version is required}"

# Write zbm-release
if [ -d zfsbootmenu ] && [ -w zfsbootmenu ]; then
echo "Updating zfsbootmenu/zbm-release"
cat > zfsbootmenu/zbm-release <<-EOF
NAME="ZFSBootMenu"
PRETTY_NAME="ZFSBootMenu"
ID="zfsbootmenu"
ID_LIKE="void"
HOME_URL="https://zfsbootmenu.org"
DOCUMENTATION_URL="https://docs.zfsbootmenu.org"
BUG_REPORT_URL="https://github.com/zbm-dev/zfsbootmenu/issues"
SUPPORT_URL="https://github.com/zbm-dev/zfsbootmenu/discussions"
VERSION="${version}"
EOF
fi

# Update generate-zbm
if [ -w bin/generate-zbm ]; then
echo "Updating bin/generate-zbm"
sed -e "s/our \$VERSION.*/our \$VERSION = '${version}';/" -i bin/generate-zbm
fi
}

version=
update=
while getopts "huv:" opt; do
case "${opt}" in
u)
update="yes"
;;
v)
version="${OPTARG}"
;;
h)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done

[ -n "${version}" ] || version="$(detect_version)"

if [ "${update}" = yes ]; then
update_version "${version}"
else
echo "ZFSBootMenu version: ${version}"
fi
26 changes: 22 additions & 4 deletions zbm-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ OPTIONS:
(Default: ghcr.io/zbm-dev/zbm-builder:latest)
-l <path>
Build from ZFSBootMenu source tree at <path>
Build from ZFSBootMenu source tree at <path>, mounted read-only
(Default: fetch upstream source tree inside container)
-L <path>
Build from ZFSBootMenu source tree at <path>, with a temporary
read-write overlay atop the tree
(Default: fetch upstream source tree inside container)
-R Remove any existing hostid in the build directory
Expand Down Expand Up @@ -96,8 +101,9 @@ BUILD_IMG="ghcr.io/zbm-dev/zbm-builder:latest"
# By default, build from the current directory
BUILD_DIRECTORY="${PWD}"

# By default, there is no local repo
# By default, there is no local repo and it is not overlaid
BUILD_REPO=
BUILD_OVERLAY=

# Arguments to the build script
BUILD_ARGS=()
Expand All @@ -114,7 +120,7 @@ else
PODMAN="docker"
fi

CMDOPTS="b:dhi:l:c:M:O:HR"
CMDOPTS="b:dhi:l:L:c:M:O:HR"

# First pass to get build directory and configuration file
while getopts "${CMDOPTS}" opt; do
Expand Down Expand Up @@ -168,6 +174,11 @@ while getopts "${CMDOPTS}" opt; do
;;
l)
BUILD_REPO="${OPTARG}"
BUILD_OVERLAY=""
;;
L)
BUILD_REPO="${OPTARG}"
BUILD_OVERLAY="yes"
;;
M)
MOUNT_FLAGS="${OPTARG}"
Expand Down Expand Up @@ -206,7 +217,14 @@ if [ -n "${BUILD_REPO}" ]; then
exit 1
fi

RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:ro${MOUNT_FLAGS:+,${MOUNT_FLAGS}}" )
mntopt=""
case "${BUILD_OVERLAY,,}" in
yes) mntopt="O" ;;
*) mntopt="ro" ;;
esac

RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:${mntopt}${MOUNT_FLAGS:+,${MOUNT_FLAGS}}" )
unset mntopt
fi

# Remove existing hostid
Expand Down
13 changes: 13 additions & 0 deletions zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ install_zbm_fonts() {
done
}

install_zbm_osver() {
local build_date
[ -r "${zfsbootmenu_module_root}/zbm-release" ] || return 0
zbm_install_file "${zfsbootmenu_module_root}/zbm-release" "/etc/zbm-release"
if build_date="$(date %Y-%m-%d)"; then
cat >> "${BUILDROOT}/etc/zbm-release" <<-EOF
BUILD_ID="${build_date}"
EOF
fi

ln -Tsf zbm-release "${BUILDROOT}/etc/os-release"
}

populate_hook_dir() {
local hfile ret hlev

Expand Down
9 changes: 9 additions & 0 deletions zfsbootmenu/zbm-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NAME="ZFSBootMenu"
PRETTY_NAME="ZFSBootMenu"
ID="zfsbootmenu"
ID_LIKE="void"
HOME_URL="https://zfsbootmenu.org"
DOCUMENTATION_URL="https://docs.zfsbootmenu.org"
BUG_REPORT_URL="https://github.com/zbm-dev/zfsbootmenu/issues"
SUPPORT_URL="https://github.com/zbm-dev/zfsbootmenu/discussions"
VERSION="2.2.2+dev"

0 comments on commit 9d7eba4

Please sign in to comment.