#!/bin/sh
# Lukasz Pawelczyk <havner@pld-linux.org> 2005
# $Id: livecd_chroot,v 1.1 2006/10/17 09:15:06 havner Exp $

. /etc/rc.d/init.d/functions-live

POLDEK_OPTS=
CHROOT=
POLDEK=
UPDATE=

load_config

usage() {
	echo "--chroot, -c	- chroot to livecd"
	echo "--poldek, -p	- run poldek on chroot system"
	echo "--update, -u	- run poldek --upa on defined sources"
}

while [ "$#" -gt "0" ]; do
	case "$1" in
		--chroot | -c )
		CHROOT=yes
		shift
		;;
		--poldek | -p )
		POLDEK=yes
		shift
		;;
		--update | -u )
		UPDATE=yes
		shift
		;;
		--help )
		usage
		exit 1
		;;
		* )
		echo "Unknown parameter"
		exit 1
		;;
	esac
done

if [ "$CHROOT" = "yes" ]; then
	chroot $ROOTFS /bin/bash --login
	exit $?
fi

if [ "$POLDEK" = "yes" ]; then
	poldek $POLDEK_OPTS --root="$ROOTFS" --uniq
	exit $?
fi

if [ "$UPDATE" = "yes" ]; then
	poldek $POLDEK_OPTS --upa
	exit $?
fi

usage
