Skip to content

Commit e1bd708

Browse files
committed
zbm-builder.sh: add script to build custom images using GHCR container
1 parent 520f78d commit e1bd708

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

‎zbm-builder.sh‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
# vim: softtabstop=2 shiftwidth=2 expandtab
3+
4+
usage() {
5+
cat <<EOF
6+
Usage: $0 [options]
7+
OPTIONS:
8+
-h Display help text
9+
10+
-H Do not copy /etc/hostid into image
11+
(Has no effect if ./hostid exists)
12+
13+
-C Do not copy /etc/zfs/zpool.cache into image
14+
(Has no effect if ./zpool.cache exists)
15+
16+
-d Force use of docker instead of podman
17+
18+
-t
19+
Build the given ZFSBootMenu tag
20+
(Default: upstream master)
21+
22+
-B
23+
Use the given zbm-builder tag to build images
24+
(Default: ghcr.io/zbm-dev/zbm-builder:latest)
25+
EOF
26+
}
27+
28+
if command -v podman >/dev/null 2>&1; then
29+
PODMAN=podman
30+
elif command -v docker >/dev/null 2>&1; then
31+
PODMAN=docker
32+
fi
33+
34+
SKIP_HOSTID=
35+
SKIP_CACHE=
36+
37+
BUILD_TAG="ghcr.io/zbm-dev/zbm-builder:latest"
38+
39+
BUILD_ARGS=()
40+
41+
while getopts "hHCdt:B:" opt; do
42+
case "${opt}" in
43+
H)
44+
SKIP_HOSTID="yes"
45+
;;
46+
C)
47+
SKIP_CACHE="yes"
48+
;;
49+
d)
50+
PODMAN=docker
51+
;;
52+
t)
53+
BUILD_ARGS+=( "-t" "${OPTARG}" )
54+
;;
55+
B)
56+
BUILD_TAG="${OPTARG}"
57+
;;
58+
h)
59+
usage
60+
exit 0
61+
;;
62+
*)
63+
usage
64+
exit 1
65+
;;
66+
esac
67+
done
68+
69+
if ! command -v "${PODMAN}" >/dev/null 2>&1; then
70+
echo "ERROR: container front-end ${PODMAN} not found"
71+
exit 1
72+
fi
73+
74+
# If no local hostid is available, copy the system hostid if desired
75+
if ! [ -r ./hostid ]; then
76+
if [ "${SKIP_HOSTID}" != "yes" ] && [ -r /etc/hostid ]; then
77+
if ! cp /etc/hostid ./hostid; then
78+
echo "ERROR: unable to copy /etc/hostid"
79+
echo "Copy a hostid file to ./hostid or use -H to disable"
80+
exit 1
81+
fi
82+
fi
83+
fi
84+
85+
# If no local zpool.cache is available, copy the system cache if desired
86+
if ! [ -r ./zpool.cache ]; then
87+
if [ "${SKIP_CACHE}" != "yes" ] && [ -r /etc/zfs/zpool.cache ]; then
88+
if ! cp /etc/zfs/zpool.cache ./zpool.cache; then
89+
echo "ERROR: unable to copy /etc/zfs/zpool.cache"
90+
echo "Copy a zpool cache to ./zpool.cache or use -C to disable"
91+
exit 1
92+
fi
93+
fi
94+
fi
95+
96+
# If no config is specified, use in-tree default
97+
if ! [ -r ./config.yaml ]; then
98+
BUILD_ARGS+=( "-c" "/zbm/etc/zfsbootomenu/config.yaml" )
99+
fi
100+
101+
# Make `/build` the working directory so relative paths in a config file make sense
102+
"${PODMAN}" run --rm -v ".:/build" -w "/build" "${BUILD_TAG}" "${BUILD_ARGS[@]}"

0 commit comments

Comments
 (0)