mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
Fix logging
This commit is contained in:
@@ -12,6 +12,27 @@
|
||||
|
||||
set -eEo pipefail
|
||||
|
||||
# Setup comprehensive logging for chroot execution
|
||||
# This ensures all output is captured even though we're running inside chroot
|
||||
CHROOT_LOG_FILE="/var/log/omarchy-install-chroot.log"
|
||||
mkdir -p "$(dirname "$CHROOT_LOG_FILE")"
|
||||
touch "$CHROOT_LOG_FILE"
|
||||
|
||||
# Redirect all output to both the log file and stdout
|
||||
# This way:
|
||||
# 1. Output is saved to /var/log/omarchy-install-chroot.log (inside chroot = /mnt/var/log on ISO)
|
||||
# 2. Output still goes to stdout so arch-chroot can potentially capture it
|
||||
# 3. We use exec to redirect the entire script's output from this point forward
|
||||
exec > >(tee -a "$CHROOT_LOG_FILE") 2>&1
|
||||
|
||||
# Log script start with timestamp
|
||||
echo "========================================"
|
||||
echo "Omarchy Chroot Install Starting"
|
||||
echo "Started at: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
echo "Log file: $CHROOT_LOG_FILE"
|
||||
echo "========================================"
|
||||
echo
|
||||
|
||||
# Find the first non-root user (UID >= 1000, < 60000)
|
||||
OMARCHY_USER=$(getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1; exit}')
|
||||
|
||||
@@ -74,6 +95,12 @@ if [[ $exit_code -eq 0 ]]; then
|
||||
echo "========================================"
|
||||
echo "Omarchy install.sh completed successfully!"
|
||||
echo "========================================"
|
||||
echo
|
||||
echo "========================================"
|
||||
echo "Omarchy Chroot Install Completed"
|
||||
echo "Finished at: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
echo "Log file: $CHROOT_LOG_FILE"
|
||||
echo "========================================"
|
||||
else
|
||||
echo
|
||||
echo "========================================"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Log output UI for .automated_script.sh
|
||||
# Tails /var/log/omarchy-install.log and displays it with pretty formatting
|
||||
# Tails one or more log files and displays them with pretty formatting
|
||||
# Supports multiple files: start_log_output file1 file2 file3
|
||||
# Uses tail -F so it waits for files that don't exist yet
|
||||
start_log_output() {
|
||||
local ANSI_SAVE_CURSOR="\033[s"
|
||||
local ANSI_RESTORE_CURSOR="\033[u"
|
||||
@@ -8,7 +10,8 @@ start_log_output() {
|
||||
local ANSI_RESET="\033[0m"
|
||||
local ANSI_GRAY="\033[90m"
|
||||
|
||||
local log_file="${1:-/var/log/omarchy-install.log}"
|
||||
# Support multiple log files, default to main install log
|
||||
local log_files=("${@:-/var/log/omarchy-install.log}")
|
||||
|
||||
# Save cursor position and hide cursor
|
||||
printf $ANSI_SAVE_CURSOR
|
||||
@@ -17,41 +20,67 @@ start_log_output() {
|
||||
(
|
||||
local log_lines=20
|
||||
local max_line_width=$((LOGO_WIDTH - 4))
|
||||
|
||||
while true; do
|
||||
# Read the last N lines into an array
|
||||
mapfile -t current_lines < <(tail -n $log_lines "$log_file" 2>/dev/null)
|
||||
|
||||
# Use tail -F to follow multiple files, even if they don't exist yet
|
||||
# -F = --follow=name --retry (follows by name, waits for files to appear)
|
||||
# -n 0 = start from end (don't show existing content)
|
||||
# -q = quiet (no headers when switching between files)
|
||||
tail -F -n 0 -q "${log_files[@]}" 2>/dev/null | while IFS= read -r line; do
|
||||
# Keep a rolling buffer of the last N lines
|
||||
if [ ! -f /tmp/omarchy-log-buffer.txt ]; then
|
||||
touch /tmp/omarchy-log-buffer.txt
|
||||
fi
|
||||
|
||||
# Append new line and keep only last N lines
|
||||
echo "$line" >> /tmp/omarchy-log-buffer.txt
|
||||
tail -n $log_lines /tmp/omarchy-log-buffer.txt > /tmp/omarchy-log-buffer.tmp
|
||||
mv /tmp/omarchy-log-buffer.tmp /tmp/omarchy-log-buffer.txt
|
||||
|
||||
# Read current buffer
|
||||
mapfile -t current_lines < /tmp/omarchy-log-buffer.txt
|
||||
|
||||
# Build complete output buffer with escape sequences
|
||||
output=""
|
||||
for ((i = 0; i < log_lines; i++)); do
|
||||
line="${current_lines[i]:-}"
|
||||
current_line="${current_lines[i]:-}"
|
||||
|
||||
# Truncate if needed
|
||||
if [ ${#line} -gt $max_line_width ]; then
|
||||
line="${line:0:$max_line_width}..."
|
||||
if [ ${#current_line} -gt $max_line_width ]; then
|
||||
current_line="${current_line:0:$max_line_width}..."
|
||||
fi
|
||||
|
||||
# Add clear line escape and formatted output for each line
|
||||
if [ -n "$line" ]; then
|
||||
output+="${ANSI_CLEAR_LINE}${ANSI_GRAY}${PADDING_LEFT_SPACES} → ${line}${ANSI_RESET}\n"
|
||||
if [ -n "$current_line" ]; then
|
||||
output+="${ANSI_CLEAR_LINE}${ANSI_GRAY}${PADDING_LEFT_SPACES} → ${current_line}${ANSI_RESET}\n"
|
||||
else
|
||||
output+="${ANSI_CLEAR_LINE}${PADDING_LEFT_SPACES}\n"
|
||||
fi
|
||||
done
|
||||
|
||||
printf "${ANSI_RESTORE_CURSOR}%b" "$output"
|
||||
|
||||
sleep 0.1
|
||||
done
|
||||
) &
|
||||
monitor_pid=$!
|
||||
}
|
||||
|
||||
stop_log_output() {
|
||||
local ANSI_SHOW_CURSOR="\033[?25h"
|
||||
|
||||
if [ -n "${monitor_pid:-}" ]; then
|
||||
kill $monitor_pid 2>/dev/null || true
|
||||
wait $monitor_pid 2>/dev/null || true
|
||||
# Kill child processes first (tail -F) with SIGKILL
|
||||
pkill -9 -P $monitor_pid 2>/dev/null || true
|
||||
|
||||
# Kill the monitor process with SIGKILL for immediate termination
|
||||
kill -9 $monitor_pid 2>/dev/null || true
|
||||
|
||||
# Don't wait - SIGKILL is immediate
|
||||
|
||||
# Clean up temp buffer file
|
||||
rm -f /tmp/omarchy-log-buffer.txt /tmp/omarchy-log-buffer.tmp 2>/dev/null || true
|
||||
|
||||
unset monitor_pid
|
||||
fi
|
||||
|
||||
# Restore cursor visibility
|
||||
printf $ANSI_SHOW_CURSOR
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user