#!/bin/bash
# Convert old MO to new LZM module format
# Author: Tomas M. <http://www.linux-live.org>
#

if [ "$2" = "" ]; then
   echo
   echo "Convert old format module .mo (ver < 6) to new .lzm format ( ver >= 6 )"
   echo "Usage: $0 oldmod.mo newmod.lzm"
   exit
fi

PATH=.:$(dirname $0):/usr/lib:$PATH
. liblinuxlive || exit 1

allow_only_root

TMP=/tmp/mo2lzm$$
mkdir -p $TMP

# try to mount it first, if we have squashfs support in kernel
mount -o loop -t squashfs "$1" $TMP 2>/dev/null

# if mounting fails, unpack it to tmp. This consumes disk space
if [ $? -ne 0 ]; then
   lzm2dir "$1" $TMP
fi

dir2lzm $TMP "$2"
umount $TMP 2>/dev/null
rm -Rf $TMP
