From: smckown Date: Fri, 4 Apr 2008 22:33:03 +0000 (+0000) Subject: Mount only the second partition, which is where the data will do; the first X-Git-Url: https://oss.titaniummirror.com/gitweb?a=commitdiff_plain;h=ad3c0e30569faf949229c0f855842914516dff08;p=ovzbpc.git Mount only the second partition, which is where the data will do; the first partition contains a recovery OS that doesn't need to be mounted except to boot off the removeable drive. Also, add a verbose option and cleanup the output. --- diff --git a/esata b/esata index ba81667..34398eb 100755 --- a/esata +++ b/esata @@ -1,61 +1,79 @@ #!/bin/bash -DEV=/dev/sdb -MNT=/media/esata- +DEV=/dev/sdb2 +MNT=/media/esata DELAY=3 registered() { if [ -b "$DEV" ]; then + [ -n "$VERBOSE" ] && echo "registered" return 0 else + [ -n "$VERBOSE" ] && echo "not registered" return 1 fi } mounted() { if mount | grep -q "$MNT"; then + [ -n "$VERBOSE" ] && echo "mounted" return 0 else + [ -n "$VERBOSE" ] && echo "not mounted" return 1 fi } doregister() { registered && return 0 + [ -n "$VERBOSE" ] && echo "register SATA device" scsiadd -a 1 0 0 0 >/dev/null || return 1 sleep $DELAY - registered && return 0 || return 0 + registered || return 1 + [ -n "$VERBOSE" ] && echo "register ok" + return 0 } domount() { mounted && return 0 doregister || return 1 - mkdir -p "${MNT}1" || return 1 - mount ${DEV}1 ${MNT}1 || return 1 - mkdir -p "${MNT}2" || return 1 - mount ${DEV}2 ${MNT}2 || return 1 + [ -n "$VERBOSE" ] && echo "mount SATA $DEV" + mkdir -p "$MNT" || return 1 + mount "$DEV" "$MNT" || return 1 + [ -n "$VERBOSE" ] && echo "mount ok" return 0 } dounregister() { registered || return 0 + [ -n "$VERBOSE" ] && echo "unregister SATA device" scsiadd -r 1 0 0 0 >/dev/null || return 1 sleep $DELAY - registered && return 1 || return 0 + registered && return 1 + [ -n "$VERBOSE" ] && echo "unregister ok" + return 0 } doumount() { mounted || return 0 - umount ${MNT}2 || return 1 - umount ${MNT}1 || return 1 + [ -n "$VERBOSE" ] && echo "unmount SATA $DEV" + umount "$MNT" || return 1 mounted && return 1 + [ -n "$VERBOSE" ] && echo "unmount ok" dounregister || return 1 return 0 } +# MAIN + +unset VERBOSE +if [ "$1" = "-v" ]; then + VERBOSE=1 + shift +fi if [ "$1" = "mount" ]; then if domount; then - echo "esata is mounted" + echo "esata mounted on $MNT" else echo "$0: cannot mount esata" >&2 dounregister @@ -69,22 +87,22 @@ elif [ "$1" = "umount" -o "$1" = "unmount" ]; then fi elif [ "$1" = "register" ]; then if doregister; then - echo "esata is registered" + echo "esata registered as $DEV" else echo "$0: cannot register esata" >&2 exit 1 fi elif [ "$1" = "status" ]; then if mounted; then - echo "esata is mounted" + echo "esata mounted on $DEV" elif registered; then - echo "esata is registered but not mounted" + echo "esata registered as $DEV but not mounted" else echo "esata is unregistered" fi #mount | grep "$DEV" #scsiadd -p | grep "scsi1" else - echo "usage: $0 [mount|umount|register|status]" + echo "usage: $0 [-v] " fi exit 0