diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c35ec2 --- /dev/null +++ b/README.md @@ -0,0 +1,175 @@ +# Linux System Updater (`linux-updater`) + +[![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) +[![Platforms](https://img.shields.io/badge/distros-Debian%20%7C%20Ubuntu%20%7C%20RHEL%20%7C%20Fedora%20%7C%20AlmaLinux%20%7C%20Rocky%20%7C%20Arch-lightgrey.svg)]() + +`linux-updater` is an enterprise-grade, standalone, zero-dependency Python 3 CLI tool designed to safely inspect, auto-remediate, and update Linux systems. It supports Debian, Ubuntu, RHEL (8 & 9), Fedora, AlmaLinux, Rocky Linux, and Arch Linux. + +--- + +## Key Features + +- **Zero External Dependencies:** Built entirely with the Python standard library. Runs out of the box on Python >= 3.6 (including stock AlmaLinux 8 / RHEL 8 without pip or AppStream updates). +- **Pre-flight Health Diagnostics:** + - **Disk Space:** Enforces safety thresholds on `/boot` (>= 250 MB), `/var` (>= 1024 MB), and `/` (>= 1024 MB). + - **Process Locks:** Detects active package manager locks (via PID checking and non-blocking `fcntl.flock` advisory locks). + - **Memory & OOM Pressure:** Inspects `/proc/meminfo` to warn or halt if available RAM is dangerously low (< 300 MB). + - **AC Power Protection:** Inspects `/sys/class/power_supply` on laptops to prevent updates on battery power. + - **Reboot Detection:** Detects pending reboots from previous kernel/library updates. +- **Safe Automated Remediation:** Safely cleans package cache when `/var` is low and clears stale locks if the holder process is confirmed dead. +- **Two Update Tiers:** + - `update`: Routine updates (with optional selective package targeting via `--packages`). + - `release-upgrade`: Major distribution upgrades (e.g. Debian 12 $\rightarrow$ 13, Ubuntu 22.04 $\rightarrow$ 24.04, Fedora 40 $\rightarrow$ 41, or RHEL/AlmaLinux `leapp` upgrades) with safety warnings. +- **Standard Linux FHS Logging:** + - Logs transactions to `/var/log/linux-updater/linux-updater--.log`. + - Atomically maintains `/var/log/linux-updater/latest.log` symlink pointing to the most recent execution. +- **Automation Ready:** + - Structured `--json` output for Zabbix, Wazuh, Prometheus node exporters, or custom agents. + - Non-interactive mode (`-y` / `--non-interactive`) for cron and systemd timers. + - Deterministic exit codes. + +--- + +## Distribution Support Matrix + +| Family | Distributions Supported | Package Manager Driver | Major Upgrade Driver | +|---|---|---|---| +| **Debian** | Debian 11/12/Testing, Ubuntu 20.04/22.04/24.04, Linux Mint | `apt` / `apt-get` | `do-release-upgrade` or `apt-get dist-upgrade` | +| **RHEL** | RHEL 8 & 9, AlmaLinux 8 & 9, Rocky Linux 8 & 9, CentOS Stream, Fedora 39/40/41 | `dnf` | `dnf system-upgrade` (Fedora) or `leapp` (RHEL/AlmaLinux) | +| **Arch** | Arch Linux, Manjaro, EndeavourOS | `pacman` | `pacman -Syu` (Rolling sync) | + +--- + +## Installation + +### Option 1: Native `.deb` Package (Debian / Ubuntu) +```bash +# Build package using pure Python standard library: +python3 packaging/build_packages.py + +# Install generated deb: +sudo dpkg -i dist/linux-updater_1.0.0_all.deb +``` + +### Option 2: Native `.rpm` Package (RHEL / Fedora / AlmaLinux / Rocky) +```bash +# Build package (sets up RPM tree and calls rpmbuild): +python3 packaging/build_packages.py + +# Install generated rpm: +sudo rpm -Uvh dist/rpm/RPMS/noarch/linux-updater-*.noarch.rpm +``` + +### Option 3: Standalone Tarball (All Linux Distributions) +```bash +tar -xzf dist/linux-updater-1.0.0.tar.gz +cd linux-updater-1.0.0 +sudo ./install.sh +``` + +--- + +## Quickstart & Common Usage + +```bash +# 1. Run pre-flight health checks and print diagnostics: +linux-updater health + +# 2. Output health diagnostics as JSON (monitoring): +linux-updater health --json + +# 3. Check for available updates non-destructively: +linux-updater check + +# 4. Simulate a routine system update (dry run): +linux-updater update --dry-run + +# 5. Apply routine updates interactively (with confirmation prompt): +sudo linux-updater update + +# 6. Apply updates non-interactively (e.g. from cron or Ansible): +sudo linux-updater -y update + +# 7. Selectively update specific packages: +sudo linux-updater -y update --packages openssl nginx + +# 8. Simulate major distribution release upgrade: +sudo linux-updater release-upgrade --dry-run -t 41 + +# 9. Clean package cache and remove orphaned packages: +sudo linux-updater clean --all +``` + +--- + +## Configuration Reference (`/etc/linux-updater.json`) + +Default settings can be customized in `/etc/linux-updater.json`: + +```json +{ + "thresholds": { + "min_boot_mb": 250, + "min_var_mb": 1024, + "min_root_mb": 1024, + "min_ram_mb": 300 + }, + "behavior": { + "auto_remediate": true, + "non_interactive": false, + "check_ac_power": true, + "clean_after_update": false + }, + "logging": { + "log_dir": "/var/log/linux-updater", + "log_file": null, + "verbose": false + } +} +``` + +CLI flags always take precedence over configuration file values. + +--- + +## Exit Codes + +| Code | Status | Meaning | +|---|---|---| +| `0` | **Success** | All operations completed cleanly; no reboot required. | +| `1` | **Error** | Pre-flight check failed and unrecovered, or package manager command returned non-zero. | +| `2` | **Reboot Required** | Operation succeeded, but a system reboot is required (kernel or core library updated). | +| `3` | **Aborted** | User cancelled operation at interactive confirmation prompt. | + +--- + +## Containerized Testing Matrix + +All packaging builds and integration tests run inside clean Podman containers: + +```bash +# Run tests for all distros (Debian 12, Ubuntu 22.04, Fedora 40, AlmaLinux 8): +./tests/containers/run_tests.sh all + +# Or run for a specific distro: +./tests/containers/run_tests.sh debian +./tests/containers/run_tests.sh ubuntu +./tests/containers/run_tests.sh fedora +./tests/containers/run_tests.sh almalinux8 +``` + +--- + +## Documentation + +- [User Guide](docs/user-guide.md): Comprehensive instructions for operators and desktop users. +- [Administrator Guide](docs/admin-guide.md): Automation, cron/systemd configuration, monitoring, and logrotate setup. +- [Developer Guide](docs/developer-guide.md): Internal architecture, adding new package managers, and test development. +- [MAN Page (Section 8)](man/linux-updater.8): System administration manual (`man 8 linux-updater`). + +--- + +## License + +MIT License. See [LICENSE](LICENSE) for details. diff --git a/docs/admin-guide.md b/docs/admin-guide.md new file mode 100644 index 0000000..7ceb1a7 --- /dev/null +++ b/docs/admin-guide.md @@ -0,0 +1,192 @@ +# Linux System Updater: Administrator Guide + +This guide covers enterprise deployment, automated scheduling, monitoring, log management, and configuration tuning for `linux-updater`. + +--- + +## 1. Automated Execution (Cron & Systemd) + +For automated maintenance windows, run `linux-updater` non-interactively using the `-y` (`--non-interactive`) flag. + +### A. Systemd Service & Timer (Recommended) + +Create `/etc/systemd/system/linux-updater.service`: +```ini +[Unit] +Description=Automated Safe Linux System Updater +After=network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/linux-updater -y update +StandardOutput=journal +StandardError=journal +``` + +Create `/etc/systemd/system/linux-updater.timer`: +```ini +[Unit] +Description=Weekly automated system update + +[Timer] +OnCalendar=Sun *-*-* 03:00:00 +Persistent=true +RandomizedDelaySec=1800 + +[Install] +WantedBy=timers.target +``` + +Enable and activate the timer: +```bash +sudo systemctl daemon-reload +sudo systemctl enable --now linux-updater.timer +sudo systemctl list-timers linux-updater.timer +``` + +### B. Standard Cron Job + +Alternatively, add an entry to `/etc/cron.d/linux-updater`: +```cron +# Run every Sunday at 03:30 AM +30 3 * * 0 root /usr/bin/linux-updater -y update > /dev/null 2>&1 +``` + +--- + +## 2. Configuration Reference (`/etc/linux-updater.json`) + +The default configuration file `/etc/linux-updater.json` governs health check thresholds and update behaviors: + +```json +{ + "thresholds": { + "min_boot_mb": 250, + "min_var_mb": 1024, + "min_root_mb": 1024, + "min_ram_mb": 300 + }, + "behavior": { + "auto_remediate": true, + "non_interactive": false, + "check_ac_power": true, + "clean_after_update": false + }, + "logging": { + "log_dir": "/var/log/linux-updater", + "log_file": null, + "verbose": false + } +} +``` + +### Threshold Parameters +- `min_boot_mb`: Minimum required free space in `/boot`. Prevents failed kernel installations. Defaults to 250 MB. +- `min_var_mb`: Minimum required free space in `/var`. If space drops below this, auto-remediation triggers a cache purge. Defaults to 1024 MB (1 GB). +- `min_root_mb`: Minimum free space on root `/`. Defaults to 1024 MB. +- `min_ram_mb`: Available RAM threshold in `/proc/meminfo`. Protects against OOM killer crashing package scripts. Defaults to 300 MB. + +### Behavior Parameters +- `auto_remediate`: When `true`, automatically clears package cache if `/var` is low and unlinks stale locks if the holder PID is dead. +- `non_interactive`: Default non-interactive state. (Overridden by CLI `-y`). +- `check_ac_power`: Inspects `/sys/class/power_supply` and warns/halts if running on battery power. +- `clean_after_update`: If `true`, runs `autoremove` automatically after successful updates. + +--- + +## 3. Monitoring & Structured JSON Integration + +`linux-updater` includes native `--json` output for direct consumption by monitoring agents (Zabbix, Wazuh, Prometheus node exporter textfile collector). + +### Health Monitoring Check +```bash +linux-updater health --json +``` + +**JSON Output:** +```json +{ + "passed": true, + "results": [ + { + "name": "disk_boot", + "status": "PASS", + "message": "/boot free space is sufficient: 1042MB", + "can_remediate": false, + "remediation_id": null + }, + { + "name": "disk_var", + "status": "PASS", + "message": "/var free space is sufficient: 42100MB", + "can_remediate": false, + "remediation_id": null + }, + { + "name": "memory_available", + "status": "PASS", + "message": "Available RAM is sufficient: 7850MB", + "can_remediate": false, + "remediation_id": null + }, + { + "name": "pending_reboot", + "status": "PASS", + "message": "No pending system reboot detected.", + "can_remediate": false, + "remediation_id": null + } + ], + "remediations_performed": [] +} +``` + +### Exit Code Handling in Automation Scripts + +In shell scripts, handle the four deterministic exit codes: + +```bash +#!/bin/bash +linux-updater -y update +STATUS=$? + +case $STATUS in + 0) + echo "Updates succeeded cleanly. No reboot required." + ;; + 1) + echo "Update or health check failed! Raising alert." >&2 + exit 1 + ;; + 2) + echo "Updates applied successfully. System reboot required!" + # Optional automated reboot: + # /sbin/reboot + ;; + 3) + echo "Operation aborted by user." + ;; +esac +``` + +--- + +## 4. Log Management & Logrotate + +By default, logs are written to `/var/log/linux-updater/` with: +- Timestamped files: `linux-updater-YYYYMMDD-HHMMSS.log` +- Symlink to latest run: `/var/log/linux-updater/latest.log` + +To manage historical logs and compress older runs, configure `/etc/logrotate.d/linux-updater`: + +```text +/var/log/linux-updater/*.log { + weekly + rotate 12 + compress + missingok + notifempty + create 0640 root root +} +``` diff --git a/docs/developer-guide.md b/docs/developer-guide.md new file mode 100644 index 0000000..00aa5ca --- /dev/null +++ b/docs/developer-guide.md @@ -0,0 +1,154 @@ +# Linux System Updater: Developer Guide + +This guide provides technical specifications, architectural details, and developer workflows for contributing to `linux-updater`. + +--- + +## 1. Architectural Overview + +`linux-updater` follows a clean separation of concerns: + +```text +linux_updater/ +├── __init__.py # Package version definition +├── __main__.py # CLI invocation entrypoint (python3 -m linux_updater) +├── cli.py # Argument parsing, formatting, execution controller +├── config.py # JSON configuration loader & default thresholds +├── models.py # Core data transfer objects (DistroInfo, CheckResult, etc.) +├── core/ +│ ├── detector.py # Distro detection via /etc/os-release parsing +│ ├── health.py # Pre-flight health diagnostics & lock checking +│ ├── remediation.py # Automated remediation actions (cache, stale locks) +│ └── runner.py # Subprocess runner with timestamped file logging +└── managers/ + ├── __init__.py # get_manager() factory + ├── base.py # PackageManager abstract base class interface + ├── apt.py # Debian/Ubuntu (APT) driver + ├── dnf.py # RHEL/Fedora/CentOS/AlmaLinux/Rocky (DNF) driver + └── pacman.py # Arch Linux (Pacman) driver +``` + +--- + +## 2. Hard Constraints & Coding Standards + +1. **Python >= 3.6 Standard Library Baseline:** + - **NO** external `pip` dependencies. Zero third-party packages allowed. + - **NO** `dataclasses` (introduced in Python 3.7). Use standard classes or `NamedTuple`. + - **NO** `subprocess.run(capture_output=True)` (introduced in Python 3.7). Use `stdout=subprocess.PIPE, stderr=subprocess.PIPE`. + - **NO** modern union operators like `int | None` (introduced in Python 3.10). Use `Optional[int]`. +2. **Deterministic Return Codes:** + - Always map execution outcomes to standard exit codes (`0` clean, `1` error, `2` reboot required, `3` user abort). +3. **Container-First Verification:** + - All tests against actual package managers and distributions MUST be run inside clean Podman containers, never on the host system. + +--- + +## 3. Implementing a New Package Manager Driver + +To add support for a new package manager (e.g. `zypper` for openSUSE or `apk` for Alpine): + +1. **Subclass `PackageManager`** in `linux_updater/managers/.py`: + +```python +from pathlib import Path +from typing import List, Optional +from linux_updater.managers.base import PackageManager +from linux_updater.models import CommandResult, PackageUpdate, RebootStatus + +class ZypperManager(PackageManager): + @property + def name(self) -> str: + return "zypper" + + def refresh_repositories(self) -> CommandResult: + return self.runner.run(["zypper", "refresh"]) + + def check_updates(self) -> List[PackageUpdate]: + # Parse 'zypper list-updates' + ... + + def apply_updates(self, packages=None, dry_run=False, non_interactive=False) -> CommandResult: + cmd = ["zypper", "update"] + if dry_run: + cmd.append("--dry-run") + if non_interactive: + cmd.append("-y") + if packages: + cmd.extend(packages) + return self.runner.run(cmd) + + def release_upgrade(self, target_release=None, dry_run=False, non_interactive=False) -> CommandResult: + cmd = ["zypper", "dup"] + if dry_run: + cmd.append("--dry-run") + if non_interactive: + cmd.append("-y") + return self.runner.run(cmd) + + def clean_cache(self) -> CommandResult: + return self.runner.run(["zypper", "clean", "-a"]) + + def autoremove(self) -> CommandResult: + return self.runner.run(["zypper", "rm", "-u"]) + + def is_reboot_required(self) -> RebootStatus: + res = self.runner.run(["zypper", "needs-rebooting"]) + return RebootStatus(required=(res.return_code != 0)) + + def get_lock_files(self) -> List[Path]: + return [Path("/var/run/zypp.pid")] +``` + +2. **Register in `linux_updater/managers/__init__.py`:** +```python +def get_manager(family: str, runner: Optional[CommandRunner] = None) -> PackageManager: + ... + elif family == "suse": + return ZypperManager(runner=runner) +``` + +3. **Add Distro Mapping in `linux_updater/models.py` and `core/detector.py`:** +Ensure `/etc/os-release` `ID` or `ID_LIKE` values map to the new family. + +--- + +## 4. Testing & Quality Assurance + +### Local Unit Tests +Unit tests use mocks and run locally with Python's built-in `unittest` runner: + +```bash +python3 -m unittest discover tests +``` + +### Container Integration Tests (Podman) +Automated multi-distro container integration testing is orchestrated by `tests/containers/run_tests.sh`: + +```bash +# Test all distributions (Debian 12, Ubuntu 22.04, Fedora 40, AlmaLinux 8): +./tests/containers/run_tests.sh all + +# Test a single distribution: +./tests/containers/run_tests.sh debian +./tests/containers/run_tests.sh ubuntu +./tests/containers/run_tests.sh fedora +./tests/containers/run_tests.sh almalinux8 +``` + +The script automatically mounts `/workspace:Z`, builds `.deb` or `.rpm` packages from source, installs the package inside the container, verifies the binary, runs health checks, tests routine update (dry-run), tests release-upgrade (dry-run), and verifies `/var/log/linux-updater/` logging. + +--- + +## 5. Building Distribution Packages + +Run the pure Python builder script: + +```bash +python3 packaging/build_packages.py +``` + +Generated artifacts: +- `dist/linux-updater-1.0.0.tar.gz`: Standalone distribution archive containing `install.sh`. +- `dist/linux-updater_1.0.0_all.deb`: Native Debian/Ubuntu binary package. +- `dist/rpm/RPMS/noarch/linux-updater-1.0.0-1.*.noarch.rpm`: Native RPM package. diff --git a/docs/plans/linux-system-updater/00-status.md b/docs/plans/linux-system-updater/00-status.md index e7a7338..59da053 100644 --- a/docs/plans/linux-system-updater/00-status.md +++ b/docs/plans/linux-system-updater/00-status.md @@ -11,7 +11,7 @@ - [x] Slice 3 — package managers (apt, dnf, pacman) & routine updates - [x] Slice 4 — major release upgrade & configuration engine - [x] Slice 5 — packaging & distribution (.tar.gz, .deb, .rpm) -- [ ] Slice 6 — documentation (man page, README, user/admin/developer guides) +- [x] Slice 6 — documentation (man page, README, user/admin/developer guides) ## Notes for a fresh session - Project: Multi-distribution Linux system updater in Python. diff --git a/docs/user-guide.md b/docs/user-guide.md new file mode 100644 index 0000000..115c859 --- /dev/null +++ b/docs/user-guide.md @@ -0,0 +1,153 @@ +# Linux System Updater: User Guide + +Welcome to the **Linux System Updater** (`linux-updater`) User Guide. This guide covers how to safely inspect and update your Linux workstation or server using `linux-updater`. + +--- + +## 1. Overview & Philosophy + +Updating a Linux system can occasionally fail due to preventable conditions: +- `/boot` partition running out of inodes or disk space during kernel installation. +- Leftover package manager lock files from crashed background processes. +- Memory exhaustion causing package compilers or post-install scripts to fail. +- Sudden laptop power loss during critical package unpacking. + +`linux-updater` acts as an intelligent safety wrapper around your system's native package manager (`apt`, `dnf`, or `pacman`). Before making any modifications, it verifies that the system is in a healthy, safe state to upgrade. + +--- + +## 2. Interactive CLI Workflow + +### Checking System Health (`health`) +To run a fast pre-flight diagnostic without checking for updates or altering system state: + +```bash +linux-updater health +``` + +**Example Output:** +```text +Linux System Updater v1.0.0 +Detected System: Ubuntu 24.04.1 LTS (Family: debian) + +Pre-flight Health Diagnostics: +----------------------------------------------------------------- +[ PASS ] disk_boot /boot free space is sufficient: 1042MB +[ PASS ] disk_var /var free space is sufficient: 42100MB +[ PASS ] disk_root Root filesystem free space is sufficient: 42100MB +[ PASS ] lock_lock-frontend No lock active at /var/lib/dpkg/lock-frontend +[ PASS ] lock_lock No lock active at /var/lib/dpkg/lock +[ PASS ] lock_lock No lock active at /var/lib/apt/lists/lock +[ PASS ] memory_available Available RAM is sufficient: 7850MB +[ PASS ] pending_reboot No pending system reboot detected. +----------------------------------------------------------------- +Overall Pre-flight Status: PASSED +``` + +### Checking for Available Updates (`check`) +To see which packages have upgrades available without installing anything: + +```bash +linux-updater check +``` + +**Example Output:** +```text +Linux System Updater v1.0.0 +Detected System: Fedora Linux 40 (Family: rhel) +Checking available updates... + +Available Updates (3): +----------------------------------------------------------------- +• openssl.x86_64 1:3.0.7-27 -> 1:3.0.7-28 (baseos) +• nginx.x86_64 1.24.0-1 -> 1.24.0-2 (updates) +• curl.x86_64 8.2.1-1 -> 8.2.1-2 (updates) +----------------------------------------------------------------- +Run 'linux-updater update' to apply updates. +``` + +### Applying Routine System Updates (`update`) +To apply routine package upgrades interactively: + +```bash +sudo linux-updater update +``` + +1. **Pre-flight Checks:** Checks `/boot`, `/var`, `/`, locks, RAM, and power. +2. **Review:** Shows list of available updates. +3. **Confirmation:** Prompts `Proceed with updates? [Y/n]: ` +4. **Execution:** Runs native package upgrade transaction. +5. **Reboot Notice:** Warns if a kernel or core library update requires a reboot. + +### Selective Package Updates (`--packages`) +If you only want to upgrade specific software (e.g. security patches for OpenSSL and Nginx) without touching the rest of the operating system: + +```bash +sudo linux-updater update --packages openssl nginx +``` + +### Simulation / Dry Run (`--dry-run`) +To simulate the complete update transaction without changing package states: + +```bash +linux-updater update --dry-run +``` + +--- + +## 3. Major Distribution Release Upgrade (`release-upgrade`) + +A major distribution upgrade transitions your system from one release version to the next (e.g., Ubuntu 22.04 LTS to 24.04 LTS, Debian 12 to 13, Fedora 40 to 41, or AlmaLinux 8 to 9). + +Because major upgrades modify thousands of core system packages, `linux-updater` introduces strict safety gates: + +```bash +# Simulate upgrade first: +linux-updater release-upgrade --dry-run -t 41 + +# Execute real upgrade: +sudo linux-updater release-upgrade -t 41 +``` + +**Safety Banner:** +```text +================================================================= + WARNING: MAJOR DISTRIBUTION RELEASE UPGRADE +================================================================= +Target Release: 41 +This operation performs a major upgrade of core system components. +Ensure you have a recent system backup or snapshot before proceeding. +================================================================= + +Are you absolutely sure you want to proceed with upgrade to 41? [y/N]: +``` + +--- + +## 4. System Cleanup (`clean`) + +To recover disk space occupied by old downloaded package files: + +```bash +# Clean package download cache: +sudo linux-updater clean + +# Clean cache AND remove orphaned dependencies: +sudo linux-updater clean --all +``` + +--- + +## 5. Reading System Logs + +All execution logs are recorded in `/var/log/linux-updater/`: + +```bash +# View the log from the most recent run: +cat /var/log/linux-updater/latest.log + +# List historical execution logs: +ls -lh /var/log/linux-updater/ +``` + +Each log line includes timestamped records of commands executed, exit codes, and diagnostics. diff --git a/man/linux-updater.8 b/man/linux-updater.8 new file mode 100644 index 0000000..cc8c570 --- /dev/null +++ b/man/linux-updater.8 @@ -0,0 +1,138 @@ +.TH LINUX-UPDATER 8 "October 2026" "linux-updater 1.0.0" "System Administration Utilities" +.SH NAME +linux-updater \- unified, safe multi-distribution Linux system update utility + +.SH SYNOPSIS +.B linux-updater +[\fB\-y\fR|\fB\-\-yes\fR] +[\fB\-c\fR \fICONFIG\fR] +[\fB\-\-dry\-run\fR] +[\fB\-\-no\-remediation\fR] +[\fB\-\-skip\-preflight\fR] +[\fB\-v\fR|\fB\-\-verbose\fR] +[\fB\-\-json\fR] +[\fICOMMAND\fR] [\fIARGS...\fR] + +.SH DESCRIPTION +.B linux-updater +is a standalone, zero-dependency Python 3 utility designed to reliably inspect system health, perform safe automated remediations, and execute updates across major Linux distributions including Debian, Ubuntu, Red Hat Enterprise Linux (RHEL 8 & 9), Fedora, AlmaLinux, Rocky Linux, and Arch Linux. + +Before applying updates, \fBlinux-updater\fR executes comprehensive pre-flight health checks: +.IP \(bu 2 +Free disk space verification on \fB/boot\fR (min 250MB), \fB/var\fR (min 1GB), and root \fB/\fR (min 1GB). +.IP \(bu 2 +Package manager lock detection and advisory locking inspections (\fBfcntl.flock\fR). +.IP \(bu 2 +Memory availability and low-RAM/OOM risk detection via \fB/proc/meminfo\fR. +.IP \(bu 2 +AC power status detection on portable systems via \fB/sys/class/power_supply\fR. +.IP \(bu 2 +Pending reboot detection from previously installed kernels or libraries. + +If low disk space on \fB/var\fR is detected, \fBlinux-updater\fR safely purges cached packages. If an abandoned lock file is identified whose holder process is confirmed dead, it removes the stale lock. + +.SH COMMANDS +.TP +.B update \fR[\fB\-\-packages \fIPKG...\fR] +Runs pre-flight diagnostics, cleans caches if needed, checks for available updates, prompts for user confirmation (unless \fB\-y\fR is provided), applies routine package upgrades, and reports reboot status. When \fB\-\-packages\fR is specified, updates only the named packages. +.TP +.B check +Non-destructively inspects pre-flight health diagnostics and lists all pending package upgrades without modifying system state. +.TP +.B release\-upgrade \fR[\fB\-t \fITARGET\fR|\fB\-\-target\-release \fITARGET\fR] +Executes a major OS distribution upgrade (e.g. Debian 12 to 13, Ubuntu 22.04 to 24.04, Fedora 40 to 41, or RHEL/AlmaLinux leapp upgrade). Requires explicit user confirmation unless \fB\-y\fR is passed. +.TP +.B clean \fR[\fB\-\-all\fR] +Cleans the local package cache. When \fB\-\-all\fR is given, also removes unused orphaned dependencies. +.TP +.B health +Runs pre-flight system diagnostics and prints a formatted health report (or JSON with \fB\-\-json\fR) without performing updates. + +.SH OPTIONS +.TP +.BR \-y ", " \-\-yes ", " \-\-non\-interactive +Bypasses interactive confirmation prompts. Required for cron, systemd timers, and automated orchestration. +.TP +.BR \-c " \fIPATH\fR, " \-\-config " \fIPATH\fR" +Specifies the path to an alternative JSON configuration file (default: \fI/etc/linux-updater.json\fR). +.TP +.B \-\-dry\-run +Simulates update operations without altering package states on disk. +.TP +.B \-\-no\-remediation +Disables automated remediation actions (such as clearing package caches or unlinking stale locks). +.TP +.B \-\-skip\-preflight +Bypasses all pre-flight health diagnostics. +.TP +.BR \-v ", " \-\-verbose +Enables verbose output and logs every executed subprocess command to stderr. +.TP +.B \-\-json +Formats CLI outputs as structured JSON for consumption by monitoring tools (e.g., Zabbix, Nagios) and automation scripts. +.TP +.B \-\-version +Displays the software version and exits. +.TP +.BR \-h ", " \-\-help +Displays the command-line help summary. + +.SH FILES +.TP +.I /etc/linux-updater.json +System configuration file containing disk thresholds, behavior switches, and logging directory settings. +.TP +.I /var/log/linux-updater/ +Standard directory for execution logs conforming to Linux FHS. Each execution creates a timestamped file \fIlinux-updater-YYYYMMDD-HHMMSS.log\fR. +.TP +.I /var/log/linux-updater/latest.log +Atomic symbolic link pointing to the most recent execution log file. + +.SH EXIT STATUS +.TP +.B 0 +Success. All requested actions finished cleanly and no reboot is needed. +.TP +.B 1 +General error (pre-flight checks failed and could not be remediated, or package manager command failed). +.TP +.B 2 +Success with reboot required. Updates were applied successfully, but a kernel or critical library upgrade requires a system reboot. +.TP +.B 3 +Operation aborted by user at interactive confirmation prompt. + +.SH EXAMPLES +.PP +Run pre-flight health checks and output JSON: +.RS +.B linux-updater health \-\-json +.RE +.PP +Simulate routine system update without changing system state: +.RS +.B linux-updater update \-\-dry\-run +.RE +.PP +Apply routine updates non-interactively: +.RS +.B linux-updater \-y update +.RE +.PP +Selectively update only the openssl and nginx packages: +.RS +.B linux-updater \-y update \-\-packages openssl nginx +.RE +.PP +Simulate major distribution upgrade to target version: +.RS +.B linux-updater release\-upgrade \-\-dry\-run \-t 41 +.RE + +.SH SEE ALSO +.BR apt-get (8), +.BR dnf (8), +.BR pacman (8) + +.SH AUTHORS +Linux System Updater Team. Released under the MIT License. diff --git a/packaging/build_packages.py b/packaging/build_packages.py index 5213438..15b4cc9 100755 --- a/packaging/build_packages.py +++ b/packaging/build_packages.py @@ -101,6 +101,10 @@ class PackageBuilder: str(tmp_root / "linux-updater.json.example"), ) + # Copy man page + if (self.source_root / "man").exists(): + shutil.copytree(str(self.source_root / "man"), str(tmp_root / "man")) + # Archive the tree with tarfile.open(str(out_path), "w:gz") as tar: tar.add(str(tmp_root), arcname=f"linux-updater-{self.version}") @@ -142,6 +146,10 @@ class PackageBuilder: str(self.source_root / "linux-updater.json.example"), str(etc_dir / "linux-updater.json"), ) + if (self.source_root / "man" / "linux-updater.8").exists(): + man_dir = data_dir / "usr" / "share" / "man" / "man8" + man_dir.mkdir(parents=True, exist_ok=True) + shutil.copy2(str(self.source_root / "man" / "linux-updater.8"), str(man_dir / "linux-updater.8")) # If dpkg-deb is available, use it; otherwise build native .deb if shutil.which("dpkg-deb"): @@ -193,6 +201,8 @@ class PackageBuilder: str(self.source_root / "linux-updater.json.example"), str(tmp_root / "linux-updater.json.example"), ) + if (self.source_root / "man").exists(): + shutil.copytree(str(self.source_root / "man"), str(tmp_root / "man")) with tarfile.open(str(tarball_path), "w:gz") as tar: tar.add(str(tmp_root), arcname=f"linux-updater-{self.version}") diff --git a/packaging/install.sh b/packaging/install.sh index 67b62b1..405dfab 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -33,4 +33,10 @@ if [ ! -f "${SYSCONFDIR}/linux-updater.json" ] && [ -f "${SCRIPT_DIR}/linux-upda chmod 644 "${SYSCONFDIR}/linux-updater.json" fi +# Install man page +if [ -f "${SCRIPT_DIR}/man/linux-updater.8" ]; then + mkdir -p "${PREFIX}/share/man/man8" + install -m 644 "${SCRIPT_DIR}/man/linux-updater.8" "${PREFIX}/share/man/man8/linux-updater.8" +fi + echo "Installation complete! Run 'linux-updater --help' to verify." diff --git a/packaging/rpm/linux-updater.spec b/packaging/rpm/linux-updater.spec index 5895e16..ce455ac 100644 --- a/packaging/rpm/linux-updater.spec +++ b/packaging/rpm/linux-updater.spec @@ -32,6 +32,10 @@ mkdir -p $RPM_BUILD_ROOT/var/log/linux-updater cp -r linux_updater $RPM_BUILD_ROOT/usr/lib/linux-updater/ install -m 755 bin/linux-updater $RPM_BUILD_ROOT/usr/bin/linux-updater install -m 644 linux-updater.json.example $RPM_BUILD_ROOT/etc/linux-updater.json +mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8 +if [ -f man/linux-updater.8 ]; then + install -m 644 man/linux-updater.8 $RPM_BUILD_ROOT%{_mandir}/man8/linux-updater.8 +fi %files %defattr(-,root,root,-) @@ -39,6 +43,7 @@ install -m 644 linux-updater.json.example $RPM_BUILD_ROOT/etc/linux-updater.json /usr/lib/linux-updater %config(noreplace) /etc/linux-updater.json %dir %attr(0750, root, root) /var/log/linux-updater +%{_mandir}/man8/linux-updater.8* %changelog * Fri Oct 02 2026 Test Factory - 1.0.0-1 diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 3f0f11a..9098a2d 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -28,6 +28,7 @@ class TestPackaging(unittest.TestCase): self.assertTrue(any("install.sh" in n for n in names)) self.assertTrue(any("linux_updater/__init__.py" in n for n in names)) self.assertTrue(any("linux-updater.json.example" in n for n in names)) + self.assertTrue(any("linux-updater.8" in n for n in names)) def test_build_deb_creates_package_or_tree(self): deb_path = self.builder.build_deb()