Add an example about how to run hooks
[ext/instance-debootstrap.git] / export
diff --git a/export b/export
index fea95de..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
@@ -21,9 +21,35 @@ set -e
 
 . common.sh
 
-vol_type=$($VOL_ID -t $blockdev)
+# 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
 
-if [ "$vol_type" = "ext3" -o "$vol_type" = "ext2" ]; then
-  dump -0 -q -f - "$blockdev"
+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
 
+vol_type=$($VOL_TYPE $filesystem_dev)
+
+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
+
+# execute cleanups
+cleanup
+trap - EXIT
+
+exit 0