From 6a10fc44c374d3e6fab6ee4dc01299321f8b2444 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 13 Apr 2021 14:09:09 -0500 Subject: Add set -e to scripts. --- chapter9/bashprofile.sh | 1 + chapter9/bootscriptconf.sh | 1 + chapter9/inputrc.sh | 1 + chapter9/lfs-bootscripts.sh | 1 + chapter9/network.sh | 1 + chapter9/shells.sh | 1 + 6 files changed, 6 insertions(+) (limited to 'chapter9') diff --git a/chapter9/bashprofile.sh b/chapter9/bashprofile.sh index 9636b3a..e52d25b 100644 --- a/chapter9/bashprofile.sh +++ b/chapter9/bashprofile.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e cat > /etc/profile << "EOF" # Begin /etc/profile diff --git a/chapter9/bootscriptconf.sh b/chapter9/bootscriptconf.sh index 3c00024..2640502 100644 --- a/chapter9/bootscriptconf.sh +++ b/chapter9/bootscriptconf.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e cat > /etc/inittab << "EOF" # Begin /etc/inittab diff --git a/chapter9/inputrc.sh b/chapter9/inputrc.sh index bab2a35..05c7dde 100644 --- a/chapter9/inputrc.sh +++ b/chapter9/inputrc.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e cat > /etc/inputrc << "EOF" # Begin /etc/inputrc diff --git a/chapter9/lfs-bootscripts.sh b/chapter9/lfs-bootscripts.sh index db9dad4..c019094 100644 --- a/chapter9/lfs-bootscripts.sh +++ b/chapter9/lfs-bootscripts.sh @@ -1,3 +1,4 @@ #!/bin/bash +set -e make -j1 install diff --git a/chapter9/network.sh b/chapter9/network.sh index e1386a4..1cd1739 100644 --- a/chapter9/network.sh +++ b/chapter9/network.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e pushd /etc/sysconfig/ >/dev/null || exit 1 cat > ifconfig.eth0 << "EOF" diff --git a/chapter9/shells.sh b/chapter9/shells.sh index d94254c..ac66dd6 100644 --- a/chapter9/shells.sh +++ b/chapter9/shells.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e cat > /etc/shells << "EOF" # Begin /etc/shells -- cgit v1.2.3-54-g00ecf From 801a63d7edbb098fdf4fa384366ba91e39845c07 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Thu, 15 Apr 2021 08:12:40 -0500 Subject: Set LC_TIME to POSIX since coreutils 8.28 has changed date behaviour from gnulib where some locales with 12 hour time data will output date's time in 12 hour instead of 24 hour format. View coreutil's changelog. --- chapter9/bashprofile.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'chapter9') diff --git a/chapter9/bashprofile.sh b/chapter9/bashprofile.sh index e52d25b..77bc1bb 100644 --- a/chapter9/bashprofile.sh +++ b/chapter9/bashprofile.sh @@ -5,6 +5,7 @@ cat > /etc/profile << "EOF" # Begin /etc/profile export LANG=en_US +export LC_TIME=POSIX # End /etc/profile EOF -- cgit v1.2.3-54-g00ecf From 8b5530be21a8e28e3e2c1b9917ca3645fbd13398 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Thu, 15 Apr 2021 08:32:23 -0500 Subject: Create fail and success functions and remove trailing white spaces at ends of lines. --- chapter6/backup.sh | 4 ++-- chapter6/cleanup.sh | 6 +++--- chapter7/backup.sh | 4 ++-- chapter7/cleanup.sh | 2 +- chapter8/backup.sh | 4 ++-- chapter8/cleanup.sh | 2 +- chapter9/bashprofile.sh | 3 +-- chapter9/bootscriptconf.sh | 3 +-- chapter9/inputrc.sh | 3 +-- chapter9/network.sh | 3 +-- chapter9/shells.sh | 3 +-- createdirs.sh | 2 +- download.sh | 8 +++++--- essential.sh | 4 ++-- functions.sh | 21 ++++++++++++++------- lfs.sh | 23 +++++++++++++---------- packageinstall.sh | 9 +++++---- setupdisk.sh | 7 ++++--- 18 files changed, 60 insertions(+), 51 deletions(-) (limited to 'chapter9') 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 748c0cc..2266d06 100644 --- a/chapter6/cleanup.sh +++ b/chapter6/cleanup.sh @@ -8,7 +8,7 @@ else printf "%b" "${GRN}Cleaning up ${YLW}${LFS}${RST}... " { - find "${LFS}"/usr/lib -name \*.la -delete + find "${LFS}"/usr/lib -name \*.la -delete find "${LFS}"/usr/libexec -name \*.la -delete rm -rfv "${LFS}"/usr/share/doc @@ -22,6 +22,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 77bc1bb..7ae73c2 100644 --- a/chapter9/bashprofile.sh +++ b/chapter9/bashprofile.sh @@ -1,5 +1,4 @@ -#!/bin/bash -set -e +#!/bin/bash cat > /etc/profile << "EOF" # Begin /etc/profile diff --git a/chapter9/bootscriptconf.sh b/chapter9/bootscriptconf.sh index 2640502..ae9633c 100644 --- a/chapter9/bootscriptconf.sh +++ b/chapter9/bootscriptconf.sh @@ -1,5 +1,4 @@ -#!/bin/bash -set -e +#!/bin/bash cat > /etc/inittab << "EOF" # Begin /etc/inittab diff --git a/chapter9/inputrc.sh b/chapter9/inputrc.sh index 05c7dde..5da8f3b 100644 --- a/chapter9/inputrc.sh +++ b/chapter9/inputrc.sh @@ -1,5 +1,4 @@ -#!/bin/bash -set -e +#!/bin/bash cat > /etc/inputrc << "EOF" # Begin /etc/inputrc diff --git a/chapter9/network.sh b/chapter9/network.sh index 1cd1739..05ab2fd 100644 --- a/chapter9/network.sh +++ b/chapter9/network.sh @@ -1,5 +1,4 @@ -#!/bin/bash -set -e +#!/bin/bash pushd /etc/sysconfig/ >/dev/null || exit 1 cat > ifconfig.eth0 << "EOF" diff --git a/chapter9/shells.sh b/chapter9/shells.sh index ac66dd6..dbeced4 100644 --- a/chapter9/shells.sh +++ b/chapter9/shells.sh @@ -1,5 +1,4 @@ -#!/bin/bash -set -e +#!/bin/bash cat > /etc/shells << "EOF" # Begin /etc/shells diff --git a/createdirs.sh b/createdirs.sh index 2c6f7c5..17bf26a 100644 --- a/createdirs.sh +++ b/createdirs.sh @@ -80,7 +80,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 422e2a4..3384917 100644 --- a/essential.sh +++ b/essential.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -e pushd "${LFS}" >/dev/null || exit 1 @@ -63,7 +63,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 diff --git a/lfs.sh b/lfs.sh index e5c6c60..8cd843a 100755 --- a/lfs.sh +++ b/lfs.sh @@ -33,23 +33,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 @@ -95,10 +98,10 @@ esac printf "%b" "${GRN}Copying required files to ${YLW}${LFS}/sources \ ${GRN}target directory${RST}... " -if ! cp -rf ./*.sh chapter* ./*.csv kernelconfig "${LFS}/sources"; then - printf "%b" "${IRED}FAILED!${RST}\n" +if ! cp -rf ./*.sh chapter* ./*.csv "${LFS}/sources"; then + fail "FAILED!" else - printf "%b" "${IGRN}OK${RST}\n" + success "OK" fi cd "${LFS}/sources" || exit 1 @@ -144,7 +147,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 -- cgit v1.2.3-54-g00ecf