From 345aec40b7a7bfdbd13c13b5aeea833f849360ef Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 30 Mar 2021 09:57:10 -0500 Subject: Add chroot command with argument for chapter 7 and perform chapter 7 commands within insidechroot.sh. --- insidechroot.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lfs.sh | 5 +- 2 files changed, 151 insertions(+), 1 deletion(-) diff --git a/insidechroot.sh b/insidechroot.sh index f1eb140..9bd96a0 100644 --- a/insidechroot.sh +++ b/insidechroot.sh @@ -1,5 +1,152 @@ #!/bin/bash +CHAPTER="$1" + source /sources/colors.sh +source /sources/functions.sh printf "%b" "${CYN}SUCCESSFULLY ENTERED ${RED}CHROOT${RST}!\n" + +if [ "${CHAPTER}" -eq 7 ]; then + printf "%b" "${GRN}Creating directories...${RST}\n" + if [ -f /sources/createdirs ]; then + printf "%b" "${GRN} Directories already created.${RST}\n" + else + mkdir -p /boot + mkdir -p /home + mkdir -p /mnt + mkdir -p /opt + mkdir -p /srv + + mkdir -p /etc/opt + mkdir -p /etc/opt/sysconfig + mkdir -p /lib/firmware + mkdir -p /media/floppy + mkdir -p /media/cdrom + mkdir -p /usr/bin + mkdir -p /usr/include + mkdir -p /usr/lib + mkdir -p /usr/sbin + mkdir -p /usr/src + mkdir -p /usr/local/bin + mkdir -p /usr/local/include + mkdir -p /usr/local/lib + mkdir -p /usr/local/sbin + mkdir -p /usr/local/src + mkdir -p /usr/share/color + mkdir -p /usr/share/dict + mkdir -p /usr/share/doc + mkdir -p /usr/share/info + mkdir -p /usr/share/locale + mkdir -p /usr/share/man + mkdir -p /usr/share/man/man1 + mkdir -p /usr/share/man/man2 + mkdir -p /usr/share/man/man3 + mkdir -p /usr/share/man/man4 + mkdir -p /usr/share/man/man5 + mkdir -p /usr/share/man/man6 + mkdir -p /usr/share/man/man7 + mkdir -p /usr/share/man/man8 + mkdir -p /usr/share/misc + mkdir -p /usr/share/terminfo + mkdir -p /usr/share/zoneinfo + mkdir -p /usr/local/share/color + mkdir -p /usr/local/share/dict + mkdir -p /usr/local/share/doc + mkdir -p /usr/local/share/info + mkdir -p /usr/local/share/locale + mkdir -p /usr/local/share/man + mkdir -p /usr/local/share/man/man1 + mkdir -p /usr/local/share/man/man2 + mkdir -p /usr/local/share/man/man3 + mkdir -p /usr/local/share/man/man4 + mkdir -p /usr/local/share/man/man5 + mkdir -p /usr/local/share/man/man6 + mkdir -p /usr/local/share/man/man7 + mkdir -p /usr/local/share/man/man8 + mkdir -p /usr/local/share/misc + mkdir -p /usr/local/share/terminfo + mkdir -p /usr/local/share/zoneinfo + mkdir -p /var/cache + mkdir -p /var/local + mkdir -p /var/log + mkdir -p /var/mail + mkdir -p /var/opt + mkdir -p /var/spool + mkdir -p /var/lib/color + mkdir -p /var/lib/misc + mkdir -p /var/lib/locate + + ln -sf /run /var/run + ln -sf /run/lock /var/lock + + install -d -m 0750 /root + install -d -m 1777 /tmp /var/tmp + + printf "%b" " ${GRN}Directories created${RST}\n" + touch /sources/createdirs + fi + + printf "%b" "${GRN}Creating essential files and symbolic links... ${RST}\n" + if [ -f "/sources/symfiles" ]; then + printf "%b" " ${GRN}Files and symbolic links already created.${RST}\n" + else + ln -sf /proc/self/mounts /etc/mtab + echo "127.0.0.1 localhost $(hostname)" > /etc/hosts + + cat > /etc/passwd << "EOF" +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/dev/null:/bin/false +daemon:x:6:6:Daemon User:/dev/null:/bin/false +messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/bin/false +uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/bin/false +nobody:x:99:99:Unprivileged User:/dev/null:/bin/false +EOF + + cat > /etc/group << "EOF" +root:x:0: +bin:x:1:daemon +sys:x:2: +kmem:x:3: +tape:x:4: +tty:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +adm:x:16: +messagebus:x:18: +input:x:24: +mail:x:34: +kvm:x:61: +uuidd:x:80: +wheel:x:97: +nogroup:x:99: +users:x:999: +EOF + + echo "tester:x:${TESTERUID}:101::/home/tester:/bin/bash" >> /etc/passwd + echo "tester:x:101:" >> /etc/group + install -o tester -d /home/tester + + touch /var/log/btmp + touch /var/log/lastlog + touch /var/log/faillog + touch /var/log/tmp + chgrp utmp /var/log/lastlog + chmod 664 /var/log/lastlog + chmod 600 /var/log/btmp + + echo -e " ${GRN}Files and symlinks created.${RST}" + touch /sources/symfiles + fi + + cd /sources || exit 1 + +fi diff --git a/lfs.sh b/lfs.sh index 7a4eaa9..f2b170c 100755 --- a/lfs.sh +++ b/lfs.sh @@ -116,4 +116,7 @@ sudo chroot "${LFS}" /usr/bin/env \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ NUMPROCS="${NUMPROCS}" \ MAKEFLAGS="${MAKEFLAGS}" \ - /bin/bash --login +h -c "/sources/insidechroot.sh" + TESTERUID="$(id -u)" \ + /bin/bash --login +h -c "/sources/insidechroot.sh 7" + +printf "%b" "${CYN}EXITED ${RED}CHROOT${CYN} ENVIRONMENT...${RST}\n" -- cgit v1.2.3-54-g00ecf