crypt-mounts/install.sh

38 lines
1.3 KiB
Bash
Raw Normal View History

2022-03-16 16:23:29 +01:00
#!/usr/bin/env bash
2022-03-17 14:57:53 +01:00
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
2022-03-16 16:23:29 +01:00
echo "Copying Systemd units to system directory..."
for f in $(dirname "$0")/mounts.conf.d/*.conf; do
if [ ! -e "$f" ]; then
continue
fi
source $f
2022-03-16 16:23:29 +01:00
mountfile=$(echo ${mount[target]} | sed -e "s:/:-:g")
mountfile=${mountfile:1}.mount
sudo cp $(dirname "$0")/template.mount /etc/systemd/system/$mountfile
sudo sed -i -e "s/PH_MAPPER/${mount[mapper]}/g" /etc/systemd/system/$mountfile
sudo sed -i -e "s:PH_TARGET:${mount[target]}:g" /etc/systemd/system/$mountfile
if [ "${mount[friendly]}" != '' ]; then
sudo sed -i -e "s/PH_FRIENDLY/${mount[friendly]}/g" /etc/systemd/system/$mountfile
else
sudo sed -i -e "s/PH_FRIENDLY/${mount[mapper]}/g" /etc/systemd/system/$mountfile
fi
2022-03-16 17:23:38 +01:00
if [ ${mount[autolock]} -eq 1 ]; then
2022-03-16 17:35:41 +01:00
sudo mkdir /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d
2022-03-16 16:23:29 +01:00
sudo cp $(dirname "$0")/close-vault.conf.template \
/etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/close-vault.conf
sudo sed -i -e "s/PH_MOUNTFILE/$mountfile/g" \
/etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/close-vault.conf
fi
done
echo "Reloading Systemd..."
sudo systemctl daemon-reload
echo "Finished install. Exiting..."
exit 0