Add an example about how to run hooks
[ext/instance-debootstrap.git] / export
diff --git a/export b/export
index 31fc235..46aa74c 100755 (executable)
--- a/export
+++ b/export
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/bin/bash
 
-# Copyright (C) 2007 Google Inc.
+# Copyright (C) 2007, 2008, 2009 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 
 set -e
 
-TEMP=`getopt -o i:b: -n '$0' -- "$@"`
+. common.sh
 
-if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
-
-# Note the quotes around `$TEMP': they are essential!
-eval set -- "$TEMP"
-
-while true; do 
-       case "$1" in
-               -i) instance="$2"; shift 2;;
+# If the target device is not a real block device we'll first losetup it.
+# This is needed for file disks.
+if [ ! -b $blockdev ]; then
+  ORIGINAL_BLOCKDEV=$blockdev
+  blockdev=$(losetup -sf $blockdev)
+  CLEANUP+=("losetup -d $blockdev")
+fi
 
-               -b) blockdev="$2"; shift 2;;
+if [ "$PARTITION_STYLE" = "none" ]; then
+  filesystem_dev=$blockdev
+elif [ "$PARTITION_STYLE" = "msdos" ]; then
+  filesystem_dev=$(map_disk0 $blockdev)
+  CLEANUP+=("unmap_disk0 $blockdev")
+else
+  echo "Unknown partition style $PARTITION_STYLE"
+  exit 1
+fi
 
-               --) shift; break;;
+vol_type=$($VOL_TYPE $filesystem_dev)
 
-               *)  echo "Internal error!"; exit 1;;
-       esac
-done
-if [ -z "$blockdev" ]; then
-       echo "Missing -b argument!"
-       exit 1
+if [ "${vol_type:0:3}" = "ext" ]; then
+  dump -0 -q -f - "$filesystem_dev"
+else
+  echo "Can't dump partition of type ${vol_type}!" >&2
+  exit 1
 fi
 
-dump -0 -q -f - "$blockdev"
+# execute cleanups
+cleanup
+trap - EXIT
+
+exit 0