#!/bin/bash
#
# (c) Lorenzo Canovi (KUBiC Labs, CH) <packager@kubiclabs.com>
# for copyright see /usr/share/doc/kusa/copyright
#
CMD=`basename $0`

set -e
set -u

cfgfile="/etc/kusa/customfiles"
logfile="/etc/kusa/customfiles.log"
tarfile="/etc/kusa/customfiles.tar.gz"
tmpfile=`mktemp /tmp/$CMD-XXXXXXX.tmp`

[ -f $cfgfile ] || {
	echo "config file '$cfgfile' not found, exit"
	exit 1
}

cd /
sed -e 's/[ ,	]*#.*//' -e '/^[ ,	]*$/d' $cfgfile >$tmpfile
echo -n "saving custom files to $tarfile ... "
tar cvfz $tarfile `cat $tmpfile` >$logfile 2>&1 || {
	stat=$?
	echo -e "errors!\nsee $logfile for details" >&2
	exit $stat
}
echo "ok"

exit 0
