#!/bin/sh -e
#utility to made final work and create romfs ramdisk image

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


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

rd_finish creates romfs ramdisk image from directory prepared by rd_install and rd_init

Valid options are:
  -h, --help	display help screen
  -v, --version	display version information
  -w, --workdir working directory
  -o, --image-file name of the output ramdisk image
		     				     
Report bugs to <inger@altlinux.org>
EOF
	[ -n "$1" ] && exit "$1" || exit
}


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

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

#remove extra files
pushd $workdir/ramdisk
rm -f .pattern
popd

#create ramdisk
/bin/genromfs -d $workdir/ramdisk  -f $image_file
