@@ -5,54 +5,83 @@ command=$1
55shift
66declare -a kargs=( " $@ " )
77ret=0
8- args=$( chroot /host/ cat /proc/cmdline)
98
10- IS_OS_UBUNTU=true; [[ " $( chroot /host/ grep -i ubuntu /etc/os-release -c) " == " 0" ]] && IS_OS_UBUNTU=false
9+ if [[ -d " /bindata/scripts" ]]; then
10+ chroot_path=" /host/"
11+ else
12+ chroot_path=" /"
13+ fi
14+
15+ args=$( chroot " $chroot_path " cat /proc/cmdline)
16+
17+ IS_OS_UBUNTU=true; [[ " $( chroot " $chroot_path " grep -i ubuntu /etc/os-release -c) " == " 0" ]] && IS_OS_UBUNTU=false
1118
12- # Kernel args configuration isn't supported for Ubuntu now, so we shouldn't do anything here
1319if ${IS_OS_UBUNTU} ; then
20+ grub_config=" /etc/default/grub"
21+ grub_cmdline=$( grep GRUB_CMDLINE_LINUX_DEFAULT grub)
22+ grub_cmdline=${grub_cmdline// " GRUB_CMDLINE_LINUX_DEFAULT=" / }
23+ grub_cmdline=" ${grub_cmdline// \" } "
24+
25+ for t in " ${kargs[@]} " ; do
26+ if [[ $command == " add" ]]; then
27+ if [[ $args != * ${t} * ]]; then
28+ grub_cmdline=" $grub_cmdline $t "
29+ let ret++
30+ fi
31+ fi
32+ if [[ $command == " remove" ]]; then
33+ if [[ $grub_cmdline == * ${t} * ]]; then
34+ grub_cmdline=$( echo $grub_cmdline | sed " s/\b$t \b//g" | sed ' s/ */ /g' )
35+ let ret++
36+ fi
37+ fi
38+ done
39+
40+ chroot " $chroot_path " sed -i " /GRUB_CMDLINE_LINUX_DEFAULT=.*/c\GRUB_CMDLINE_LINUX_DEFAULT=\" $grub_cmdline \" " $grub_config
41+ chroot " $chroot_path " update-grub
42+
1443 echo $ret
1544 exit 0
1645fi
1746
18- if chroot /host/ test -f /run/ostree-booted ; then
47+ if chroot " $chroot_path " test -f /run/ostree-booted ; then
1948 for t in " ${kargs[@]} " ; do
2049 if [[ $command == " add" ]]; then
2150 if [[ $args != * ${t} * ]]; then
22- if chroot /host/ rpm-ostree kargs | grep -vq ${t} ; then
23- chroot /host/ rpm-ostree kargs --append ${t} > /dev/null 2>&1
51+ if chroot " $chroot_path " rpm-ostree kargs | grep -vq ${t} ; then
52+ chroot " $chroot_path " rpm-ostree kargs --append ${t} > /dev/null 2>&1
2453 fi
2554 let ret++
2655 fi
2756 fi
2857 if [[ $command == " remove" ]]; then
2958 if [[ $args == * ${t} * ]]; then
30- if chroot /host/ rpm-ostree kargs | grep -q ${t} ; then
31- chroot /host/ rpm-ostree kargs --delete ${t} > /dev/null 2>&1
59+ if chroot " $chroot_path " rpm-ostree kargs | grep -q ${t} ; then
60+ chroot " $chroot_path " rpm-ostree kargs --delete ${t} > /dev/null 2>&1
3261 fi
3362 let ret++
3463 fi
3564 fi
3665 done
3766else
38- chroot /host/ which grubby > /dev/null 2>&1
67+ chroot " $chroot_path " which grubby > /dev/null 2>&1
3968 # if grubby is not there, let's tell it
4069 if [ $? -ne 0 ]; then
4170 exit 127
4271 fi
4372 for t in " ${kargs[@]} " ; do
4473 if [[ $command == " add" ]]; then
4574 if [[ $args != * ${t} * ]]; then
46- if chroot /host/ grubby --info=DEFAULT | grep args | grep -vq ${t} ; then
47- chroot /host/ grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
75+ if chroot " $chroot_path " grubby --info=DEFAULT | grep args | grep -vq ${t} ; then
76+ chroot " $chroot_path " grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
4877 fi
4978 let ret++
5079 fi
5180 fi
5281 if [[ $command == " remove" ]]; then
5382 if [[ $args == * ${t} * ]]; then
54- if chroot /host/ grubby --info=DEFAULT | grep args | grep -q ${t} ; then
55- chroot /host/ grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
83+ if chroot " $chroot_path " grubby --info=DEFAULT | grep args | grep -q ${t} ; then
84+ chroot " $chroot_path " grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
5685 fi
5786 let ret++
5887 fi
0 commit comments