#!/bin/bash
# convert .MO compressed file back into directory tree
#
# Author: Tomas M. <http://www.linux-live.org>
#

if [ ! -d "$2" ]; then
   echo 
   echo "Convert .MO compressed module back into directory tree"
   echo "usage: $0 source_file.mo existing_output_directory"
   exit 1
fi

if [ -a ./liblinuxlive ]; then
   . ./liblinuxlive
else
   . /usr/lib/liblinuxlive || exit 1
fi

allow_only_root

TMPDIR=/tmp/mo2dir$$

mkdir -p $TMPDIR
mount_module "$1" "$TMPDIR" 2>/dev/null
if [ $? -ne 0 ]; then
   echo "Error mounting module. Please make sure it's squashfs filesystem."
   echo "If you are in unioned dir, try to move the module outside of the union"
   echo "eg. to harddisk partition or /mnt/live/memory ... then try $0 again"
   exit
fi
cp -R --preserve=all $TMPDIR/* "$2"
umount "$TMPDIR"
rmdir "$TMPDIR"
