]> oss.titaniummirror.com Git - ovzbpc.git/commitdiff
esata: new known state partitioned
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 29 Jan 2013 03:57:00 +0000 (20:57 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 29 Jan 2013 04:01:52 +0000 (21:01 -0700)
Properly determines a registered state independently of a partitioned
drive.  Before, the script simply looked for /dev/sdX2 to determine
registration state.  This would be inaccurate when a drive with no
partition table was registered.

esata

diff --git a/esata b/esata
index 87f08ae643f5831e163267db541b149de4e78c28..f95995aee2f8ed1e653c21d585754d64e32bab63 100755 (executable)
--- a/esata
+++ b/esata
@@ -5,13 +5,16 @@
 #
 # Add, remove, mount, and unmount external SATA drives
 
-DEV=/dev/sdb2
+BASEDEV=/dev/sdc
+PARTITION=2
 MNT=/media/esata
+SCSIDEV=3 # This can change based on OS, bus enumeration, etc.
+# ----
+DEV=${BASEDEV}${PARTITION}
 DELAY=5
-SCSIDEV=1 # This can change based on OS, etc.
 
 registered() {
-    if [ -b "$DEV" ]; then
+    if [ -b "$BASEDEV" ]; then
        [ -n "$VERBOSE" ] && echo "registered"
        return 0
     else
@@ -20,6 +23,16 @@ registered() {
     fi
 }
 
+partitioned() {
+    if [ -b "$DEV" ]; then
+       [ -n "$VERBOSE" ] && echo "partitioned"
+       return 0
+    else
+       [ -n "$VERBOSE" ] && echo "not partitioned"
+       return 1
+    fi
+}
+
 mounted() {
     if mount | grep -q "$MNT"; then
        [ -n "$VERBOSE" ] && echo "mounted"
@@ -43,6 +56,7 @@ doregister() {
 domount() {
     mounted && return 0
     doregister || return 1
+    partitioned || return 1
     [ -n "$VERBOSE" ] && echo "mount SATA $DEV"
     mkdir -p "$MNT" || return 1
     mount "$DEV" "$MNT" || return 1
@@ -94,7 +108,8 @@ elif [ "$1" = "umount" -o "$1" = "unmount" ]; then
     fi
 elif [ "$1" = "register" ]; then
     if doregister; then
-       echo "esata registered as $DEV"
+       echo "esata drive registered as $BASEDEV"
+       partitioned || echo "WARNING: drive is not partitioned"
     else
        echo "$0: cannot register esata" >&2
        exit 1
@@ -103,7 +118,8 @@ elif [ "$1" = "status" ]; then
     if mounted; then
        echo "esata mounted on $MNT"
     elif registered; then
-       echo "esata registered as $DEV but not mounted"
+       echo "esata registered as $BASEDEV but not mounted"
+       partitioned || echo "WARNING: drive is not partitioned"
     else
        echo "esata is unregistered"
     fi