feat: real-time streaming runner, --releasever alias, enriched help examples, and Fedora offline upgrade guidance
This commit is contained in:
1 parent
5940327b54
commit
b1c0f22ce7
8 files changed
+247
-37
No files matched your search
+98
-11
@@ -59,8 +59,22 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="linux-updater",
|
||||
description="Unified, safe multi-distribution Linux system updater and health inspector.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
parents=[common],
|
||||
epilog="""
|
||||
Examples:
|
||||
linux-updater health # Run pre-flight health diagnostic checks
|
||||
linux-updater check # Check for available updates without applying
|
||||
sudo linux-updater update # Update system packages interactively
|
||||
sudo linux-updater update -y # Non-interactive automated update
|
||||
sudo linux-updater update --packages curl # Selectively update specific package(s)
|
||||
sudo linux-updater release-upgrade -t 44 # Upgrade distribution release (Fedora/RHEL/Debian/Ubuntu)
|
||||
sudo linux-updater clean --all # Clean package cache and unused dependencies
|
||||
|
||||
Subcommand Help:
|
||||
Run 'linux-updater <subcommand> --help' for options specific to that subcommand.
|
||||
Example: 'linux-updater release-upgrade --help'
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v", "--version",
|
||||
@@ -76,7 +90,15 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"update",
|
||||
parents=[common],
|
||||
help="Inspect health, auto-remediate safe issues, and apply package updates.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="Inspect health, auto-remediate safe issues, and apply package updates.",
|
||||
epilog="""
|
||||
Examples:
|
||||
sudo linux-updater update
|
||||
sudo linux-updater update -y
|
||||
sudo linux-updater update --dry-run
|
||||
sudo linux-updater update --packages nginx redis
|
||||
""",
|
||||
)
|
||||
update_parser.add_argument(
|
||||
"--packages",
|
||||
@@ -90,7 +112,13 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"check",
|
||||
parents=[common],
|
||||
help="Check system health and list available updates without making modifications.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="Check system health and list available updates without making modifications.",
|
||||
epilog="""
|
||||
Examples:
|
||||
linux-updater check
|
||||
linux-updater check --json
|
||||
""",
|
||||
)
|
||||
|
||||
# Subcommand: release-upgrade
|
||||
@@ -98,12 +126,26 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"release-upgrade",
|
||||
parents=[common],
|
||||
help="Perform a major distribution release upgrade with additional safety guardrails.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="Perform a major distribution release upgrade with safety checks (e.g. Fedora, Ubuntu, AlmaLinux/Rocky).",
|
||||
epilog="""
|
||||
Target Release Specification:
|
||||
On Fedora and Red Hat-based systems, you must specify the target release version.
|
||||
Both '-t / --target-release' and '--releasever' are supported.
|
||||
|
||||
Examples:
|
||||
sudo linux-updater release-upgrade -t 44 # Fedora: upgrade to version 44
|
||||
sudo linux-updater release-upgrade --releasever 44 # Fedora: alias syntax
|
||||
sudo linux-updater release-upgrade -t 24.04 # Ubuntu/Debian: upgrade to 24.04
|
||||
sudo linux-updater release-upgrade -t 9 # AlmaLinux / Rocky: upgrade to EL 9
|
||||
sudo linux-updater release-upgrade -t 44 --dry-run # Simulate upgrade without applying
|
||||
""",
|
||||
)
|
||||
release_parser.add_argument(
|
||||
"-t", "--target-release",
|
||||
"-t", "--target-release", "--releasever",
|
||||
dest="target_release",
|
||||
type=str,
|
||||
help="Specify the target distribution version number/codename (e.g. 24.04, 41).",
|
||||
help="Specify target distribution version number/codename (e.g. 44 for Fedora, 24.04 for Ubuntu, 9 for AlmaLinux).",
|
||||
)
|
||||
|
||||
# Subcommand: clean
|
||||
@@ -111,7 +153,13 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"clean",
|
||||
parents=[common],
|
||||
help="Clean downloaded package cache and remove orphaned packages.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="Clean downloaded package cache and remove orphaned packages.",
|
||||
epilog="""
|
||||
Examples:
|
||||
sudo linux-updater clean
|
||||
sudo linux-updater clean --all
|
||||
""",
|
||||
)
|
||||
clean_parser.add_argument(
|
||||
"--all",
|
||||
@@ -124,7 +172,14 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
"health",
|
||||
parents=[common],
|
||||
help="Run only the pre-flight health diagnostic checks.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="Run only the pre-flight health diagnostic checks and print a formatted report.",
|
||||
epilog="""
|
||||
Examples:
|
||||
linux-updater health
|
||||
linux-updater health --json
|
||||
linux-updater health --no-remediation
|
||||
""",
|
||||
)
|
||||
|
||||
return parser
|
||||
@@ -247,6 +302,9 @@ def _run(
|
||||
json_output: bool,
|
||||
config_path: str,
|
||||
) -> int:
|
||||
if json_output:
|
||||
os.environ["LINUX_UPDATER_NO_STREAM"] = "1"
|
||||
|
||||
config = UpdaterConfig.load(Path(config_path) if config_path else None)
|
||||
if non_interactive:
|
||||
config.non_interactive = True
|
||||
@@ -430,6 +488,30 @@ def _run(
|
||||
# 6. Release-Upgrade Command
|
||||
if args.command == "release-upgrade":
|
||||
target = getattr(args, "target_release", None)
|
||||
|
||||
if distro.distro_id.lower() == "fedora" and not target:
|
||||
current_ver = distro.version_id.strip() if distro.version_id else ""
|
||||
suggested = f"-t {int(current_ver) + 1}" if current_ver.isdigit() else "-t <version>"
|
||||
if not json_output:
|
||||
print(
|
||||
f"\nError: Fedora major release upgrade requires specifying the target version.\n"
|
||||
f"Current system version: Fedora {distro.version_id or 'unknown'}\n\n"
|
||||
f"Usage:\n"
|
||||
f" sudo linux-updater release-upgrade -t <version>\n"
|
||||
f" sudo linux-updater release-upgrade --releasever <version>\n\n"
|
||||
f"Examples:\n"
|
||||
f" sudo linux-updater release-upgrade {suggested}\n"
|
||||
f" sudo linux-updater release-upgrade {suggested} --dry-run\n",
|
||||
file=sys.stderr,
|
||||
)
|
||||
else:
|
||||
print(json.dumps({
|
||||
"success": False,
|
||||
"error": "Target release version required for Fedora",
|
||||
"current_version": distro.version_id,
|
||||
}, indent=2))
|
||||
return 1
|
||||
|
||||
if not json_output:
|
||||
print("\n" + "=" * 65)
|
||||
print(" WARNING: MAJOR DISTRIBUTION RELEASE UPGRADE")
|
||||
@@ -470,9 +552,14 @@ def _run(
|
||||
"reboot_required": reboot.required,
|
||||
}, indent=2))
|
||||
else:
|
||||
print("\nRelease upgrade completed successfully!")
|
||||
if reboot.required:
|
||||
print("\n[!] ATTENTION: A system reboot is required to boot into the new release.")
|
||||
print("\nRelease upgrade preparation completed successfully!")
|
||||
if distro.distro_id.lower() == "fedora" and not dry_run:
|
||||
print("\n[!] ATTENTION: Fedora offline upgrade packages have been downloaded.")
|
||||
print(" To execute the upgrade and reboot into the new release, run:")
|
||||
print(" sudo dnf system-upgrade reboot")
|
||||
return 2
|
||||
elif reboot.required:
|
||||
print(f"\n[!] ATTENTION: A system reboot is required to boot into the new release ({reboot.reason}).")
|
||||
return 2
|
||||
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user