28 lines
693 B
Bash
Executable File
28 lines
693 B
Bash
Executable File
#!/bin/sh
|
|
# pick out the drive but not sda because thats the main drive
|
|
choice=`lsblk -lp | \
|
|
grep 'disk ' | \
|
|
awk '{print $1, $4}' | \
|
|
dmenu -i -p 'Drive to (un)mount'`
|
|
if [ -z "$choice" ]; then exit; fi
|
|
|
|
# Check if it's already mounted / something was even picked
|
|
dev=`echo $choice | awk '{print $1}'`
|
|
name="`basename $dev`"
|
|
if [ -z "$dev" ]; then exit; fi
|
|
if grep -qs "$dev" /proc/mounts;
|
|
then
|
|
# unmount the drive
|
|
umount "$HOME/.mounts/$name"
|
|
rm -d "$HOME/.mounts/$name"
|
|
# check if we still need the .mounts directory or nah
|
|
if [ "`ls ~/.mounts/`" ]
|
|
then
|
|
rm -d ~/.mounts/
|
|
fi
|
|
else
|
|
# Finally we can mount the thing
|
|
mkdir -p "~/.mounts/$name"
|
|
mount "$dev" "~/.mounts/$name"
|
|
fi
|