#!/bin/bash
# Konqueror service menu script to convert old sq3 module to .xzm
# Author: Brokenman <brokenman@porteus.org>

path=${1}
mod=${2}
chk=`file $path/$mod|grep "endian"`
wrk=/tmp/un
nam=${mod%.*}
ext=${mod##*.}

# Check if module is in fact sq3
if [ ! -z "$chk" ]; then
   v4=1
	else
  v3=1
fi

#Convert module
if [ -d $wrk ]; then
   rm -rf $wrk
fi

if [ ! -z $v3 ]; then
mkdir $wrk
kdialog --passivepopup "Unpacking $mod to $nam.xzm ..... please wait" 3
unsquashfs3 -f -dest $wrk $path/$mod
wait

kdialog --passivepopup "Packing $mod to $nam.xzm..." 3
dir2xzm $wrk $path/$nam.xzm
wait
rm -rf $wrk
  else
kdialog --passivepopup "Unpacking $mod to $nam.xzm ..... please wait" 3
xzm2dir $path/$mod $wrk
wait

kdialog --passivepopup "Packing $mod to $nam.xzm...\nWAIT FOR CONFIRMATION WINDOW" 3
dir2xzm $wrk $path/$nam.xzm
fi
