Created
May 1, 2021 00:46
-
-
Save theandrewbailey/3b5bbb3fa3a53c2ef0e1ffb84a9e172c to your computer and use it in GitHub Desktop.
bash script to unlock, mount, backup to, unmount, and lock an encrypted external drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
backupfrom="/srv/smb/" | |
blockdev=${1:-/dev/sdd1} | |
permunlock=$(pkaction|grep org.freedesktop.udisks2.encrypted-unlock) | |
permmount=$(pkaction|grep org.freedesktop.udisks2.filesystem-mount) | |
if [[ -z "$permunlock" ]] || [[ -z "$permmount" ]]; then | |
echo "enter disk password first, then login password twice" | |
echo "login password prompts can be eliminated via polkit" | |
echo "see script source for details" | |
fi | |
device=$(udisksctl unlock -b $blockdev | grep -Po "(?<= as )/[0-9A-Za-z/-]+") | |
direct=$(udisksctl mount -b $device | grep -Po "(?<= at )/[0-9A-Za-z/-]+") | |
if [[ $? -eq 0 ]] ; then | |
rsync -atP --del $backupfrom $direct | |
fi | |
udisksctl unmount -b $device | |
udisksctl lock -b $blockdev | |
exit | |
# add polkit permissions in /etc/polkit-1/localauthority/50-local.d/10-encmount.pkla | |
# I'm not sure what all of these do | |
[udisks] | |
Identity=unix-group:sudo | |
Action=org.freedesktop.udisks2.* | |
ResultAny=yes | |
ResultInactive=no | |
ResultActive=yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment