Expand cleanup_lxc to support more distros

The cleanup_lxc function now supports package manager cleanup for Fedora, Rocky, AlmaLinux, CentOS (dnf/yum), openSUSE (zypper), and Gentoo (emerge), in addition to Alpine and Debian/Ubuntu. All package manager and language tool cleanup commands now suppress error output for robustness. JSON files were reformatted for consistent indentation.
This commit is contained in:
CanbiZ 2025-12-04 14:55:00 +01:00
parent 3971eb49c7
commit 8aecfce5a3
12 changed files with 411 additions and 371 deletions

View File

@ -1,7 +1,9 @@
{ {
"name": "AlmaLinux", "name": "AlmaLinux",
"slug": "almalinux", "slug": "almalinux",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Alpine Linux", "name": "Alpine Linux",
"slug": "alpine", "slug": "alpine",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "CentOS Stream", "name": "CentOS Stream",
"slug": "centos", "slug": "centos",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Debian", "name": "Debian",
"slug": "debian", "slug": "debian",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Devuan", "name": "Devuan",
"slug": "devuan", "slug": "devuan",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Fedora", "name": "Fedora",
"slug": "fedora", "slug": "fedora",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Gentoo", "name": "Gentoo",
"slug": "gentoo", "slug": "gentoo",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "openEuler", "name": "openEuler",
"slug": "openeuler", "slug": "openeuler",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "openSUSE", "name": "openSUSE",
"slug": "opensuse", "slug": "opensuse",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Rocky Linux", "name": "Rocky Linux",
"slug": "rockylinux", "slug": "rockylinux",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -1,7 +1,9 @@
{ {
"name": "Ubuntu", "name": "Ubuntu",
"slug": "ubuntu", "slug": "ubuntu",
"categories": [0], "categories": [
0
],
"date_created": "2025-12-04", "date_created": "2025-12-04",
"type": "ct", "type": "ct",
"updateable": true, "updateable": true,

View File

@ -787,7 +787,8 @@ is_verbose_mode() {
# cleanup_lxc() # cleanup_lxc()
# #
# - Comprehensive cleanup of package managers, caches, and logs # - Comprehensive cleanup of package managers, caches, and logs
# - Supports Alpine (apk), Debian/Ubuntu (apt), and language package managers # - Supports Alpine (apk), Debian/Ubuntu (apt), Fedora/Rocky/CentOS (dnf/yum),
# openSUSE (zypper), Gentoo (emerge), and language package managers
# - Cleans: Python (pip/uv), Node.js (npm/yarn/pnpm), Go, Rust, Ruby, PHP # - Cleans: Python (pip/uv), Node.js (npm/yarn/pnpm), Go, Rust, Ruby, PHP
# - Truncates log files and vacuums systemd journal # - Truncates log files and vacuums systemd journal
# - Run at end of container creation to minimize disk usage # - Run at end of container creation to minimize disk usage
@ -795,13 +796,30 @@ is_verbose_mode() {
cleanup_lxc() { cleanup_lxc() {
msg_info "Cleaning up" msg_info "Cleaning up"
# OS-specific package manager cleanup
if is_alpine; then if is_alpine; then
$STD apk cache clean || true $STD apk cache clean 2>/dev/null || true
rm -rf /var/cache/apk/* rm -rf /var/cache/apk/*
else elif command -v apt &>/dev/null; then
$STD apt -y autoremove || true # Debian/Ubuntu/Devuan
$STD apt -y autoclean || true $STD apt -y autoremove 2>/dev/null || true
$STD apt -y clean || true $STD apt -y autoclean 2>/dev/null || true
$STD apt -y clean 2>/dev/null || true
elif command -v dnf &>/dev/null; then
# Fedora/Rocky/AlmaLinux/CentOS 8+
$STD dnf clean all 2>/dev/null || true
$STD dnf autoremove -y 2>/dev/null || true
elif command -v yum &>/dev/null; then
# CentOS 7/older RHEL
$STD yum clean all 2>/dev/null || true
elif command -v zypper &>/dev/null; then
# openSUSE
$STD zypper clean --all 2>/dev/null || true
elif command -v emerge &>/dev/null; then
# Gentoo
$STD emerge --quiet --depclean 2>/dev/null || true
$STD eclean-dist -d 2>/dev/null || true
$STD eclean-pkg -d 2>/dev/null || true
fi fi
# Clear temp artifacts (keep sockets/FIFOs; ignore errors) # Clear temp artifacts (keep sockets/FIFOs; ignore errors)
@ -815,22 +833,22 @@ cleanup_lxc() {
fi fi
# Node.js npm # Node.js npm
if command -v npm &>/dev/null; then $STD npm cache clean --force || true; fi if command -v npm &>/dev/null; then $STD npm cache clean --force 2>/dev/null || true; fi
# Node.js yarn # Node.js yarn
if command -v yarn &>/dev/null; then $STD yarn cache clean || true; fi if command -v yarn &>/dev/null; then $STD yarn cache clean 2>/dev/null || true; fi
# Node.js pnpm # Node.js pnpm
if command -v pnpm &>/dev/null; then $STD pnpm store prune || true; fi if command -v pnpm &>/dev/null; then $STD pnpm store prune 2>/dev/null || true; fi
# Go # Go
if command -v go &>/dev/null; then $STD go clean -cache -modcache || true; fi if command -v go &>/dev/null; then $STD go clean -cache -modcache 2>/dev/null || true; fi
# Rust cargo # Rust cargo
if command -v cargo &>/dev/null; then $STD cargo clean || true; fi if command -v cargo &>/dev/null; then $STD cargo clean 2>/dev/null || true; fi
# Ruby gem # Ruby gem
if command -v gem &>/dev/null; then $STD gem cleanup || true; fi if command -v gem &>/dev/null; then $STD gem cleanup 2>/dev/null || true; fi
# Composer (PHP) # Composer (PHP)
if command -v composer &>/dev/null; then $STD composer clear-cache || true; fi if command -v composer &>/dev/null; then $STD composer clear-cache 2>/dev/null || true; fi
if command -v journalctl &>/dev/null; then if command -v journalctl &>/dev/null; then
$STD journalctl --vacuum-time=10m || true $STD journalctl --vacuum-time=10m 2>/dev/null || true
fi fi
msg_ok "Cleaned" msg_ok "Cleaned"
} }