2019-07-04 20:31:12 +00:00
|
|
|
#!/bin/sh
|
2019-08-29 00:34:42 +00:00
|
|
|
mntpnt="/mnt"
|
|
|
|
|
2019-07-04 20:31:12 +00:00
|
|
|
# pick out the drive but not sda because thats the main drive
|
|
|
|
choice=`lsblk -lp | \
|
2019-08-29 00:34:42 +00:00
|
|
|
grep -e 'part $' -e "part /mnt/*"| \
|
2019-07-05 21:17:10 +00:00
|
|
|
awk '{print $1, $4}' | \
|
|
|
|
dmenu -i -p 'Drive to (un)mount'`
|
|
|
|
if [ -z "$choice" ]; then exit; fi
|
|
|
|
|
2019-07-04 20:31:12 +00:00
|
|
|
dev=`echo $choice | awk '{print $1}'`
|
2019-07-05 21:17:10 +00:00
|
|
|
name="`basename $dev`"
|
|
|
|
if [ -z "$dev" ]; then exit; fi
|
2019-08-29 00:34:42 +00:00
|
|
|
|
|
|
|
# Check if it's already mounted / something was even picked
|
2019-07-05 21:17:10 +00:00
|
|
|
if grep -qs "$dev" /proc/mounts;
|
|
|
|
then
|
|
|
|
# unmount the drive
|
2019-09-07 23:17:33 +00:00
|
|
|
umount "$HOME/.mounts/$name"
|
|
|
|
rm -d "$HOME/.mounts/$name"
|
2019-07-05 21:17:10 +00:00
|
|
|
# check if we still need the .mounts directory or nah
|
|
|
|
if [ "`ls ~/.mounts/`" ]
|
|
|
|
then
|
|
|
|
rm -d ~/.mounts/
|
|
|
|
fi
|
2019-08-29 00:34:42 +00:00
|
|
|
umount $dev
|
|
|
|
rm -d "$mntpnt/$name"
|
2019-07-05 21:17:10 +00:00
|
|
|
else
|
2019-08-29 00:34:42 +00:00
|
|
|
mkdir -p "$mntpnt/$name"
|
|
|
|
mount "$dev" "$mntpnt/$name"
|
2019-07-05 21:17:10 +00:00
|
|
|
fi
|