forked from coreos/ignition-dracut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignition-apply-kargs.sh
executable file
·53 lines (44 loc) · 1.13 KB
/
ignition-apply-kargs.sh
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
#!/bin/bash
set -euo pipefail
cmdline=( $(</proc/cmdline) )
# finds ostree= inside /proc/cmdline
cmdline_arg_ostree() {
name="ostree" value=""
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
break
fi
done
echo "${value}"
}
# finds name value pair inside /proc/cmdline
cmdline_arg() {
local name="$1" value="$2"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
# copied from ignition-generator for testing
cmdline_bool() {
local value=$(cmdline_arg "$@")
case "$value" in
""|0|no|off) return 1;;
*) return 0;;
esac
}
# Checks if kernel argument directory exists,
# then redeploy and reboot the system if it exists
reboot_if_kargs_dir_exists() {
local REFSPEC=( $(ostree refs --repo /sysroot/ostree/repo) )
if [ -d /sysroot/etc/ostree/kargs.d ]; then
ostree admin deploy REFSPEC
exec systemctl reboot
fi
}
if $(cmdline_bool 'ignition.firstboot' 0); then
reboot_if_kargs_dir_exists
fi