2023-01-05 06:17:49 +00:00
#!/bin/bash
2023-01-05 09:26:40 +00:00
# Set SU
2023-01-06 08:59:14 +00:00
# ======
command -v sudo > /dev/null
2023-01-05 09:26:40 +00:00
if [ $? -eq 1 ]
then
SU = doas
else
SU = sudo
fi
2023-01-06 08:59:14 +00:00
# Exit on error
# =============
2023-01-05 06:17:49 +00:00
exit_status = 0
function check_exit_code( ) {
if [ $? -ne 0 ]
then
exit_status = 1
else
exit_status = 0
fi
}
function stop_script( ) {
echo " Script failed in $( pwd ) / $1 "
exit 1
}
2023-01-06 08:59:14 +00:00
# Chapter 2
# =========
2023-01-05 06:17:49 +00:00
echo "Chapter 2"
2023-01-22 14:26:54 +00:00
bash ./chapter2/main.sh
2023-01-05 06:17:49 +00:00
2023-01-06 08:59:14 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 14:30:07 +00:00
stop_script "Stopped in chapter 2"
2023-01-06 08:59:14 +00:00
fi
# Set LFS variable
# ================
export LFS = /mnt/lfs
echo " LFS is $LFS "
2023-01-06 04:55:59 +00:00
2023-01-06 08:59:14 +00:00
# Chapter 3
# =========
2023-01-06 04:55:59 +00:00
echo "Chapter 3"
2023-01-22 14:33:01 +00:00
bash ./chapter3/main.sh
2023-01-06 04:55:59 +00:00
2023-01-06 08:59:14 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 14:33:01 +00:00
stop_script "Stopped in chapter 3"
2023-01-06 08:59:14 +00:00
fi
# Chapter 4
# =========
2023-01-06 04:55:59 +00:00
echo "Chapter 4"
2023-01-22 15:50:56 +00:00
bash ./chapter4/main.sh
2023-01-06 08:59:14 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 15:50:56 +00:00
stop_script "Stopped in chapter 4"
2023-01-06 08:59:14 +00:00
fi
2023-01-06 09:13:50 +00:00
2023-01-22 16:04:33 +00:00
# Chapter 5
# =========
2023-01-09 05:17:03 +00:00
echo "Chapter 5"
2023-01-22 15:55:59 +00:00
bash ./chapter5/main.sh
2023-01-06 09:13:50 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 15:55:59 +00:00
stop_script "Stopped in chapter 5"
2023-01-09 04:53:36 +00:00
fi
2023-01-22 16:31:17 +00:00
# Chapter 6
# =========
2023-01-09 05:17:03 +00:00
echo "Chapter 6"
2023-01-22 16:31:17 +00:00
bash ./chapter6/main.sh
2023-01-09 10:13:43 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:31:17 +00:00
stop_script "Stopped in chapter 6"
2023-01-09 10:13:43 +00:00
fi
2023-01-22 16:39:37 +00:00
# Chapter 7
# =========
2023-01-09 10:18:17 +00:00
echo "Chapter 7"
2023-01-22 16:31:17 +00:00
bash ./chapter7/main-prechroot.sh
2023-01-09 10:18:17 +00:00
2023-01-09 10:23:14 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:31:17 +00:00
stop_script "Stopped in chapter 7"
2023-01-09 10:23:14 +00:00
fi
2023-01-10 04:45:45 +00:00
# Chapter 7.4
# ===========
echo "Entering the Chroot Environment"
2023-01-10 06:13:55 +00:00
#su -c "bash $PWD/chapter7/7.4-enter-chroot.sh"
2023-01-10 04:45:45 +00:00
# Exit on error
2023-01-10 06:13:55 +00:00
# check_exit_code
# if [ $exit_status -ne 0 ]
# then
# stop_script "chapter7/7.4-enter-chroot.sh"
# fi
# If I think it is what it is, then it should not be executed as a child script as it would exit chroot. However, I wouldn't know unless I run it. I will keep it commented for now.
chroot " $LFS " /usr/bin/env -i \
HOME = /root \
TERM = " $TERM " \
PS1 = '(lfs chroot) \u:\w\$ ' \
PATH = /usr/bin:/usr/sbin \
/bin/bash --login
PWD = $( pwd )
# I don't think $PWD is important at this point since the chroot will drop us in $LFS, treated as /. We lost the location of this script. Here's hoping the user puts this repo in $LFS/sources. So much for avoiding hardcoded paths...all goes out the window.
export SCRIPT = /sources/lfs-scripts
2023-01-10 04:45:45 +00:00
2023-01-10 04:48:20 +00:00
# Chapter 7.5
# ===========
2023-01-22 16:31:17 +00:00
bash ./chapter7/main-postchroot.sh
2023-01-10 04:52:09 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:31:17 +00:00
stop_script "Stopped in chapter 7, post chroot"
2023-01-10 04:52:09 +00:00
fi
2023-01-22 16:31:17 +00:00
# Exit chroot
exit
2023-01-10 05:25:53 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:31:17 +00:00
stop_script "Stopped in chapter 7, post chroot"
2023-01-10 05:25:53 +00:00
fi
2023-01-10 06:13:55 +00:00
# Unmount virtual filesystems
umount $LFS /dev/pts
umount $LFS /{ sys,proc,run,dev}
# Create backup
cd $LFS
tar -cJpf $HOME /lfs-temp-tools-11.2.tar.xz .
# Entering chroot
echo "Preparing virtual kernel filesystems"
su -c " bash $PWD /chapter7/7.3-prepare-virtual-fs.sh "
echo "Entering the Chroot Environment"
chroot " $LFS " /usr/bin/env -i \
HOME = /root \
TERM = " $TERM " \
PS1 = '(lfs chroot) \u:\w\$ ' \
PATH = /usr/bin:/usr/sbin \
/bin/bash --login
export SCRIPT = /sources/lfs-scripts
2023-01-22 16:39:37 +00:00
# Chapter 8
# =========
2023-01-10 09:15:50 +00:00
echo "Chapter 8"
2023-01-22 16:39:37 +00:00
bash ./chapter8/main.sh
2023-01-14 16:01:44 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:39:37 +00:00
stop_script "Stopped in chapter 8"
2023-01-14 16:01:44 +00:00
fi
2023-01-22 16:44:06 +00:00
# Chapter 9
# =========
2023-01-14 16:05:44 +00:00
echo "Chapter 9"
2023-01-22 16:44:06 +00:00
bash ./chapter9/main.sh
2023-01-14 16:26:44 +00:00
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
2023-01-22 16:44:06 +00:00
stop_script "Stopped in chapter 9"
2023-01-14 16:26:44 +00:00
fi
2023-01-14 16:30:50 +00:00
# Chapter 10.2
# ============
echo "Chapter 10"
echo "Creating /etc/fstab"
su -c " bash $SCRIPT /chapter10/10.2-fstab.sh "
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
stop_script "chapter10/10.2-fstab.sh"
fi
2023-01-14 16:37:25 +00:00
# Chapter 10.3
# ============
echo "Building kernel"
su -c " bash $SCRIPT /chapter10/10.3-kernel.sh "
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
stop_script "chapter10/10.3-kernel.sh"
fi
2023-01-14 16:44:19 +00:00
# Chapter 10.4
# ============
echo "Installng grub"
su -c " bash $SCRIPT /chapter10/10.4-grub.sh "
# Exit on error
check_exit_code
if [ $exit_status -ne 0 ]
then
stop_script "chapter10/10.4-grub.sh"
fi
2023-01-14 16:47:22 +00:00
# Chapter 11.1
# ============
echo "Chapter 11"
echo "Finishing up"
echo 11.2 > /etc/lfs-release
cat > /etc/lsb-release << "EOF"
DISTRIB_ID = "Linux From Scratch"
DISTRIB_RELEASE = "11.2"
DISTRIB_CODENAME = "summer2023"
DISTRIB_DESCRIPTION = "Linux From Scratch"
EOF
cat > /etc/os-release << "EOF"
NAME = "Linux From Scratch"
VERSION = "11.2"
ID = lfs
PRETTY_NAME = "Linux From Scratch 11.2"
VERSION_CODENAME = "summer2023"
EOF
2023-01-14 16:49:52 +00:00
# Exit chroot
logout
# Unmount filesystems
2023-01-14 17:05:54 +00:00
su -c " umount -v $LFS /dev/pts "
su -c " umount -v $LFS /dev "
su -c " umount -v $LFS /run "
su -c " umount -v $LFS /proc "
su -c " umount -v $LFS /sys "
su -c " umount -v $LFS "
2023-01-14 16:49:52 +00:00