feat: release v2.0.0 with tab completion, package filtering, db health checks, flatpak and logrotate
Build and Publish Release / Build Packages and Publish (push) Successful in 27s
Build and Publish Release / Build Packages and Publish (push) Successful in 27s
This commit is contained in:
1 parent
8d4157b42d
commit
8bec4ed932
27 files changed
+1053
-69
No files matched your search
@@ -0,0 +1,163 @@
|
||||
"""Shell completion script generator for linux-updater (Bash & Zsh)."""
|
||||
|
||||
BASH_COMPLETION = """# bash completion for linux-updater
|
||||
|
||||
_linux_updater() {
|
||||
local cur prev words cword
|
||||
_init_completion -n : || return
|
||||
|
||||
local commands="update check release-upgrade clean health completion"
|
||||
local common_opts="-c --config -y --yes --non-interactive --dry-run --no-remediation --skip-preflight --json --reboot -h --help"
|
||||
|
||||
# Find the current subcommand (if any)
|
||||
local cmd=""
|
||||
local i
|
||||
for (( i=1; i < cword; i++ )); do
|
||||
case "${words[i]}" in
|
||||
update|check|release-upgrade|clean|health|completion)
|
||||
cmd="${words[i]}"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Handle completion for previous option
|
||||
case "$prev" in
|
||||
-c|--config)
|
||||
_filedir json
|
||||
return 0
|
||||
;;
|
||||
-t|--target-release|--releasever)
|
||||
return 0
|
||||
;;
|
||||
--packages|--exclude)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# If no subcommand has been entered yet
|
||||
if [[ -z "$cmd" ]]; then
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $(compgen -W "$common_opts -v --version" -- "$cur") )
|
||||
return 0
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Subcommand-specific completions
|
||||
case "$cmd" in
|
||||
update)
|
||||
COMPREPLY=( $(compgen -W "$common_opts --packages --exclude --security --flatpak" -- "$cur") )
|
||||
;;
|
||||
check)
|
||||
COMPREPLY=( $(compgen -W "$common_opts" -- "$cur") )
|
||||
;;
|
||||
release-upgrade)
|
||||
COMPREPLY=( $(compgen -W "$common_opts -t --target-release --releasever" -- "$cur") )
|
||||
;;
|
||||
clean)
|
||||
COMPREPLY=( $(compgen -W "$common_opts --all" -- "$cur") )
|
||||
;;
|
||||
health)
|
||||
COMPREPLY=( $(compgen -W "$common_opts" -- "$cur") )
|
||||
;;
|
||||
completion)
|
||||
COMPREPLY=( $(compgen -W "bash zsh" -- "$cur") )
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -F _linux_updater linux-updater
|
||||
"""
|
||||
|
||||
ZSH_COMPLETION = r"""#compdef linux-updater
|
||||
|
||||
_linux_updater() {
|
||||
local context state state_descr line
|
||||
typeset -A opt_args
|
||||
|
||||
local -a common_args
|
||||
common_args=(
|
||||
'(-c --config)'{-c,--config}'[Path to JSON configuration file]:config file:_files -g "*.json"'
|
||||
'(-y --yes --non-interactive)'{-y,--yes,--non-interactive}'[Run without interactive confirmation prompts]'
|
||||
'--dry-run[Simulate execution without modifying system state]'
|
||||
'--no-remediation[Disable automatic remediation of failed health checks]'
|
||||
'--skip-preflight[Skip pre-flight health checks]'
|
||||
'--json[Output structured JSON results]'
|
||||
'--reboot[Automatically reboot the system after upgrade or if required]'
|
||||
'(-h --help)'{-h,--help}'[Show help message and exit]'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
'(-v --version)'{-v,--version}'[Show program version and exit]' \
|
||||
$common_args \
|
||||
'1: :->command' \
|
||||
'*:: :->args'
|
||||
|
||||
case $state in
|
||||
command)
|
||||
local -a commands
|
||||
commands=(
|
||||
'update:Inspect health, auto-remediate safe issues, and apply package updates'
|
||||
'check:Check system health and list available updates without making modifications'
|
||||
'release-upgrade:Perform a major distribution release upgrade with safety checks'
|
||||
'clean:Clean downloaded package cache and remove orphaned packages'
|
||||
'health:Run only the pre-flight health diagnostic checks'
|
||||
'completion:Generate shell autocompletion script (bash or zsh)'
|
||||
)
|
||||
_describe -t commands 'subcommand' commands
|
||||
;;
|
||||
args)
|
||||
case $line[1] in
|
||||
update)
|
||||
_arguments \
|
||||
$common_args \
|
||||
'--packages[Selectively update specified package(s)]:package: ' \
|
||||
'--exclude[Exclude package(s) or glob patterns from update]:exclude: ' \
|
||||
'--security[Apply only security-related updates]' \
|
||||
'--flatpak[Update Flatpak packages if available]'
|
||||
;;
|
||||
check)
|
||||
_arguments \
|
||||
$common_args
|
||||
;;
|
||||
release-upgrade)
|
||||
_arguments \
|
||||
$common_args \
|
||||
'(-t --target-release --releasever)'{-t,--target-release,--releasever}'[Specify target distribution version number/codename]:target release: '
|
||||
;;
|
||||
clean)
|
||||
_arguments \
|
||||
$common_args \
|
||||
'--all[Clean both package cache and autoremove unused dependencies]'
|
||||
;;
|
||||
health)
|
||||
_arguments \
|
||||
$common_args
|
||||
;;
|
||||
completion)
|
||||
local -a shells
|
||||
shells=('bash:Generate Bash completion script' 'zsh:Generate Zsh completion script')
|
||||
_describe -t shells 'shell' shells
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_linux_updater "$@"
|
||||
"""
|
||||
|
||||
|
||||
def get_bash_completion() -> str:
|
||||
"""Returns the Bash completion script."""
|
||||
return BASH_COMPLETION.strip() + "\n"
|
||||
|
||||
|
||||
def get_zsh_completion() -> str:
|
||||
"""Returns the Zsh completion function."""
|
||||
return ZSH_COMPLETION.strip() + "\n"
|
||||
@@ -340,6 +340,37 @@ class HealthChecker:
|
||||
)
|
||||
return results
|
||||
|
||||
def check_package_db(self) -> List[CheckResult]:
|
||||
results: List[CheckResult] = []
|
||||
try:
|
||||
res = self.manager.verify_db_consistency()
|
||||
if isinstance(res, (tuple, list)) and len(res) == 2:
|
||||
is_ok, msg = res
|
||||
else:
|
||||
is_ok, msg = True, "Package database is consistent."
|
||||
except Exception as e:
|
||||
is_ok, msg = False, f"Package database check failed: {e}"
|
||||
|
||||
if is_ok:
|
||||
results.append(
|
||||
CheckResult(
|
||||
name="package_db",
|
||||
status=CheckStatus.PASS,
|
||||
message=msg,
|
||||
)
|
||||
)
|
||||
else:
|
||||
results.append(
|
||||
CheckResult(
|
||||
name="package_db",
|
||||
status=CheckStatus.FAIL,
|
||||
message=msg,
|
||||
can_remediate=True,
|
||||
remediation_id="repair_package_db",
|
||||
)
|
||||
)
|
||||
return results
|
||||
|
||||
def run_all_checks(self) -> PreflightReport:
|
||||
all_results: List[CheckResult] = []
|
||||
all_results.extend(self.check_disk_space())
|
||||
@@ -347,6 +378,7 @@ class HealthChecker:
|
||||
all_results.extend(self.check_memory_and_oom())
|
||||
all_results.extend(self.check_power())
|
||||
all_results.extend(self.check_pending_reboot())
|
||||
all_results.extend(self.check_package_db())
|
||||
|
||||
has_failure = any(r.status == CheckStatus.FAIL for r in all_results)
|
||||
return PreflightReport(passed=not has_failure, results=all_results)
|
||||
@@ -14,7 +14,7 @@ class RemediationEngine:
|
||||
def can_remediate(self, check: CheckResult) -> bool:
|
||||
if not check.can_remediate:
|
||||
return False
|
||||
return check.remediation_id in {"clean_cache", "remove_stale_lock"}
|
||||
return check.remediation_id in {"clean_cache", "remove_stale_lock", "repair_package_db"}
|
||||
|
||||
def remediate(self, check: CheckResult) -> bool:
|
||||
if not self.can_remediate(check):
|
||||
@@ -24,9 +24,20 @@ class RemediationEngine:
|
||||
return self.clean_cache()
|
||||
elif check.remediation_id == "remove_stale_lock":
|
||||
return self.remove_stale_lock(check.message)
|
||||
elif check.remediation_id == "repair_package_db":
|
||||
return self.repair_package_db()
|
||||
|
||||
return False
|
||||
|
||||
def repair_package_db(self) -> bool:
|
||||
try:
|
||||
res = self.manager.repair_db()
|
||||
if hasattr(res, "success"):
|
||||
return bool(res.success)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def clean_cache(self) -> bool:
|
||||
try:
|
||||
res = self.manager.clean_cache()
|
||||
|
||||
Reference in new issue
Block a user