mildly working usb mount script

This commit is contained in:
shockrahwow 2019-07-05 14:17:10 -07:00
parent 6de10846e6
commit 6c34743c37

29
usm Normal file → Executable file
View File

@ -1,10 +1,27 @@
#!/bin/sh #!/bin/sh
# pick out the drive but not sda because thats the main drive # pick out the drive but not sda because thats the main drive
choice=`lsblk -lp | \ choice=`lsblk -lp | \
grep 'disk $' | awk '{print $1, $4}' | grep -v 'sda' | \ grep 'disk ' | \
dmenu -i -p 'Drive to mount'` 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}'` dev=`echo $choice | awk '{print $1}'`
if [ -z "$dev" ];then exit 0;fi name="`basename $dev`"
# Finally we can mount the thing if [ -z "$dev" ]; then exit; fi
mkdir -p "/mnt/`basename $dev`" if grep -qs "$dev" /proc/mounts;
mount "$dev" "$name" then
# unmount the drive
umount "~/.mounts/$name"
rm -d "~/.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