#!/bin/sh

# Author: 周鹏(Chowroc)
# Date: 2006-12-01
# Email: chowroc.z@gmail.com

# Copy all packages' installation profiles for the crablfs script's
#	'turn key' installation the next time migration or recovery.

if [ $# -lt 1 ]; then
	echo "please give \$homepre directory as an argument" >&2
	exit 1
fi

homepre=$1
dirs=`find "$homepre" -mindepth 1 -maxdepth 1 -type d`
if [ $? -gt 0 ]; then
	echo "terminated by the previous error" >&2
	exit 1
fi

tdir='profiles'
if [ ! -e "$tdir" ]; then
	mkdir "$tdir"
elif [ ! -d "$tdir" ]; then
	echo "target $tdir exists but is not a directory" >&2
fi

for dir in $dirs; do
	echo $dir
	pkgname=`basename "$dir"`
	cp -f "$dir/.config" "$tdir/$pkgname"
done
