diff --git a/install.sh b/install.sh index 7042ed7..641d4a4 100755 --- a/install.sh +++ b/install.sh @@ -7,6 +7,12 @@ if [ -f $run_directory/.disabled ]; then exit 0 fi +if [[ $user != 'root' ]]; then + sudo="sudo" +else + sudo="" +fi + echo "Copying Systemd units to system directory..." for f in $run_directory/mounts.conf.d/*.conf; do if [ ! -e "$f" ]; then @@ -15,25 +21,33 @@ for f in $run_directory/mounts.conf.d/*.conf; do source $f 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 + $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 if [ "${mount[friendly]}" != '' ]; then - sudo sed -i -e "s/PH_FRIENDLY/${mount[friendly]}/g" /etc/systemd/system/$mountfile + $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 + $sudo sed -i -e "s/PH_FRIENDLY/${mount[mapper]}/g" /etc/systemd/system/$mountfile fi if [ ${mount[autolock]} -eq 1 ]; then - sudo mkdir /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d - sudo cp $run_directory/close-vault.conf.template \ + 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 \ /etc/systemd/system/systemd-cryptsetup@${mount[mapper]}.service.d/close-vault.conf - sudo sed -i -e "s/PH_MOUNTFILE/$mountfile/g" \ + $sudo sed -i -e "s/PH_MOUNTFILE/$mountfile/g" \ /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 done echo "Reloading Systemd..." -sudo systemctl daemon-reload +$sudo systemctl daemon-reload echo "Finished install. Exiting..." exit 0 diff --git a/mounts.conf.template b/mounts.conf.template index 2042b2c..3d0dbf2 100644 --- a/mounts.conf.template +++ b/mounts.conf.template @@ -7,3 +7,4 @@ mount[mapper]='' # As in /dev/mapper/ mount[target]='' # Mount point (absolute path) mount[friendly]='' # Optional friendly name for unit file Description mount[autolock]=0 # Set to 1 to enable autolock +mount[timeout]=0 # Set to 1 to enable mount timeout (30 seconds) diff --git a/timeout.conf b/timeout.conf new file mode 100644 index 0000000..8f689e8 --- /dev/null +++ b/timeout.conf @@ -0,0 +1,2 @@ +[Unit] +JobTimeoutSec=30