neodotfiles/user/.config/fuzzel/scripts/fuzz_mount

41 lines
1.7 KiB
Bash
Executable file

#!/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 "]"}}')
# menu
selected_device=$(echo -e "${devices}" | $RUNNER -i -p "Drive manager" | awk '{print $1}')
# Verify if the drive is mounted
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
passphrase=$($RUNNER -p "Enter passphrase for ${selected_device}" --password)
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"
exit 1
fi
else
exit 0;
fi