#!/bin/bash set -u clear printf "%b" "Sourcing colors...\n" # Colors defined for text source colors.sh printf "%b" "Sourcing environment variables...\n" # LFS build environment settings source env.sh printf "%b" "Sourcing functions...\n" # Functions used during build source functions.sh # Version check script #source versioncheck.sh printf "%b" "\n\n\n${CYN}BUILDING ${YLW}${LFS_VER} $(uname -m)${CYN} at \ ${IWHT}${LFS}${CYN} on ${IWHT}${LFS_DISK}${LFS_PART}${RST}\n\n" printf "%b" "${IRED}*** ${IREDB}WARNING${RST} \ ${IWHT}POTENTIAL DATA LOSS \ ${IREDB}WARNING ${RST}${IRED}***${GRN}\n${RST}" printf "%b" "${GRN}Automatic creation of partition(s), filesystem(s) \n\ and mounting will occur unless manually performed\n\ before continuing.${RST}\n\n\n" # Continue or Abort printf "%b" "${IGRN}CONTINUE ${IWHTB}(C)${RST} / ${IRED}ABORT ${IWHTB}(OTHER)${RST}\n" if read -r -n 1 contabort; then if [[ "$contabort" == "C" ]] || [[ "$contabort" == "c" ]]; then printf "%b" "\b${IWHT}Build is ${IGRN}CONTINUING${RST}\n\n" else printf "%b" "\b${IWHT}Build ${IRED}ABORTED!\n\n" exit 0 fi else printf "%b" "\b${IWHT}Selection ${IRED}FAILURE!${RST}\n\n" exit 1 fi # Create LFS directory if it doesn't exist printf "%b" "${GRN}Creating LFS directory at ${YLW}${LFS}${GRN}${RST}... " if [[ -d "${LFS}" ]]; then printf "%b" "${IGRN}EXISTS${RST}\n" else if ! mkdir "${LFS}" >/dev/null 2>&1; then printf "%b" "${IRED}FAILED!${RST}\n" exit 1 fi fi # Setup partition, filesystem, format and mount if # LFS filesystem is not previously mounted if ! grep -q "${LFS}" /proc/mounts; then printf "%b" "${GRN}Preparing LFS partition and filesystem${RST}...\n" source setupdisk.sh "${LFS_DISK}" "${LFS_PART}" printf "%b" " ${IGRN}Mounting ${IWHT}${LFS_DISK}${LFS_PART} ${IGRN}at \ ${IWHT}${LFS}${RST}\n" sudo mount "${LFS_DISK}${LFS_PART}" "${LFS}" printf "%b" " ${IGRN}Changing ownership of ${IWHT}${LFS}${IGRN} \ to user ${IWHT}${USER}${RST}\n" sudo chown "${USER}" "${LFS}" fi # Create limited directory layout mkdir -p "${LFS}"/sources mkdir -p "${LFS}"/tools mkdir -p "${LFS}"/bin mkdir -p "${LFS}"/etc mkdir -p "${LFS}"/lib mkdir -p "${LFS}"/sbin mkdir -p "${LFS}"/usr mkdir -p "${LFS}"/var case $(uname -m) in x86_64) mkdir -p "${LFS}"/lib64 ;; esac # Will use normal user and not special lfs user #sudo groupadd lfs #sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs #printf "%b" "${LFS_PWD}\n${LFS_PWD}\n" | sudo passwd lfs # Copy scripts and csv files to LFS sources target printf "%b" "${GRN}Copying required files to ${YLW}${LFS}/sources \ ${GRN}target directory${RST}... " if ! cp -rf ./*.sh chapter* ./*.csv "${LFS}/sources"; then printf "%b" "${IRED}FAILED!${RST}\n" else printf "%b" "${IGRN}OK${RST}\n" fi cd "${LFS}/sources" || exit 1 # Download packages and patches printf "%b" "\n${IWHT}============ ${IGRN}Downloading source files and patches \ ${IWHT}============${RST}\n" source download.sh retval=$? if [[ "$retval" -ne 0 ]]; then exit 1 fi # Chapter 5 printf "%b" "\n${IWHT}============ ${IGRN}Building ${IYLW}Chapter 5${IWHT} \ ============${RST}\n" for package in binutils gcc linux-api-headers glibc libstdc++; do source packageinstall.sh 5 $package retval=$? if [[ "$retval" -ne 0 ]]; then exit 1 fi done # Chapter 6 printf "%b" "\n${IWHT}============ ${IGRN}Building ${IYLW}Chapter 6${IWHT} \ ============${RST}\n" for package in m4 ncurses bash coreutils diffutils file findutils gawk grep gzip make patch sed tar xz binutils gcc; do source packageinstall.sh 6 $package retval=$? if [[ "$retval" -ne 0 ]]; then exit 1 fi done printf "%b" "\n${IWHT}======= ${IYLW}Chapter 6 ${IGRN}Cleanup and Backup \ ${IWHT}=======${RST}\n" source chapter6/cleanup.sh source chapter6/backup.sh # Prepare chroot scripts to be executable for owner, group and others chmod ugo+x preparechroot.sh chmod ugo+x insidechroot.sh printf "%b" "\n${CYN}PREPARING ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n" sudo ./preparechroot.sh "${LFS}" source createdirs.sh source essential.sh printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n" sleep 3 sudo chroot "${LFS}" /usr/bin/env \ HOME=/root \ TERM="${TERM}" \ PS1='(lfs chroot) \u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ NUMPROCS="${NUMPROCS}" \ MAKEFLAGS="${MAKEFLAGS}" \ SPINNER="${SPINNER}" \ /bin/bash --login +h -c "/sources/insidechroot.sh 7" retval=$? printf "%b" "\n${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n" # Cleanup and Backup if chapter 7 successfully finished if [[ "$retval" -eq 0 ]]; then source umountvirtfs.sh printf "%b" "\n${IWHT}======= ${IYLW}Chapter 7 ${IGRN}Cleanup and Backup \ ${IWHT}=======${RST}\n" source "${LFS}"/sources/chapter7/cleanup.sh source "${LFS}"/sources/chapter7/backup.sh else exit "$retval" fi # Mount virtual kernel filesystems after cleanup and backup source mountvirtfs.sh printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT...${RST}\n" sleep 3 # Enter CHROOT for chapter 8, 9 and 10 sudo chroot "${LFS}" /usr/bin/env \ HOME=/root \ TERM="${TERM}" \ PS1='(lfs chroot) \u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ NUMPROCS="${NUMPROCS}" \ MAKEFLAGS="${MAKEFLAGS}" \ SPINNER="${SPINNER}" \ /bin/bash --login +h -c "/sources/insidechroot.sh 8" printf "%b" "\n${CYN}EXITED ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n"