diskutil
1 #!/bin/sh 2 3 # helper functions 4 5 # errcho - a variant of echo that prints to stderr 6 errcho() { 7 >&2 echo "$@" 8 } 9 10 # subcommands 11 12 eject() { 13 if [ "$#" -lt 1 ]; then 14 errcho "Usage: diskutil eject MountPoint|DiskIdentifier|DeviceNode" 15 exit 1 16 fi 17 18 DISK_PATH=$1 19 shift; 20 21 if [ ! -e "$DISK_PATH" ]; then 22 errcho "Unable to find disk for $DISK_PATH" 23 exit 1 24 fi 25 26 if ! hdiutil detach "$DISK_PATH" > /dev/null 2>&1; then 27 errcho "Unmount of $DISK_PATH failed: at least one volume could not be unmounted" 28 exit 1 29 fi 30 31 echo "Disk $DISK_PATH ejected" 32 } 33 34 if [ "$#" -lt 1 ]; then 35 >&2 cat <<- 'EOF' 36 Disk Utility Tool 37 Utility to manage local disks and volumes 38 Most commands require an administrator or root user 39 40 WARNING: Most destructive operations are not prompted 41 42 eject (Eject a disk) 43 EOF 44 exit 1 45 fi 46 47 VERB="$1" 48 shift; 49 50 case "$VERB" in 51 eject) 52 eject "$@" 53 ;; 54 *) 55 errcho "diskutil: did not recognize verb \"$VERB\"; type \"diskutil\" for a list" 56 exit 1 57 ;; 58 esac