#!/bin/sh mntpnt="/media" # pick out the drive but not sda because thats the main drive choice=`lsblk -lp | \ grep -e 'part $' -e "part /mnt/*"| \ awk '{print $1, $4}' | \ dmenu -i -l 10 -p 'Drive to (un)mount'` # Ignore empty choices and back out if [ -z "$choice" ]; then exit; fi dev=`echo $choice | awk '{print $1}'` name="`basename $dev`" if [ -z "$dev" ]; then exit; fi # Check if it's already mounted / something was even picked if grep -qs "$dev" /proc/mounts; then echo "Unmounting mounted device $dev" # unmount the drive umount "$mntpnt/$name" rm -d "$mntpnt/$name" # Cleanup the old mount points directory if [ "`ls $mntpnt`" ]; then rm -d "$mntpnt" fi umount $dev rm -d "$mntpnt/$name" else echo "Mounting unmounted device $dev" mkdir -p "$mntpnt/$name" mount "$dev" "$mntpnt/$name" fi