summaryrefslogtreecommitdiffstats
path: root/tools/mdkinst_stage2_tool
diff options
context:
space:
mode:
authorDexter Morgan <dmorgan@mageia.org>2011-06-02 20:51:35 +0000
committerDexter Morgan <dmorgan@mageia.org>2011-06-02 20:51:35 +0000
commita9b2bdafaf625d10aef2f476aa4014fd36c846bc (patch)
tree2364afc0ee6739b59a25c44d68c9f003bcaf03d9 /tools/mdkinst_stage2_tool
downloaddrakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar
drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.gz
drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.bz2
drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.tar.xz
drakx-a9b2bdafaf625d10aef2f476aa4014fd36c846bc.zip
Branch for updates
Diffstat (limited to 'tools/mdkinst_stage2_tool')
-rwxr-xr-xtools/mdkinst_stage2_tool66
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/mdkinst_stage2_tool b/tools/mdkinst_stage2_tool
new file mode 100755
index 000000000..c1ef5d151
--- /dev/null
+++ b/tools/mdkinst_stage2_tool
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+error() {
+ cat <<EOF;
+usage: mdkinst_stage2_tool [--clean] [--compress | --uncompress] <stage2 dir> [<compressed file>]
+EOF
+ exit 1
+}
+
+if [ "$1" = "--clean" ]; then
+ CLEAN=1
+ shift
+fi
+
+[ $# = 2 -o $# = 3 ] || error
+
+if [ "$1" = "--compress" -o "$1" == "--uncompress" ]; then
+ ACTION=$1
+ shift
+ STAGE2_DIR="$1"
+ shift
+ LIVE_DIR="$STAGE2_DIR/live"
+ if [ -n "$1" ]; then
+ COMPRESSED_IMAGE=$1
+ shift
+ else
+ COMPRESSED_IMAGE="$STAGE2_DIR/mdkinst.sqfs"
+ fi
+else
+ error
+fi
+
+if [ $ACTION = "--compress" ]; then
+ which mksquashfs >/dev/null 2>/dev/null || { echo "missing command mksquashfs (from squashfs-tools)"; exit 1; }
+
+ [ -d "$LIVE_DIR" ] || error
+ echo "Creating $COMPRESSED_IMAGE from $LIVE_DIR"
+ rm -f $STAGE2_DIR/.room
+ mksquashfs $LIVE_DIR $COMPRESSED_IMAGE -all-root -noappend >/dev/null || { echo "mksquashfs failed"; exit 1; }
+ chmod 755 $COMPRESSED_IMAGE
+ echo foo > $STAGE2_DIR/.room
+ if [ -s $STAGE2_DIR/.room ]; then
+ rm -f $STAGE2_DIR/.room
+ [ -n "$CLEAN" ] && rm -rf $LIVE_DIR
+ else
+ echo "not enough space"
+ rm -f $COMPRESSED_IMAGE
+ exit 1
+ fi
+else
+ which unsquashfs >/dev/null 2>/dev/null || { echo "missing command unsquashfs (from squashfs-tools)"; exit 1; }
+
+ [ -f "$COMPRESSED_IMAGE" ] || error
+ echo "Creating $LIVE_DIR from $COMPRESSED_IMAGE"
+
+ if [ $EUID != "0" ]; then
+ SUDO="sudo"
+ PATH="/sbin:/usr/sbin:$PATH"
+ fi
+
+ unsquashfs -dest $LIVE_DIR $COMPRESSED_IMAGE || { rm -rf $LIVE_DIR; exit 1; }
+
+ [ -n "$CLEAN" ] && rm -f $COMPRESSED_IMAGE
+fi
+
+exit 0