Added command logging and refactored execution helpers.
This commit is contained in:
@@ -54,7 +54,9 @@ print_info() {
|
||||
|
||||
# Run a command with gray background for its output
|
||||
# Use this for commands that produce visible output (fdisk, pacstrap, pacman, etc.)
|
||||
# Logs the command before execution for auditing
|
||||
run_visible_cmd() {
|
||||
log_cmd "$@"
|
||||
echo -ne "${COLOR_BG_GRAY}"
|
||||
"$@"
|
||||
local exit_code=$?
|
||||
@@ -62,6 +64,55 @@ run_visible_cmd() {
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Run a command with piped input and gray background for its output
|
||||
# Logs the command (without the piped input) before execution
|
||||
# Arguments:
|
||||
# $1 - input to pipe to the command
|
||||
# $@ - command and arguments
|
||||
run_piped_cmd() {
|
||||
local input="$1"
|
||||
shift
|
||||
log_cmd "$@"
|
||||
echo -ne "${COLOR_BG_GRAY}"
|
||||
echo -n "$input" | "$@"
|
||||
local exit_code=$?
|
||||
echo -e "${COLOR_RESET}"
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Run a command with logging only (no visual wrapper)
|
||||
# Use for commands that need stdout preserved (pipes, redirections)
|
||||
run_cmd() {
|
||||
log_cmd "$@"
|
||||
"$@"
|
||||
}
|
||||
|
||||
# Run a command that is allowed to fail
|
||||
# Logs the command, suppresses stderr, and always returns success
|
||||
# Use for cleanup commands where failure is acceptable
|
||||
run_cmd_allow_fail() {
|
||||
log_cmd "$@"
|
||||
"$@" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Run a command in the chroot environment with logging
|
||||
# Use for commands that don't produce visible output
|
||||
run_cmd_in_chroot() {
|
||||
log_cmd arch-chroot "${MOUNT_POINT}" "$@"
|
||||
arch-chroot "${MOUNT_POINT}" "$@"
|
||||
}
|
||||
|
||||
# Run a command in the chroot environment with gray background
|
||||
# Use for commands that produce visible output (pacman, mkinitcpio, etc.)
|
||||
run_visible_cmd_in_chroot() {
|
||||
log_cmd arch-chroot "${MOUNT_POINT}" "$@"
|
||||
echo -ne "${COLOR_BG_GRAY}"
|
||||
arch-chroot "${MOUNT_POINT}" "$@"
|
||||
local exit_code=$?
|
||||
echo -e "${COLOR_RESET}"
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Print an installation step/phase header with progress indicator
|
||||
print_step() {
|
||||
local step="$1"
|
||||
|
||||
@@ -65,12 +65,12 @@ cleanup_on_error() {
|
||||
print_warning "Cleaning up after error..."
|
||||
|
||||
# Unmount filesystems (ignore errors)
|
||||
umount -R "${MOUNT_POINT}" 2>/dev/null || true
|
||||
run_cmd_allow_fail umount -R "${MOUNT_POINT}"
|
||||
|
||||
# Close LUKS containers (ignore errors)
|
||||
cryptsetup close cryptroot 2>/dev/null || true
|
||||
cryptsetup close cryptroot-primary 2>/dev/null || true
|
||||
cryptsetup close cryptroot-secondary 2>/dev/null || true
|
||||
run_cmd_allow_fail cryptsetup close cryptroot
|
||||
run_cmd_allow_fail cryptsetup close cryptroot-primary
|
||||
run_cmd_allow_fail cryptsetup close cryptroot-secondary
|
||||
|
||||
print "Cleanup complete. You may retry the installation."
|
||||
}
|
||||
@@ -91,6 +91,7 @@ safe_run() {
|
||||
local description="$1"
|
||||
shift
|
||||
|
||||
log_cmd "$@"
|
||||
print " $description..."
|
||||
if ! "$@"; then
|
||||
print_error "Failed: $description"
|
||||
@@ -108,6 +109,7 @@ retry() {
|
||||
local delay="$2"
|
||||
shift 2
|
||||
|
||||
log_cmd "$@"
|
||||
local attempt=1
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if "$@"; then
|
||||
|
||||
@@ -55,6 +55,13 @@ init_logging() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Log a command before execution
|
||||
# Arguments:
|
||||
# $@ - command and arguments to log
|
||||
log_cmd() {
|
||||
echo -e "\033[0;35m[CMD]\033[0m $*"
|
||||
}
|
||||
|
||||
# Copy log file to installed system
|
||||
finalize_logging() {
|
||||
local final_log="${MOUNT_POINT}${LOG_FILE}"
|
||||
|
||||
Reference in New Issue
Block a user