aboutsummaryrefslogtreecommitdiffstats
path: root/chapter8
diff options
context:
space:
mode:
Diffstat (limited to 'chapter8')
-rw-r--r--chapter8/backup.sh25
-rw-r--r--chapter8/cleanup.sh63
2 files changed, 88 insertions, 0 deletions
diff --git a/chapter8/backup.sh b/chapter8/backup.sh
new file mode 100644
index 0000000..57b356d
--- /dev/null
+++ b/chapter8/backup.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+file="${LFS_VER}-ch8-backup.tar.xz"
+directories=(bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var)
+
+if [ -f "${LFS}/sources/chapter8/backup" ]; then
+ printf "%b" " ${IGRN}Backup previously completed${RST}\n"
+else
+
+ printf "%b" "${GRN}Backing up ${YLW}${LFS}${GRN} to ${YLW}${file}${RST}... "
+ pushd "${LFS}" > /dev/null || exit 1
+ sudo XZ_OPTS="-T${NUMPROCS} -e" tar cJvpf "${HOME}"/"${file}" "${directories[@]}" >"${LFS}"/sources/log/chapter8/backup.log 2>&1 & pid=$!
+ spinner "$pid" "${SPINNER}"
+ retval=$?
+ if [ "${retval}" -ne 0 ]; then
+ printf "%b" "${IRED}FAILED!${RST}\n"
+ exit "${retval}"
+ else
+ sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >"${LFS}"/sources/log/chapter8/backup.log 2>&1
+ printf "%b" "${IGRN}OK${RST}\n"
+ fi
+ popd > /dev/null || exit 1
+
+ touch "${LFS}/sources/chapter8/backup"
+fi
diff --git a/chapter8/cleanup.sh b/chapter8/cleanup.sh
new file mode 100644
index 0000000..46c152d
--- /dev/null
+++ b/chapter8/cleanup.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+if [ -f "${LFS}/sources/chapter8/cleanup" ]; then
+ printf "%b" " ${IGRN}Cleanup already performed${RST}\n"
+else
+
+ printf "%b" "${GRN}Cleaning up ${YLW}${LFS}${RST}... "
+
+ {
+
+ sudo rm -rfv "${LFS}"/tmp/*
+ sudo rm -rfv "${LFS}"/tools
+
+ sudo find "${LFS}"/usr/lib -name \*.la -delete
+ sudo find "${LFS}"/usr/libexec -name \*.la -delete
+
+ sudo find "${LFS}"/usr -depth -name "$(uname -m)"-lfs-linux-gnu\* | xargs sudo rm -rfv
+
+ sudo sed '/tester/d' -i "${LFS}"/etc/group
+ sudo sed '/tester/d' -i "${LFS}"/etc/passwd
+ sudo rm -rfv "${LFS}"/home/tester
+
+ sudo rm -rfv "${LFS}"/usr/share/doc
+ sudo rm -rfv "${LFS}"/usr/share/info
+ sudo rm -rfv "${LFS}"/usr/share/man
+
+ # Place debugging symbols for selected libraries in seprate files
+ save_lib="ld-2.33.so libc-2.33.so libpthread-2.33.so libthread_db-1.0.so"
+ cd "${LFS}"/lib || exit 1
+
+ for LIB in $save_lib; do
+ sudo objcopy --only-keep-debug "${LIB}" "${LIB}".dbg
+ sudo strip --strip-unneeded "${LIB}"
+ sudo objcopy --add-gnu-debuglink="${LIB}".dbg "${LIB}"
+ done
+
+ save_usrlib="libquadmath.so.0.0.0 libstdc++.so.6.0.28 libitm.so.1.0.0 libatomic.so.1.2.0"
+
+ cd "${LFS}"/usr/lib || exit 1
+
+ for LIB in $save_usrlib; do
+ sudo objcopy --only-keep-debug "${LIB}" "${LIB}".dbg
+ sudo strip --strip-unneeded "${LIB}"
+ sudo objcopy --add-gnu-debuglink="${LIB}".dbg "${LIB}"
+ done
+
+ sudo find "${LFS}"/usr/lib -type f -name \*.a -exec strip --strip-debug {} ';'
+ sudo find "${LFS}"/lib -type f -name \*.so* ! -name \*dbg -exec strip --strip-unneeded {} ';'
+ sudo find "${LFS}"/usr/lib -type f -name \*.so* ! -name \*dbg -exec strip --strip-unneeded {} ';'
+
+
+ sudo find "${LFS}"/bin -type f -exec strip --strip-all {} ';'
+ sudo find "${LFS}"/sbin -type f -exec strip --strip-all {} ';'
+ sudo find "${LFS}"/usr/bin -type f -exec strip --strip-all {} ';'
+ sudo find "${LFS}"/usr/sbin -type f -exec strip --strip-all {} ';'
+ sudo find "${LFS}"/usr/libexec -type f -exec strip --strip-all {} ';'
+
+
+} >"${LFS}"/sources/log/chapter8/cleanup.log 2>&1
+
+ printf "%b" "${IGRN}OK${RST}\n"
+ sudo touch "${LFS}"/sources/chapter8/cleanup >/dev/null 2>&1
+fi