Log each install and update, and keep only the recent logs
shellcheck / shellcheck (push) Failing after 17s
shellcheck / shellcheck (push) Failing after 17s
Each run's output now goes to ~/.local/state/coredesktop/logs/, so what failed can be read after the terminal is gone. In a terminal, update runs itself under script(1), so everything it runs still sees a terminal, then strips color codes and progress redraws from the log; otherwise it uses tee. install.sh, usually piped into bash, uses tee, and runs configure straight on the terminal, outside the log. Both name the log when something fails. 95-cleanup.sh keeps the newest 10 update logs and 3 install logs. The sudo keepalive loops no longer share the logged output, so their sleep can't hold the log open after the run ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+20
-3
@@ -21,6 +21,14 @@ clear
|
||||
print_logo
|
||||
cd
|
||||
|
||||
# Log the install to ~/.local/state/coredesktop/logs (update deletes old ones).
|
||||
# It's usually piped into bash, so it can't run itself again under script(1)
|
||||
# the way update does; send its output through tee instead.
|
||||
if mkdir -p -m 700 "$HOME/.local/state/coredesktop/logs"; then
|
||||
INSTALL_LOG="$HOME/.local/state/coredesktop/logs/install-$(date +%Y-%m-%d-%H%M%S).log"
|
||||
exec > >(tee -a "$INSTALL_LOG") 2>&1
|
||||
fi
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
@@ -51,9 +59,16 @@ if ! sudo -v; then
|
||||
echo "archinstall, make the user a superuser): https://wiki.archlinux.org/title/Sudo"
|
||||
exit 1
|
||||
fi
|
||||
while kill -0 $$ 2> /dev/null; do sudo -n -v; sleep 60; done 2> /dev/null &
|
||||
while kill -0 $$ 2> /dev/null; do sudo -n -v; sleep 60; done > /dev/null 2>&1 &
|
||||
SUDO_KEEPALIVE_PID=$!
|
||||
trap 'kill "$SUDO_KEEPALIVE_PID" 2> /dev/null' EXIT
|
||||
on_exit() {
|
||||
local status=$?
|
||||
kill "$SUDO_KEEPALIVE_PID" 2> /dev/null
|
||||
if (( status != 0 )) && [ -n "$INSTALL_LOG" ]; then
|
||||
echo "The install stopped with an error. The full output is in $INSTALL_LOG"
|
||||
fi
|
||||
}
|
||||
trap on_exit EXIT
|
||||
|
||||
# Ensure git is available before attempting to clone anything
|
||||
if ! command -v git &> /dev/null; then
|
||||
@@ -283,7 +298,9 @@ if ~/.local/bin/configure --list | grep -q '^to do'; then
|
||||
echo "$CONFIGURE_HINT"
|
||||
if { : < /dev/tty; } 2> /dev/null && read -rp "Run configure now? [Y/n] " answer < /dev/tty \
|
||||
&& [[ "$answer" != [nN]* ]]; then
|
||||
~/.local/bin/configure < /dev/tty || true
|
||||
# Straight to the terminal, outside the log: sign-ins need a terminal, and
|
||||
# their codes and links don't belong in a log
|
||||
~/.local/bin/configure < /dev/tty > /dev/tty 2>&1 || true
|
||||
else
|
||||
echo "To do it later, run: configure"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user