Skip to content

Commit 33c23a9

Browse files
committed
quickstart: preflight-check podman and jq before execution
Add check_prerequisites() to fail fast with actionable install instructions when podman (or an outdated version <4) or jq is missing, rather than hitting a cryptic command-not-found mid-run. Package manager detection covers dnf, apt-get, and zypper.
1 parent f915e4c commit 33c23a9

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/quickstart.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@ TAG=${TAG:-latest}
88

99
LVM_DISK="/var/lib/microshift-okd/lvmdisk.image"
1010
VG_NAME="myvg1"
11+
PODMAN_VMAJOR=4
12+
13+
function check_prerequisites() {
14+
for tool in "$@"; do
15+
if ! command -v "${tool}" &>/dev/null; then
16+
echo "ERROR: '${tool}' is not installed."
17+
echo "Install it with:"
18+
if command -v dnf &>/dev/null; then
19+
echo " sudo dnf install -y ${tool}"
20+
elif command -v apt-get &>/dev/null; then
21+
echo " sudo apt-get install -y ${tool}"
22+
elif command -v zypper &>/dev/null; then
23+
echo " sudo zypper install -y ${tool}"
24+
else
25+
echo " Install '${tool}' using your system package manager"
26+
fi
27+
exit 1
28+
fi
29+
done
30+
}
31+
32+
function check_podman_version() {
33+
local podman_version
34+
podman_version="$(podman --version | awk '/^podman version /{print $3}')"
35+
local podman_major
36+
podman_major="$(echo "${podman_version}" | cut -d. -f1)"
37+
if [ -z "${podman_major}" ] || [ "${podman_major}" -lt "${PODMAN_VMAJOR}" ]; then
38+
echo "ERROR: podman ${podman_version:-unknown} is too old (minimum required: ${PODMAN_VMAJOR}.0)"
39+
echo "Please upgrade podman and try again."
40+
exit 1
41+
fi
42+
}
1143

1244
function pull_bootc_image() {
1345
local -r image_ref="$1"
@@ -109,8 +141,12 @@ if [ "$(id -u)" -ne 0 ]; then
109141
exit 1
110142
fi
111143

144+
check_prerequisites podman
145+
check_podman_version
146+
112147
# For remote images with the 'latest' tag, update the tag to the latest released version
113148
if [[ "${IMAGE}" != localhost/* ]] && [ "${TAG}" == "latest" ]; then
149+
check_prerequisites curl jq
114150
TAG="$(curl -s --max-time 60 "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" | jq -r .tag_name)"
115151
if [ -z "${TAG}" ] || [ "${TAG}" == "null" ] ; then
116152
echo "ERROR: Could not determine the latest release tag from GitHub"

0 commit comments

Comments
 (0)