]> arthur.barton.de Git - bup.git/commitdiff
cmd/import-rsnapshot: fix some sh stylistic stuff.
authorAvery Pennarun <apenwarr@gmail.com>
Tue, 4 Jan 2011 08:03:17 +0000 (00:03 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 4 Jan 2011 08:50:02 +0000 (00:50 -0800)
Should not affect functionality.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/import-rsnapshot-cmd.sh

index 4ae422adbc66ea42efa0373c5253fde9b9c06fe8..760fd00ec048ef22f8c03c37801cdda59da5a580 100755 (executable)
@@ -1,72 +1,60 @@
 #!/bin/sh
-# bup-import-rsnapshot.sh
-
 # Does an import of a rsnapshot archive.
 
 usage() {
     echo "Usage: bup import-rsnapshot [-n]" \
         "<path to snapshot_root> [<backuptarget>]"
-    echo "-n,--dry-rung: don't do anything just print out what would be done"
+    echo "-n,--dry-run: just print what would be done"
     exit -1
 }
 
-if [ "$1" = "-n" -o "$1" = "--dry-run" ]; then
-    bup()
-    {
-        echo bup "$@" >&2
-    }
-    shift 1
-elif [ -n "$BUP_MAIN_EXE" ]; then
-    bup()
-    {
-        "$BUP_MAIN_EXE" "$@"
-    }
-else
-    bup()
-    {
-        bup "$@"
-    }
-fi
+DRY_RUN=
+while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
+    DRY_RUN=echo
+    shift
+done
 
-[ "$#" -eq 1 ] || [ "$#" -eq 2 ] || usage
+bup()
+{
+    $DRY_RUN "${BUP_MAIN_EXE:=bup}" "$@"
+}
 
-if [ ! -e "$1/." ]; then
-    echo "$1 isn't a directory!"
-    exit -1
-fi
+SNAPSHOT_ROOT=$1
+TARGET=$2
+
+[ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage
 
-TARGET=
-[ "$#" -eq 2 ] && TARGET="$2"
+if [ ! -e "$SNAPSHOT_ROOT/." ]; then
+    echo "'$SNAPSHOT_ROOT' isn't a directory!"
+    exit 1
+fi
 
 
-ABSPATH=`readlink -f "$1"`
+ABSPATH=$(readlink -f "$SNAPSHOT_ROOT")
 
 for SNAPSHOT in "$ABSPATH/"*; do
     if [ -e "$SNAPSHOT/." ]; then
         for BRANCH_PATH in "$SNAPSHOT/"*; do
             if [ -e "$BRANCH_PATH/." ]; then
                 # Get the snapshot's ctime
-                DATE=`stat -c %Z "$BRANCH_PATH"`
-                BRANCH=`basename "$BRANCH_PATH"`
-                TMPIDX="/tmp/$BRANCH"
+                DATE=$(stat -c %Z "$BRANCH_PATH")
+                BRANCH=$(basename "$BRANCH_PATH")
+                TMPIDX=/tmp/$BRANCH
 
-                if [ "$TARGET" = "" ] || [ "$TARGET" = "$BRANCH" ]; then
+                if [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ]; then
                     bup index -ux \
-                        -f $TMPIDX \
-                        $BRANCH_PATH/
+                        -f "$TMPIDX" \
+                        "$BRANCH_PATH/"
                     bup save \
                         --strip \
                         --date=$DATE \
-                        -f $TMPIDX \
+                        -f "$TMPIDX" \
                         -n $BRANCH \
-                        $BRANCH_PATH/
+                        "$BRANCH_PATH/"
 
-                    if [ -e "$TMPIDX" ]; then
-                        rm "$TMPIDX"
-                    fi
+                    rm -f "$TMPIDX"
                 fi
             fi
         done
     fi
 done
-