From 6c34743c373c072341507ba85670e5bbcf8b146e Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Fri, 5 Jul 2019 14:17:10 -0700 Subject: [PATCH] mildly working usb mount script --- usm | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) mode change 100644 => 100755 usm diff --git a/usm b/usm old mode 100644 new mode 100755 index 4101253..8066f69 --- a/usm +++ b/usm @@ -1,10 +1,27 @@ #!/bin/sh # pick out the drive but not sda because thats the main drive choice=`lsblk -lp | \ - grep 'disk $' | awk '{print $1, $4}' | grep -v 'sda' | \ - dmenu -i -p 'Drive to mount'` + 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}'` -if [ -z "$dev" ];then exit 0;fi -# Finally we can mount the thing -mkdir -p "/mnt/`basename $dev`" -mount "$dev" "$name" +name="`basename $dev`" +if [ -z "$dev" ]; then exit; fi +if grep -qs "$dev" /proc/mounts; +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