#!/bin/bash
set -e

pushd "${LFS}" > /dev/null || exit 1

printf "%b" "${GRN}Creating directories${RST}... "
if [[ -f sources/createdirs ]]; then
	printf "%b" "\n  ${IGRN}Directories already created${RST}\n"
else {
	sudo mkdir -pv boot
	sudo mkdir -pv home
	sudo mkdir -pv mnt
	sudo mkdir -pv opt
	sudo mkdir -pv srv

	sudo mkdir -pv etc/opt
	sudo mkdir -pv etc/sysconfig
	sudo mkdir -pv lib/firmware
	sudo mkdir -pv media/floppy
	sudo mkdir -pv media/cdrom
	sudo mkdir -pv usr/bin
	sudo mkdir -pv usr/include
	sudo mkdir -pv usr/lib
	sudo mkdir -pv usr/sbin
	sudo mkdir -pv usr/src
	sudo mkdir -pv usr/local/bin
	sudo mkdir -pv usr/local/include
	sudo mkdir -pv usr/local/lib
	sudo mkdir -pv usr/local/sbin
	sudo mkdir -pv usr/local/src
	sudo mkdir -pv usr/share/color
	sudo mkdir -pv usr/share/dict
	sudo mkdir -pv usr/share/doc
	sudo mkdir -pv usr/share/info
	sudo mkdir -pv usr/share/locale
	sudo mkdir -pv usr/share/man
	sudo mkdir -pv usr/local/share/color
	sudo mkdir -pv usr/local/share/dict
	sudo mkdir -pv usr/local/share/doc
	sudo mkdir -pv usr/local/share/info
	sudo mkdir -pv usr/local/share/locale
	sudo mkdir -pv usr/local/share/man
	sudo mkdir -pv usr/share/misc
	sudo mkdir -pv usr/share/terminfo
	sudo mkdir -pv usr/share/zoneinfo
	sudo mkdir -pv usr/local/share/misc
	sudo mkdir -pv usr/local/share/terminfo
	sudo mkdir -pv usr/local/share/zoneinfo
	sudo mkdir -pv usr/share/man/man1
	sudo mkdir -pv usr/share/man/man2
	sudo mkdir -pv usr/share/man/man3
	sudo mkdir -pv usr/share/man/man4
	sudo mkdir -pv usr/share/man/man5
	sudo mkdir -pv usr/share/man/man6
	sudo mkdir -pv usr/share/man/man7
	sudo mkdir -pv usr/share/man/man8
	sudo mkdir -pv usr/local/share/man/man1
	sudo mkdir -pv usr/local/share/man/man2
	sudo mkdir -pv usr/local/share/man/man3
	sudo mkdir -pv usr/local/share/man/man4
	sudo mkdir -pv usr/local/share/man/man5
	sudo mkdir -pv usr/local/share/man/man6
	sudo mkdir -pv usr/local/share/man/man7
	sudo mkdir -pv usr/local/share/man/man8
	sudo mkdir -pv var/cache
	sudo mkdir -pv var/local
	sudo mkdir -pv var/log
	sudo mkdir -pv var/mail
	sudo mkdir -pv var/opt
	sudo mkdir -pv var/spool
	sudo mkdir -pv var/lib/color
	sudo mkdir -pv var/lib/misc
	sudo mkdir -pv var/lib/locate
	
	sudo ln -sfv ../run var/run
	sudo ln -sfv ../run/lock var/lock

	sudo install -v -d -m 0750 root
	sudo install -v -d -m 1777 tmp
	sudo install -v -d -m 1777 var/tmp
} >"${LFS}"/sources/createdirs.log 2>&1

	success "OK"
	touch sources/createdirs

fi

popd >/dev/null >/dev/null || exit 1