mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-20 14:32:20 +01:00
Vendored makepkg's run_pacman() waits on /var/lib/pacman/db.lck existence
with no timeout BEFORE invoking pacman, so an orphaned lock hangs
`makepkg -i` forever ("Pacman is currently in use, please wait...") and
the pacman wrapper's stale-lock cleanup never gets a turn. Wrap makepkg
(mirroring the pacman-wrapper pattern) to clear an orphaned lock up front.
- Extract stale-lock logic into shared pacman_lock_lib.sh; pacman_wrapper
sources it after integrity verification and it is in the SHA256 manifest
- makepkg_wrapper: pre-flight clear for -i/--install; bypass on FAKEROOTKEY
and non-install; FAIL OPEN if the lib is missing (never brick makepkg)
- Cross-user pacman_process_running() pgrep guard: unprivileged makepkg can
detect a root pacman its own fuser cannot see (avoids removing a live lock)
- Upgrade survival: rewrap hook (Install/Upgrade only) + check_makepkg_wrapper
drift verifier + both wrappers wired into the hourly periodic driver
- Fix reorg path bugs: stale ~/linux-configuration periodic path,
$CONFIG_DIR/hosts -> scripts/periodic_background/hosts, test WRAPPER_DIR;
refresh .orig only when target isn't already our symlink (no exec loop)
- Tests: test_makepkg_wrapper.sh (18) incl. hook Operation validity; add
lib-integrity coverage to test_pacman_wrapper_security.sh (also path-fixed)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JsCs1GUyiinA7bg68YvAh1
55 lines
1.6 KiB
Bash
Executable File
55 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Periodic system maintenance script
|
|
# Installs pacman wrapper and updates hosts file
|
|
# This file is installed by setup_periodic_system.sh
|
|
|
|
set -e
|
|
|
|
LOG_FILE="/var/log/periodic-system-maintenance.log"
|
|
|
|
# Path placeholders replaced at install time
|
|
PACMAN_WRAPPER_INSTALL="__PACMAN_WRAPPER_INSTALL__"
|
|
MAKEPKG_WRAPPER_INSTALL="__MAKEPKG_WRAPPER_INSTALL__"
|
|
HOSTS_INSTALL_SCRIPT="__HOSTS_INSTALL_SCRIPT__"
|
|
|
|
# Function to log with timestamp
|
|
log_message() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
|
}
|
|
|
|
# Function to execute with logging
|
|
execute_with_log() {
|
|
local script_path="$1"
|
|
local script_name="$2"
|
|
|
|
log_message "Starting $script_name"
|
|
echo "Executing $script_name..." >&2
|
|
|
|
if [[ -f $script_path ]]; then
|
|
if bash "$script_path" >> "$LOG_FILE" 2>&1; then
|
|
log_message "$script_name completed successfully"
|
|
echo "✓ $script_name completed successfully" >&2
|
|
else
|
|
local ec=$?
|
|
log_message "$script_name failed with exit code $ec"
|
|
echo "✗ $script_name failed (exit $ec)" >&2
|
|
fi
|
|
else
|
|
log_message "$script_name not found at $script_path"
|
|
echo "✗ $script_name not found at $script_path" >&2
|
|
fi
|
|
}
|
|
|
|
# Start maintenance
|
|
log_message "=== Periodic System Maintenance Started ==="
|
|
|
|
# Install pacman wrapper
|
|
execute_with_log "$PACMAN_WRAPPER_INSTALL" "Pacman Wrapper Installation"
|
|
execute_with_log "$MAKEPKG_WRAPPER_INSTALL" "Makepkg Wrapper Installation"
|
|
|
|
# Update hosts file
|
|
execute_with_log "$HOSTS_INSTALL_SCRIPT" "Hosts File Update"
|
|
|
|
log_message "=== Periodic System Maintenance Completed ==="
|
|
echo "Periodic system maintenance completed. Check $LOG_FILE for details." >&2
|