2022-10-15 21:14:01 +00:00
#!/bin/bash
type getarg >/dev/null 2>& 1 || . /lib/dracut-lib.sh
GENERATOR_DIR = " $2 "
[ -z " $GENERATOR_DIR " ] && exit 1
[ -d " $GENERATOR_DIR " ] || mkdir " $GENERATOR_DIR "
2022-11-23 09:44:39 +00:00
oem_label = $( getarg rd.cos.oemlabel= )
2023-03-01 11:42:35 +00:00
// Several things indicate booting from a different media so we should not do anything
// rd.cos.disable is set on LIVECD and disables mounting of any type
if getargbool 0 rd.cos.disable; then
exit 0
fi
// Netboot is set on...well, netboot obiously
if getargbool 0 netboot; then
exit 0
fi
2022-11-23 09:44:39 +00:00
# See https://github.com/kairos-io/packages/blob/d12b12b043a71d8471454f7b4fc84c3181d2bf60/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh#L29
{
echo "[Unit]"
echo "DefaultDependencies=no"
echo "Before=cos-immutable-rootfs.service"
2022-11-23 09:59:55 +00:00
echo "Conflicts=initrd-switch-root.target"
2022-11-23 11:51:55 +00:00
if getargbool 0 rd.neednet; then
2022-10-15 21:14:01 +00:00
echo "Wants=network-online.target"
2022-11-23 09:44:39 +00:00
echo "After=network-online.target"
2022-11-23 11:51:55 +00:00
echo "Description=kcrypt online mount"
else
echo "Description=kcrypt mount"
2022-11-23 09:44:39 +00:00
fi
# OEM is special as kcrypt plugins might need that in order to unlock other partitions and plugins can reside in /oem as well and kcrypt needs to find them
if [ -n " ${ oem_label } " ] ; then
echo "After=oem.mount"
fi
2022-11-23 09:59:55 +00:00
echo "After=sysroot.mount"
2022-11-23 09:44:39 +00:00
echo "[Service]"
echo "Type=oneshot"
echo "RemainAfterExit=no"
2022-11-23 10:29:11 +00:00
echo "ExecStart=/usr/bin/kcrypt unlock-all"
2022-11-23 09:44:39 +00:00
} > " $GENERATOR_DIR " /kcrypt.service
2022-10-15 21:14:01 +00:00
if [ ! -e " $GENERATOR_DIR /initrd-fs.target.requires/kcrypt.service " ] ; then
mkdir -p " $GENERATOR_DIR " /initrd-fs.target.requires
ln -s " $GENERATOR_DIR " /kcrypt.service \
" $GENERATOR_DIR " /initrd-fs.target.requires/kcrypt.service
2022-11-23 11:51:55 +00:00
fi