From b3cf81f95d46fd1eb87ea3c76e200eee86e3ee35 Mon Sep 17 00:00:00 2001 From: oddlama Date: Thu, 2 Jan 2020 23:42:45 +0100 Subject: [PATCH] Disable logging before chrooting --- scripts/functions.sh | 6 ++++++ scripts/main.sh | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 7132b68..7985f32 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -257,6 +257,11 @@ extract_stage3() { || die "Could not cd into '$TMP_DIR'" } +disable_logging() { + # Disables logging which is needed before exec-ing + exec 1>&3 +} + gentoo_umount() { einfo "Unmounting root filesystem" if mountpoint -q -- "$ROOT_MOUNTPOINT"; then @@ -293,6 +298,7 @@ gentoo_chroot() { # Execute command einfo "Chrooting..." + disable_logging EXECUTED_IN_CHROOT=true \ TMP_DIR=$TMP_DIR \ exec chroot "$ROOT_MOUNTPOINT" "$GENTOO_BOOTSTRAP_DIR/scripts/main_chroot.sh" "$@" \ diff --git a/scripts/main.sh b/scripts/main.sh index c93b490..a83bace 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -108,12 +108,15 @@ main_umount() { ################################################ # Main dispatch -# Redirect output to logfiles +einfo "Verbose script output will be logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'" +# Save old stdout exec 3>&1 -trap 'exec 1>&3' 0 1 2 3 +# Restore old filedescriptor on certain signals +trap 'exec 1>&3' 0 1 2 3 RETURN +# Replace stdout with logfole exec 1>"$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out" +# Link to latest log file ln -sf "$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out" "$GENTOO_BOOTSTRAP_DIR/log.out" -einfo "Verbose script output is logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'" SCRIPT_ALIAS="$(basename "$0")" if [[ "$SCRIPT_ALIAS" == "main.sh" ]]; then