crypt-mounts/install.sh

56 lines
1.9 KiB
Bash
Raw Normal View History

2022-03-16 16:23:29 +01:00
#!/usr/bin/env bash
run_directory=$(dirname $(readlink -f "$0"))
2024-08-12 20:31:07 +02:00
user=$(whoami)
2022-03-17 15:11:40 +01:00
2022-03-17 14:57:53 +01:00
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
if [[ $user != 'root' ]]; then
sudo="sudo"
else
sudo=""
fi
2022-03-16 16:23:29 +01:00
echo "Copying Systemd units to system directory..."
2022-03-17 15:11:40 +01:00
for f in $run_directory/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 $run_directory/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
2023-07-27 16:29:06 +02:00
$sudo sed -i -e "s:PH_FSTYPE:${mount[type]}:g" /etc/systemd/system/$mountfile
2022-03-16 16:23:29 +01:00
if [ "${mount[friendly]}" != '' ]; then
$sudo sed -i -e "s/PH_FRIENDLY/${mount[friendly]}/g" /etc/systemd/system/$mountfile
2022-03-16 16:23:29 +01:00
else
$sudo sed -i -e "s/PH_FRIENDLY/${mount[mapper]}/g" /etc/systemd/system/$mountfile
2022-03-16 16:23:29 +01:00
fi
2022-03-16 17:23:38 +01:00
if [ ${mount[autolock]} -eq 1 ]; then
if [ ! -d /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d ]; then
$sudo mkdir /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d
fi
$sudo cp $run_directory/close-vault.conf.template \
2022-03-16 16:23:29 +01:00
/etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/close-vault.conf
$sudo sed -i -e "s/PH_MOUNTFILE/$mountfile/g" \
2022-03-16 16:23:29 +01:00
/etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/close-vault.conf
fi
if [ ${mount[timeout]} -eq 1 ]; then
if [ ! -d /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d ]; then
$sudo mkdir /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d
fi
$sudo cp $run_directory/timeout.conf /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/timeout.conf
fi
2022-03-16 16:23:29 +01:00
done
echo "Reloading Systemd..."
$sudo systemctl daemon-reload
2022-03-16 16:23:29 +01:00
echo "Finished install. Exiting..."
exit 0