-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add ignition-kargs binary example
- Loading branch information
Stephen Lowrie
committed
Apr 28, 2021
1 parent
4e06be9
commit 383893d
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
# Requires sed & awk to be present | ||
|
||
set -euxo pipefail | ||
|
||
# Mount /boot. Note that we mount /boot but we don't unmount it because we | ||
# are run in a systemd unit with MountFlags=slave so it is unmounted for us. | ||
bootmnt=/mnt/boot_partition | ||
mkdir -p ${bootmnt} | ||
bootdev=/dev/disk/by-label/boot | ||
mount -o rw ${bootdev} ${bootmnt} | ||
grubcfg="${bootmnt}/grub/grub.cfg" | ||
|
||
kernelopts="$(grep kernelopts= <$grubcfg | sed \"s,kernelopts=,,g\")" | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
--should-exist) | ||
arg="$2" | ||
# don't repeat the arg | ||
if [[ ! " ${kernelopts[*]} " =~ " ${arg} " ]]; then | ||
kernelopts="$kernelopts $arg " | ||
fi | ||
shift 2 | ||
;; | ||
--should-not-exist) | ||
kernelopts="$(echo "$kernelopts" | sed "s|$2||g")" | ||
shift 2 | ||
;; | ||
*) | ||
echo "Unknown option" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# only apply the changes & reboot if changes have been made | ||
if [[ "$kernelopts" != "$(grep kernelopts= <$grubcfg)" ]]; then | ||
awk "{sub(/kernelopts=.*/,\"kernelopts=$kernelopts\"); print}" $grubcfg > /run/kargs_tmp && mv /run/kargs_tmp $grubcfg | ||
|
||
systemctl reboot | ||
fi |