#!/bin/sh -e
#utility to made first initialization of the ramdisk creation engine

if [ "$0" = ./rd_init ]; then
	. ./functions
	lib_dir="$(/bin/pwd)"
else
	. /usr/share/predator/functions
fi

print_usage()
{
	[ "$1" = 0 ] || exec >&2
	cat <<EOF
Usage: $PROG [options]

rd_init initialize aptbox and other directories we need to create ramdisk

Valid options are:
  -h, --help	display help screen
  -v, --version	display version information
  -w, --workdir working directory
  -a, --aptconf name of alternative apt.conf
		     				     
Report bugs to <inger@altlinux.org>
EOF
	[ -n "$1" ] && exit "$1" || exit
}



#parse command line options
TEMP=`getopt -n rd_init -o w:,d:,l:,v,h -l workdir:,aptconf:,version,help -- "$@"` || exit 1
eval set -- "$TEMP"

workdir=
deps_file=
langs=
while :; do
	case "$1" in
		-h|--help) print_usage 0
			;;
		-w|--workdir)
			shift
			workdir="$1"
		    ;;
		-a|--aptconf)
			shift
			aptconf="$1"
		    ;;
		-v|--version) print_version
		    ;;
		--) shift; break
		   ;;
		*) "unrecognized option: $1"
		    exit 1
			;;
	esac
	shift
done

#cleanup files from previous work
mkdir -p $workdir
rm -rf $workdir/aptbox

#create aptbox
if [ -z "$aptconf" ]
then
    $hasher_datadir/mkaptbox --update --no-stuff $workdir
else
    $hasher_datadir/mkaptbox --update --no-stuff --apt-config $aptconf $workdir
fi
