···11+#!/bin/sh
22+33+# helper functions
44+55+# errcho - a variant of echo that prints to stderr
66+errcho() {
77+ >&2 echo $@
88+}
99+1010+# subcommands
1111+1212+eject() {
1313+ if [ "$#" -lt 1 ]; then
1414+ errcho "Usage: diskutil eject MountPoint|DiskIdentifier|DeviceNode"
1515+ exit 1
1616+ fi
1717+1818+ DISK_PATH=$1
1919+ shift;
2020+2121+ if [ ! -e "$DISK_PATH" ]; then
2222+ errcho "Unable to find disk for $DISK_PATH"
2323+ exit 1
2424+ fi
2525+2626+ if ! hdiutil detach "$DISK_PATH" > /dev/null 2>&1; then
2727+ errcho "Unmount of $DISK_PATH failed: at least one volume could not be unmounted"
2828+ exit 1
2929+ fi
3030+3131+ echo "Disk $DISK_PATH ejected"
3232+}
3333+3434+if [ "$#" -lt 1 ]; then
3535+ >&2 cat <<- 'EOF'
3636+ Disk Utility Tool
3737+ Utility to manage local disks and volumes
3838+ Most commands require an administrator or root user
3939+4040+ WARNING: Most destructive operations are not prompted
4141+4242+ eject (Eject a disk)
4343+ EOF
4444+ exit 1
4545+fi
4646+4747+VERB="$1"
4848+shift;
4949+5050+case "$VERB" in
5151+ eject)
5252+ eject $@
5353+ ;;
5454+ *)
5555+ errcho "diskutil: did not recognize verb \"$VERB\"; type \"diskutil\" for a list"
5656+ exit 1
5757+ ;;
5858+esac