#!/bin/bash

#sanify check

if [ $# -lt 1 ] ; then
	echo "usage $0 ROOTDIR"
	exit 1
fi

rootdir=$1

if [ -z "$rootdir" ]; then
	echo "ROOTDIR is not set."
	exit 1
fi
		
# Check root directory
if [ ! -d $rootdir ]; then
	echo "$rootdir: should be a directory."
	exit 1
fi

pushd $rootdir > /dev/null
# Bootstrap a minimal chroot tree for the rest installation
mkdir -p var/lib/rpm
mkdir -p var/tmp
mkdir -p dev
mkdir -p run
ln -s ../run var/run

chmod 666 dev/null

# Make /sbin as symlink, so move the /sbin/init
mkdir -p usr/sbin
mv sbin/* usr/sbin
rm -rf sbin
ln -s usr/sbin sbin

mkdir -p etc/sysconfig
touch etc/sysconfig/network
touch etc/fstab

popd > /dev/null
