2019-07-04 20:31:12 +00:00
|
|
|
#!/bin/sh
|
2022-04-14 04:16:03 +00:00
|
|
|
mntpnt="/media"
|
2019-08-29 00:34:42 +00:00
|
|
|
|
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}' | \
|
2022-04-14 04:16:03 +00:00
|
|
|
dmenu -i -l 10 -p 'Drive to (un)mount'`
|
|
|
|
|
|
|
|
# Ignore empty choices and back out
|
2019-07-05 21:17:10 +00:00
|
|
|
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
|
2022-04-14 04:16:03 +00:00
|
|
|
if grep -qs "$dev" /proc/mounts; then
|
|
|
|
echo "Unmounting mounted device $dev"
|
2019-07-05 21:17:10 +00:00
|
|
|
# unmount the drive
|
2022-04-14 04:16:03 +00:00
|
|
|
umount "$mntpnt/$name"
|
|
|
|
rm -d "$mntpnt/$name"
|
|
|
|
|
|
|
|
# Cleanup the old mount points directory
|
|
|
|
if [ "`ls $mntpnt`" ]; then
|
|
|
|
rm -d "$mntpnt"
|
2019-07-05 21:17:10 +00:00
|
|
|
fi
|
2019-08-29 00:34:42 +00:00
|
|
|
umount $dev
|
|
|
|
rm -d "$mntpnt/$name"
|
2019-07-05 21:17:10 +00:00
|
|
|
else
|
2022-04-14 04:16:03 +00:00
|
|
|
echo "Mounting unmounted device $dev"
|
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
|