2023-04-04 07:00:35 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# List of available drives
|
|
|
|
devices=$(lsblk -lpo "name,size,type,mountpoint" --noheadings | grep -v -e "disk" -e "lvm" -e "nvme" | awk '{if ($4=="") {print $1, "(" $2 ")", "[unmounted]"} else {print $1, "(" $2 ")", "[" $4 "]"}}')
|
|
|
|
|
2023-09-08 18:43:08 +00:00
|
|
|
# menu
|
|
|
|
selected_device=$(echo -e "${devices}" | $RUNNER -i -p "Drive manager" | awk '{print $1}')
|
2023-04-04 07:00:35 +00:00
|
|
|
|
|
|
|
# Verify if the drive is mounted
|
2023-06-18 18:26:38 +00:00
|
|
|
if [ -n "$selected_device" ]; then
|
|
|
|
if [ "$(lsblk -lp | grep "${selected_device}" | awk '{print $7}')" ]; then
|
|
|
|
# Check if the drive is encrypted
|
|
|
|
if [ "$(lsblk -n -o TYPE "${selected_device}")" == "crypt" ]; then
|
|
|
|
mmg_device=$(echo "${selected_device}" | sed -s 's/\/dev\/mapper\///')
|
|
|
|
udisksctl unmount -b "${selected_device}"
|
|
|
|
pkexec cryptsetup close "${mmg_device}"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
# If it's mounted, unmount it
|
|
|
|
udisksctl unmount -b "$selected_device"
|
|
|
|
notify-send "The drive was unmounted successfully"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# If it's not mounted, check if it's an encrypted drive
|
|
|
|
if [ "$(lsblk -n -o FSTYPE "${selected_device}")" == "crypto_LUKS" ]; then
|
|
|
|
# If it's an encrypted drive, prompt for the passphrase and mount it
|
2023-09-08 18:43:08 +00:00
|
|
|
passphrase=$($RUNNER -p "Enter passphrase for ${selected_device}" --password)
|
2023-06-18 18:26:38 +00:00
|
|
|
if [ -n "$passphrase" ]; then
|
|
|
|
echo "$passphrase" | pkexec cryptsetup open "${selected_device}" encrypted_"${selected_device##*/}"
|
|
|
|
udisksctl mount -b /dev/mapper/encrypted_"${selected_device##*/}"
|
|
|
|
notify-send "The encrypted drive was mounted successfully"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
udisksctl mount -b "$selected_device"
|
|
|
|
notify-send "The drive was mounted successfully"
|
2023-04-04 07:00:35 +00:00
|
|
|
exit 1
|
2023-06-18 18:26:38 +00:00
|
|
|
fi
|
2023-04-04 07:00:35 +00:00
|
|
|
else
|
2023-06-18 18:26:38 +00:00
|
|
|
exit 0;
|
2023-04-04 07:00:35 +00:00
|
|
|
fi
|