#!/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="AlmaLinux"
VERSION="8.3 (Purple Manul)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.3"
PLATFORM_ID="platform:el8"
PRETTY_NAME="AlmaLinux 8.3 (Purple Manul)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:almalinux:almalinux:8.3:GA"
HOME_URL="https://almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-8"
ALMALINUX_MANTISBT_PROJECT_VERSION="8.3"

' > etc/os-release

popd > /dev/null
