#!/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

# Create os-release
echo 'NAME="Red Hat Enterprise Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.4:GA"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.4
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.4"

' > etc/os-release

popd > /dev/null
