#!/bin/bash #title :srUSBdd.sh #description :Safely remove USB disk drives [in Ubuntu 12.10] #author :mirceamld@gmail.com #date :20130104 #version :0.1a declare -a device declare -a devicename i=0 for dev in $(awk '($4 ~ /sd[b-m]/)&&($4 !~ /sd[b-m][1-9]/) {print "/dev/"$4}' < /proc/partitions) do device[$i]=$dev devicename[$i]=$(udevadm info --query=property -n $dev | grep -e "ID_MODEL=" | awk '{split($0,array,"=")} END{print array[2]}') let "i++" done if [ $i -eq 0 ] then exit 0 fi index=`for ((j=1; j<=i; j++)) do echo $j echo ${device[$j-1]} echo ${devicename[$j-1]} done | zenity --list\ --title="Choose the USB disk you want to detach"\ --column="No" --column="Device" --column="Device info"` if [ -z $index ] then exit 0 fi message="Partition(s) successfully unmounted\nPartition\t\tMount point\n" for partition in $(awk -v hdd="${device[$index-1]}" '$1 ~ hdd {print $1}' < /proc/mounts) do mountpoint=$(awk -v partition="$partition" '$1 ~ partition { print $2 }' < /proc/mounts) udisks --unmount $partition message="$message$partition\t\t$mountpoint\n" done udisks --detach ${device[$index-1]} message="$message\n${devicename[$index-1]} (${device[$index-1]}) can now be safely removed!" zenity --info --text="$message" exit 0