#!/bin/sh
pkgmgr="python /usr/sbin/packagemanager"

dir=/var/tmp/packagemanager
bcfg2=/var/lib/bcfg2

if [ "$1" = "autoupdate" ]
then
 $pkgmgr autoupdate
fi

[ -d "/etc/puppet" ] && $0-puppet

localscript=/usr/local/sbin/update-packagelists.local
if [ -x "$localscript" ]
then
	$localscript
fi

[ -d "$bcfg2" ] || exit 0

[ -n "$dir" ] || exit 1
[ -d "$dir" ] || mkdir "$dir" || exit 1
rm -rf "$dir/*"
mkdir -p "$dir/Bundler" "$dir/Pkgmgr"

$pkgmgr autoprofiles "$dir/autoprofiles.xml"
$pkgmgr exportxml    "$dir"

mv $dir/Pkgmgr/* $bcfg2/Pkgmgr
mv $dir/Bundler/* $bcfg2/Bundler
mv $dir/autoprofiles.xml $bcfg2/Metadata
