diff options
-rw-r--r-- | chapter6/backup.sh | 4 | ||||
-rw-r--r-- | chapter6/cleanup.sh | 14 | ||||
-rw-r--r-- | chapter7/backup.sh | 4 | ||||
-rw-r--r-- | chapter7/cleanup.sh | 2 | ||||
-rw-r--r-- | chapter8/backup.sh | 4 | ||||
-rw-r--r-- | chapter8/cleanup.sh | 2 | ||||
-rw-r--r-- | chapter9/bashprofile.sh | 2 | ||||
-rw-r--r-- | chapter9/bootscriptconf.sh | 2 | ||||
-rw-r--r-- | chapter9/inputrc.sh | 2 | ||||
-rw-r--r-- | chapter9/network.sh | 2 | ||||
-rw-r--r-- | chapter9/shells.sh | 2 | ||||
-rw-r--r-- | createdirs.sh | 2 | ||||
-rw-r--r-- | download.sh | 8 | ||||
-rw-r--r-- | essential.sh | 4 | ||||
-rw-r--r-- | functions.sh | 21 | ||||
-rwxr-xr-x | lfs.sh | 21 | ||||
-rw-r--r-- | packageinstall.sh | 9 | ||||
-rw-r--r-- | setupdisk.sh | 7 |
18 files changed, 63 insertions, 49 deletions
diff --git a/chapter6/backup.sh b/chapter6/backup.sh index 837c44c..f9a761c 100644 --- a/chapter6/backup.sh +++ b/chapter6/backup.sh @@ -15,12 +15,12 @@ else spinner "$pid" "${SPINNER}" retval=$? if [ "$retval" -ne 0 ]; then - printf "%b" "${IRED}FAILED!${RST}\n" + fail "FAILED!" exit "${retval}" else # shellcheck disable=SC2024 sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >>"${LFS}"/sources/log/chapter6/backup.log - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi popd > /dev/null || exit 1 diff --git a/chapter6/cleanup.sh b/chapter6/cleanup.sh index 0eb80a2..5f6e327 100644 --- a/chapter6/cleanup.sh +++ b/chapter6/cleanup.sh @@ -7,12 +7,12 @@ else printf "%b" "${GRN}Cleaning up ${YLW}${LFS}${RST}... " { - find "${LFS}"/usr/lib -name \*.la -delete - find "${LFS}"/usr/libexec -name \*.la -delete + find "${LFS}"/usr/lib -name \*.la -delete + find "${LFS}"/usr/libexec -name \*.la -delete - rm -rfv "${LFS}"/usr/share/doc - rm -rfv "${LFS}"/usr/share/info - rm -rfv "${LFS}"/usr/share/man + rm -rfv "${LFS}"/usr/share/doc + rm -rfv "${LFS}"/usr/share/info + rm -rfv "${LFS}"/usr/share/man strip --strip-debug "${LFS}"/usr/lib/* strip --strip-unneeded "${LFS}"/usr/bin/* @@ -21,6 +21,6 @@ else } >"${LFS}"/sources/log/chapter6/cleanup.log 2>&1 - printf "%b" "${IGRN}OK${RST}\n" - touch "${LFS}"/sources/chapter6/cleanup + success "OK" + touch "${LFS}"/sources/chapter6/cleanup fi diff --git a/chapter7/backup.sh b/chapter7/backup.sh index 9418775..b903897 100644 --- a/chapter7/backup.sh +++ b/chapter7/backup.sh @@ -15,12 +15,12 @@ else spinner "$pid" "${SPINNER}" retval=$? if [ "${retval}" -ne 0 ]; then - printf "%b" "${IRED}FAILED!${RST}\n" + fail "FAILED!" exit "${retval}" else # shellcheck disable=SC2024 sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >"${LFS}"/sources/log/chapter7/backup.log 2>&1 - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi popd > /dev/null || exit 1 diff --git a/chapter7/cleanup.sh b/chapter7/cleanup.sh index 53ad4d4..3e4dfa3 100644 --- a/chapter7/cleanup.sh +++ b/chapter7/cleanup.sh @@ -21,6 +21,6 @@ else sudo strip --strip-unneeded "${LFS}"/tools/bin/* || true } >"${LFS}"/sources/log/chapter7/cleanup.log 2>&1 - printf "%b" "${IGRN}OK${RST}\n" + success "OK" sudo touch "${LFS}"/sources/chapter7/cleanup >/dev/null 2>&1 fi diff --git a/chapter8/backup.sh b/chapter8/backup.sh index d7a29ac..4df6f79 100644 --- a/chapter8/backup.sh +++ b/chapter8/backup.sh @@ -15,12 +15,12 @@ else spinner "$pid" "${SPINNER}" retval=$? if [ "${retval}" -ne 0 ]; then - printf "%b" "${IRED}FAILED!${RST}\n" + fail "FAILED!" exit "${retval}" else # shellcheck disable=SC2024 sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >"${LFS}"/sources/log/chapter8/backup.log 2>&1 - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi popd > /dev/null || exit 1 diff --git a/chapter8/cleanup.sh b/chapter8/cleanup.sh index ec4084f..12bbae4 100644 --- a/chapter8/cleanup.sh +++ b/chapter8/cleanup.sh @@ -63,6 +63,6 @@ else } >"${LFS}"/sources/log/chapter8/cleanup.log 2>&1 - printf "%b" "${IGRN}OK${RST}\n" + success "OK" sudo touch "${LFS}"/sources/chapter8/cleanup >/dev/null 2>&1 fi diff --git a/chapter9/bashprofile.sh b/chapter9/bashprofile.sh index 455a6fd..7ae73c2 100644 --- a/chapter9/bashprofile.sh +++ b/chapter9/bashprofile.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash cat > /etc/profile << "EOF" # Begin /etc/profile diff --git a/chapter9/bootscriptconf.sh b/chapter9/bootscriptconf.sh index 3c00024..ae9633c 100644 --- a/chapter9/bootscriptconf.sh +++ b/chapter9/bootscriptconf.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash cat > /etc/inittab << "EOF" # Begin /etc/inittab diff --git a/chapter9/inputrc.sh b/chapter9/inputrc.sh index bab2a35..5da8f3b 100644 --- a/chapter9/inputrc.sh +++ b/chapter9/inputrc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash cat > /etc/inputrc << "EOF" # Begin /etc/inputrc diff --git a/chapter9/network.sh b/chapter9/network.sh index e1386a4..05ab2fd 100644 --- a/chapter9/network.sh +++ b/chapter9/network.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash pushd /etc/sysconfig/ >/dev/null || exit 1 cat > ifconfig.eth0 << "EOF" diff --git a/chapter9/shells.sh b/chapter9/shells.sh index d94254c..dbeced4 100644 --- a/chapter9/shells.sh +++ b/chapter9/shells.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash cat > /etc/shells << "EOF" # Begin /etc/shells diff --git a/createdirs.sh b/createdirs.sh index ad95ab5..4c405c6 100644 --- a/createdirs.sh +++ b/createdirs.sh @@ -81,7 +81,7 @@ else { sudo install -v -d -m 1777 var/tmp } >"${LFS}"/sources/createdirs.log 2>&1 - printf "%b" " ${IGRN}OK${RST}\n" + success "OK" touch sources/createdirs fi diff --git a/download.sh b/download.sh index 72c250b..fff69f7 100644 --- a/download.sh +++ b/download.sh @@ -18,9 +18,11 @@ cat packages.csv patches.csv | while read -r line; do if ! echo "${MD5SUM} ${LFS}/sources/${CACHEFILE}" | md5sum -c > /dev/null 2>&1; then rm -f "${LFS}/sources/${CACHEFILE}" - printf "%b" "\n${IPRP} MD5SUM ${YLW}${MD5SUM}${IRED} FAILED! MD5 MISMATCH!${RST}\n" - exit 1 + printf "%b" "\n${IPRP} MD5SUM ${YLW}${MD5SUM} " + fail "FAILED! MD5 MISMATCH!" + exit 1 fi - printf "%b" "\n${IPRP} MD5SUM ${YLW}${MD5SUM}${IGRN} OK${RST}\n" + printf "%b" "\n${IPRP} MD5SUM ${YLW}${MD5SUM} " + success "OK" done diff --git a/essential.sh b/essential.sh index f12cbb4..dacfd1a 100644 --- a/essential.sh +++ b/essential.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -e pushd "${LFS}" >/dev/null || exit 1 @@ -65,7 +65,7 @@ EOF' } >"${LFS}"/sources/log/essential.log 2>&1 sudo touch sources/essential - sudo printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi diff --git a/functions.sh b/functions.sh index a260f66..b343e65 100644 --- a/functions.sh +++ b/functions.sh @@ -18,20 +18,15 @@ download() export -f download # Shows a spinner while another command is running. Randomly picks one of 12 spinner styles. -# @args command to run (with any parameters) while showing a spinner. +# @args command to run (with any parameters) while showing a spinner. # E.g. ‹spinner sleep 10› -function shutdown() { - tput cnorm # reset cursor -} -trap shutdown EXIT - function cursorBack() { echo -en "\033[$1D" } function spinner() { - # make sure we use non-unicode character type locale + # make sure we use non-unicode character type locale # (that way it works for any locale as long as the font supports the characters) local numspinners=12 @@ -114,3 +109,15 @@ function spinner() { wait "$pid" # capture exit code return $? } + +fail() +{ + printf "%b" "${IRED}${1}${RST}\n" +} +export -f fail + +success() +{ + printf "%b" "${IGRN}${1}${RST}\n" +} +export -f success @@ -34,23 +34,26 @@ before continuing.${RST}\n\n\n" 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" + printf "%b" "\b${IWHT}Build is " + success "CONTINUING\n" + else + printf "%b" "\b${IWHT}Build " + fail "ABORTED!\n" exit 0 fi else - printf "%b" "\b${IWHT}Selection ${IRED}FAILURE!${RST}\n\n" + printf "%b" "\b${IWHT}Selection " + fail "FAILURE!\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" + success "EXISTS" else if ! mkdir "${LFS}" >/dev/null 2>&1; then - printf "%b" "${IRED}FAILED!${RST}\n" + fail "FAILED!" exit 1 fi fi @@ -97,9 +100,9 @@ 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" + fail "FAILED!" else - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi cd "${LFS}/sources" || exit 1 @@ -145,7 +148,7 @@ chmod ugo+x preparechroot.sh chmod ugo+x insidechroot.sh printf "%b" "\n${CYN}PREPARING ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n" -source preparechroot.sh "${LFS}" +source preparechroot.sh "${LFS}" source createdirs.sh source essential.sh diff --git a/packageinstall.sh b/packageinstall.sh index 706880c..e0516db 100644 --- a/packageinstall.sh +++ b/packageinstall.sh @@ -26,10 +26,11 @@ else spinner "$pid" "${SPINNER}" retval=$? if [[ "$retval" -ne 0 ]]; then - printf "%b" "${GRN}Extraction ${IRED}FAILED!${RST}\n" + printf "%b" "${GRN}Extraction " + fail "FAILED!" return $retval else - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi pushd "${DIRNAME}" > /dev/null || return 1 @@ -42,11 +43,11 @@ else spinner "$pid" "${SPINNER}" retval=$? if [[ "$retval" -ne 0 ]]; then - printf "%b" "${IRED}FAILED!${RST}\n" + fail "FAILED!" popd > /dev/null || return 1 return $retval else - printf "%b" "${IGRN}OK${RST}\n" + success "OK" touch "${LFS}"/sources/chapter"${CHAPTER}"/"${PACKAGE}" rm -rf "${LFS}"/sources/"${DIRNAME}" fi diff --git a/setupdisk.sh b/setupdisk.sh index b79f27f..659a621 100644 --- a/setupdisk.sh +++ b/setupdisk.sh @@ -22,14 +22,15 @@ q EOF retval=$? if [[ "$retval" -ne 0 ]]; then - printf "%b" " ${IGRN}Creating partition ${IWHT}${LFS_DISK}${LFS_PART} \ -${IRED}FAILED!${RST}\n" + printf "%b" " ${IGRN}Creating partition ${IWHT}${LFS_DISK}${LFS_PART} " + fail "FAILED!" exit 1 fi printf "%b" " ${IGRN}Formatting ${IWHT}${LFS_DISK}${LFS_PART} with \ ${IWHT}${LFS_FS}${IGRN} filesystem and label ${IWHT}${LFS_VER}${RST}\n" if ! sudo /sbin/mkfs -t "${LFS_FS,,}" -L "${LFS_VER}" -F "${LFS_DISK}${LFS_PART}" >/dev/null 2>&1; then printf "%b" " ${IGRN}Creating ${IWHT}${LFS_FS}${IGRN} filesystem at \ -${IWHT}${LFS_DISK}${LFS_PART} ${IRED}FAILED!${RST}\n" +${IWHT}${LFS_DISK}${LFS_PART} " + fail "FAILED!" exit 1 fi |