This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
ignition-generator
executable file
·67 lines (58 loc) · 2.09 KB
/
ignition-generator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -e
UNIT_DIR="${1:-/tmp}"
cmdline=( $(</proc/cmdline) )
cmdline_arg() {
local name="$1" value="$2"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
cmdline_bool() {
local value=$(cmdline_arg "$@")
case "$value" in
""|0|no|off) return 1;;
*) return 0;;
esac
}
add_requires() {
local name="$1"; shift
local target="$1"; shift
local requires_dir="${UNIT_DIR}/${target}.requires"
mkdir -p "${requires_dir}"
ln -sf "../${name}" "${requires_dir}/${name}"
}
# This can't be done with ConditionKernelCommandLine because that always
# starts the unit's dependencies. We want to start networking only on first
# boot.
if $(cmdline_bool 'ignition.firstboot' 0); then
add_requires ignition-complete.target initrd.target
# Invoke distro hook for detecting whether we're booted from a live image,
# and therefore won't have a root disk.
if ! command -v is-live-image >/dev/null || ! is-live-image; then
add_requires ignition-diskful.target ignition-complete.target
# ignition-setup-user.service should depend on the boot device node
# only on diskful boots
mkdir -p "${UNIT_DIR}/ignition-setup-user.service.d"
cat > "${UNIT_DIR}/ignition-setup-user.service.d/diskful.conf" <<EOF
[Unit]
Requires=dev-disk-by\x2dlabel-boot.device
After=dev-disk-by\x2dlabel-boot.device
EOF
fi
else
# If we're doing a non-Ignition (subsequent) boot, then
# queue a different target. This is necessary so that units
# like `ignition-ostree-mount-sysroot.service`
# can cleanly distinguish between the two.
add_requires ignition-subsequent.target initrd.target
if ! command -v is-live-image >/dev/null || ! is-live-image; then
add_requires ignition-diskful-subsequent.target ignition-subsequent.target
fi
fi
echo "PLATFORM_ID=$(cmdline_arg ignition.platform.id)" > /run/ignition.env