diff options
-rw-r--r-- | chapter7/backup.sh | 24 | ||||
-rw-r--r-- | chapter7/bison.sh | 3 | ||||
-rw-r--r-- | chapter7/cleanup.sh | 23 | ||||
-rw-r--r-- | chapter7/gettext.sh | 5 | ||||
-rw-r--r-- | chapter7/libstdc++.sh | 12 | ||||
-rw-r--r-- | chapter7/perl.sh | 11 | ||||
-rw-r--r-- | chapter7/python.sh | 5 | ||||
-rw-r--r-- | chapter7/texinfo.sh | 3 | ||||
-rw-r--r-- | chapter7/util-linux.sh | 15 | ||||
-rw-r--r-- | insidechroot.sh | 160 | ||||
-rwxr-xr-x | lfs.sh | 43 |
11 files changed, 299 insertions, 5 deletions
diff --git a/chapter7/backup.sh b/chapter7/backup.sh new file mode 100644 index 0000000..71ad3a0 --- /dev/null +++ b/chapter7/backup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +FILE="${LFS_VER}-ch7-backup.tar.xz" +DIRS=(bin dev etc lib lib64 proc run sbin sources sys tools usr var) + +if [ -f "${LFS}/sources/chapter7/backup" ]; then + echo -e "${YLW}Chapter 7 ${GRN}Backup found. Remove manually to backup again.${RST}" +else + + echo -ne "${GRN}Backing up ${YLW}${LFS}${GRN} to ${YLW}${FILE}${RST}... " + pushd "${LFS}" > /dev/null || exit 1 + sudo XZ_OPTS="-T${NUMPROCS} -e" tar cJpf "${HOME}"/"${FILE}" "${DIRS[@]}" & pid=$! + spinner "$pid" + retval=$? + if [ "$retval" -ne 0 ]; then + echo -e "${RED}Backup FAILED!${RST}" + else + echo -e "${GRN}OK${RST}" + fi + popd > /dev/null || exit 1 + + touch "${LFS}/sources/chapter7/backup" +fi + diff --git a/chapter7/bison.sh b/chapter7/bison.sh new file mode 100644 index 0000000..a2344a6 --- /dev/null +++ b/chapter7/bison.sh @@ -0,0 +1,3 @@ +./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.7.5 && +make && +make -j1 install diff --git a/chapter7/cleanup.sh b/chapter7/cleanup.sh new file mode 100644 index 0000000..b300e7e --- /dev/null +++ b/chapter7/cleanup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ -f "${LFS}/sources/chapter7/cleanup" ]; then + echo -e "${YLW}Chapter 7 ${GRN}cleanup already performed.${RST}" +else + + echo -ne "${GRN}Cleaning up ${YLW}${LFS}${RST}... " + + sudo find "${LFS}"/usr/lib -name \*.la -delete >/dev/null 2>&1 + sudo find "${LFS}"/usr/libexec -name \*.la -delete >/dev/null 2>&1 + + sudo rm -rf "${LFS}"/usr/share/doc >/dev/null 2>&1 + sudo rm -rf "${LFS}"/usr/share/info >/dev/null 2>&1 + sudo rm -rf "${LFS}"/usr/share/man >/dev/null 2>&1 + + sudo strip --strip-debug "${LFS}"/usr/lib/* >/dev/null 2>&1 + sudo strip --strip-unneeded "${LFS}"/usr/bin/* >/dev/null 2>&1 + sudo strip --strip-unneeded "${LFS}"/usr/sbin/* >/dev/null 2>&1 + sudo strip --strip-unneeded "${LFS}"/tools/bin/* >/dev/null 2>&1 + + echo -e "${GRN}OK${RST}" + touch "${LFS}"/sources/chapter7/cleanup >/dev/null 2>&1 +fi diff --git a/chapter7/gettext.sh b/chapter7/gettext.sh new file mode 100644 index 0000000..85bc7f4 --- /dev/null +++ b/chapter7/gettext.sh @@ -0,0 +1,5 @@ +./configure --disable-shared +make && +cp -v gettext-tools/src/msgfmt /usr/bin +cp -v gettext-tools/src/msgmerge /usr/bin +cp -v gettext-tools/src/xgettext /usr/bin diff --git a/chapter7/libstdc++.sh b/chapter7/libstdc++.sh new file mode 100644 index 0000000..5e81693 --- /dev/null +++ b/chapter7/libstdc++.sh @@ -0,0 +1,12 @@ +ln -s gthr-posix.h libgcc/gthr-default.h +mkdir build +cd build +../libstdc++-v3/configure \ + CXXFLAGS="-g -O2 -D_GNU_SOURCE" \ + --prefix=/usr \ + --disable-multilib \ + --disable-nls \ + --host=$(uname -m)-lfs-linux-gnu \ + --disable-libstdcxx-pch && +make && +make -j1 install diff --git a/chapter7/perl.sh b/chapter7/perl.sh new file mode 100644 index 0000000..2cb5245 --- /dev/null +++ b/chapter7/perl.sh @@ -0,0 +1,11 @@ +sh Configure -des \ + -Dprefix=/usr \ + -Dvendorprefix=/usr \ + -Dprivlib=/usr/lib/perl5/5.32/core_perl \ + -Darchlib=/usr/lib/perl5/5.32/core_perl \ + -Dsitelib=/usr/lib/perl5/5.32/site_perl \ + -Dsitearch=/usr/lib/perl5/5.32/site_perl \ + -Dvendorlib=/usr/lib/perl5/5.32/vendor_perl \ + -Dvendorarch=/usr/lib/perl5/5.32/vendor_perl && +make && +make -j1 install diff --git a/chapter7/python.sh b/chapter7/python.sh new file mode 100644 index 0000000..7d158b1 --- /dev/null +++ b/chapter7/python.sh @@ -0,0 +1,5 @@ +./configure --prefix=/usr \ + --enable-shared \ + --without-ensurepip && +make && +make -j1 install diff --git a/chapter7/texinfo.sh b/chapter7/texinfo.sh new file mode 100644 index 0000000..7f133fe --- /dev/null +++ b/chapter7/texinfo.sh @@ -0,0 +1,3 @@ +./configure --prefix=/usr && +make && +make -j1 install diff --git a/chapter7/util-linux.sh b/chapter7/util-linux.sh new file mode 100644 index 0000000..170e3f5 --- /dev/null +++ b/chapter7/util-linux.sh @@ -0,0 +1,15 @@ +mkdir -p /var/lib/hwclock && +./configure ADJTIME_PATH=/var/lib/hwclock/adjtime \ + --docdir=/usr/share/doc/util-linux-2.36.2 \ + --disable-chfn-chsh \ + --disable-login \ + --disable-nologin \ + --disable-su \ + --disable-setpriv \ + --disable-runuser \ + --disable-pylibmount \ + --disable-static \ + --without-python \ + runstatedir=/run && +make && +make -j1 install diff --git a/insidechroot.sh b/insidechroot.sh index f1eb140..1863531 100644 --- a/insidechroot.sh +++ b/insidechroot.sh @@ -1,5 +1,165 @@ #!/bin/bash +CHAPTER="$1" + source /sources/colors.sh +source /sources/spinner.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:$(ls -n "$(tty)" | cut -d" " -f3):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 + + # Chapter 7 + for package in libstdc++ gettext bison perl python texinfo util-linux; do + source packageinstall.sh 7 $package + retval=$? + if [ "$retval" -ne 0 ]; then + exit 1 + fi + done + + exit 7 +else + printf "%b" "Do Chapter 8, 9 and 10 stuff here.\n" +fi + @@ -99,14 +99,14 @@ for package in m4 ncurses bash coreutils diffutils file findutils gawk grep gzip fi done -#source chapter6/cleanup.sh -#source chapter6/backup.sh +source chapter6/cleanup.sh +source chapter6/backup.sh chmod ugo+x preparechroot.sh chmod ugo+x insidechroot.sh -printf "%b" "${CYN}PREPARING CHROOT ENVIRONMENT...${RST}\n" +printf "%b" "${CYN}PREPARING ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n" sudo ./preparechroot.sh "${LFS}" -printf "%b" "${CYN}ENTERING CHROOT ENVIRONMENT...${RST}\n" +printf "%b" "${CYN}ENTERING ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n" sleep 3 sudo chroot "${LFS}" /usr/bin/env \ @@ -116,4 +116,37 @@ 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" + /bin/bash --login +h -c "/sources/insidechroot.sh 7" +retval=$? + +printf "%b" "${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n" +# Cleanup and Backup if chapter 7 successfully finished +if [ "$retval" -eq 7 ]; then + printf "%b" "${GRN}Unmounting Virtual Kernel Filesystems...\n" + sudo umount "${LFS}"/dev/pts + sudo umount "${LFS}"/dev/ + sudo umount "${LFS}"/run + sudo umount "${LFS}"/sys + sudo umount "${LFS}"/proc + + printf "%b" "${GRN}Cleaning and backing up before starting Chapter 8.\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 + +# 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}" \ + /bin/bash --login +h -c "/sources/insidechroot.sh 8" + +printf "%b" "${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n" |