83 lines
1.6 KiB
Plaintext
83 lines
1.6 KiB
Plaintext
|
#!/bin/sh
|
||
|
|
||
|
function usage () {
|
||
|
echo "Usage:"
|
||
|
echo "$0 <action>"
|
||
|
}
|
||
|
|
||
|
# If no display found, full text interface. use dmenu and dunstify else.
|
||
|
if [ -z "$DISPLAY" ] ; then
|
||
|
interface=text
|
||
|
function notify () {
|
||
|
echo "$1\n$2"
|
||
|
}
|
||
|
function ask () {
|
||
|
echo "Text interface not implemented. use X :(" >/dev/stderr
|
||
|
exit 1
|
||
|
#TODO
|
||
|
i=0
|
||
|
while read l ; do
|
||
|
echo "$i) $l"
|
||
|
((i++))
|
||
|
done
|
||
|
echo -n "Your choice: "
|
||
|
read choice
|
||
|
if [ "$choice" -le "$i" ] && [ "$choice" -ge 0 ] ; then
|
||
|
echo $i
|
||
|
fi
|
||
|
}
|
||
|
else
|
||
|
interface=x
|
||
|
function notify () {
|
||
|
dunstify "$1" "$2"
|
||
|
}
|
||
|
function ask () {
|
||
|
dmenu
|
||
|
}
|
||
|
fi
|
||
|
|
||
|
|
||
|
if [ "$1" = "mount" ] ; then
|
||
|
action=mount
|
||
|
elif [ "$1" = umount ] || [ "$1" = unmount ] ; then
|
||
|
action=umount
|
||
|
else
|
||
|
usage
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
mounted=""
|
||
|
umounted=""
|
||
|
mounted_nb=0
|
||
|
umounted_nb=0
|
||
|
|
||
|
# List mounted and unmounted disks
|
||
|
while read disk size mountpoint ; do
|
||
|
# Filters. Add yours
|
||
|
[[ "$disk" = /dev/sda* ]] && continue
|
||
|
[ "$disk" = /dev/mapper/cryptroot ] && continue
|
||
|
|
||
|
# Selection
|
||
|
if [ -z "$mountpoint" ] ; then
|
||
|
umounted="$umounted$disk $size\n"
|
||
|
((umounted_nb++))
|
||
|
else
|
||
|
mounted="$mounted$disk $size $mountpoint\n"
|
||
|
((mounted_nb++))
|
||
|
fi
|
||
|
done <<< $(lsblk -prno NAME,SIZE,MOUNTPOINTS)
|
||
|
|
||
|
# Prompt user for disk action
|
||
|
if [ "$action" = "mount" ] ; then
|
||
|
read disk size <<< $(echo -en $umounted | dmenu -i -l "$umounted_nb" -p 'Mount: ')
|
||
|
if [ -b "$disk" ] ; then
|
||
|
notify "Mounting $disk" "$(udisksctl mount -b "$disk" 2>&1)"
|
||
|
fi
|
||
|
elif [ "$action" = "umount" ] ; then
|
||
|
read disk size mountpoint <<< $(echo -en $mounted | dmenu -i -l "$mounted_nb" -p 'Unmount: ')
|
||
|
if [ -b "$disk" ] ; then
|
||
|
notify "Unmounting $disk" "$(udisksctl unmount -b "$disk" 2>&1)"
|
||
|
fi
|
||
|
fi
|
||
|
|