#!/bin/sh

if [ $# -ne 1 -a $# -ne 2 ]; then
	echo "usage: pcs5xx_customise dir [target]"
	echo "    where dir is the directory containing the custom files"
	echo "    and target is the name of the generated file - default = pcs5xx-256M.site"
	echo
	exit
fi

base=$1
of=/SpliceCom/ftp/tftp/pcs5xx-256M.site
if [ $# -ne 1 ]; then
	of=/SpliceCom/ftp/tftp/$2
fi

if [ ! -d $base ]; then
	echo "$base is not a directory"
	exit
fi

if [ ! -d $base/ringtunes -a ! -d $base/logos -a ! -d $base/translations ]; then
        echo "The directory specified should contain a subdirectory"
        echo "called ringtunes and/or logos and/or translations"
        exit
fi


if [ -d $base/ringtunes ]; then
	echo found ringtunes:
	for x in $base/ringtunes/Ring\ Tune\ [3-9].wav; do
		b=`basename "$x"`
		echo "    $b"
	done
fi

if [ -d $base/translations ]; then                                              
        echo found translations:                                                
        for x in $base/translations/*.strings; do                               
                b=`basename "$x"`                                   
                echo "    $b"                                   
        done                                              
fi                                                        

if [ -f $base/logos/logosmall.png ]; then
	echo found logo: logosmall.png for PCS560/570
fi

if [ -f $base/logos/logobig.png ]; then
	echo found logo: logobig.png for PCS580
fi

/SpliceCom/bin/mkfs.jffs2 --pad --eraseblock=131072 --little-endian \
        --no-cleanmarkers --root=$base --output=$of
	        
sz=`wc -c $of | awk '{print $1}'`
if [ $sz -gt 8388608 ]; then
	echo Files are too big
	rm $of
	exit
fi

echo PCS5xx site customisation file installed and ready for PCS5xx upgrade.
