#
# vim:set sw=4 ts=4:
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: 
path=etc
output_path=output
basename=myname
section=mega
Section=$(echo $section | tr "[:lower:]" "[:upper:]")

export LANG=C
#
# search the files
#
##             section=<section to scan>
##             mode=<file mode (permissions)>
##             user=<owner of the file>
##             group=<group owner>
##             path=<path to place the file>
##             name=<tag name in section to find contents>
##             filter=<filter to modify the tags content>

mkdir -p $output_path
> $output_path/${basename}.${section}.tcf
> $output_path/${basename}.misc.tcf
#
# TODO: file names must not contain spaces
#
echo "Importing config files"
(
    echo "<MISC_FILE_TABLE>"
    find $path -type f -print | while read file
    do
	tag=$(echo $file | sed -e "s/[ -/]/_/g");
	stat --format="section=mega name=$tag mode=%a; gid=%g; uid=%u; path=/%n" $file
	(
	    echo "<${Section}_${tag}>"
	    cat $file 
	    echo "</${Section}_${tag}>"
	) >> $output_path/${basename}.${section}.tcf
	printf "." >&2
    done
    echo "</MISC_FILE_TABLE>"
) > $output_path/${basename}.misc.tcf
#
# search the links
#
echo
echo "Importing symbolic links"
(
    echo "<MISC_CFG_LINKS>"
    find $path -type l -print | while read link
    do
	ls -l $link | awk '{ print $9 " " $11 }'
	printf "." >&2
    done
    echo "</MISC_CFG_LINKS>"
) >> $output_path/${basename}.misc.tcf
printf "\n" >&1
