#!/bin/bash

. /etc/DISTRO_SPECS

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

if [ ! -d "$t" ];then

  echo "error: no valid folder specified!"
  exit 0

fi

### if no _versionnummer in the end, get it from system
check=`echo $t | sed "s/\(.*\)_[0-9][0-9][0-9]$/\1/"`

#echo --- $check

if [ "$check" == "$t" ];then

  v=$DISTRO_VERSION
  z="${check}_$v"

fi
#echo $t - $z


if [ -f "$z.sfs" ];then

  echo "$z.sfs already exists, refusing to overwrite it!"
  exit 0

fi

mksquashfs "$t" "$z.sfs"
md5sum "$z.sfs" > "$z.sfs-md5.txt"
sync


echo
echo
s=`du -m "$z.sfs" | sed "s/\s.*//"`
echo "created: $z.sfs ( $s MB )"
echo "created: $z.sfs-md5.txt"
echo
echo "...byebye..."
echo
