Add and use cleanup_lxc function for system cleanup
Some checks failed
Bump build.func Revision / bump-revision (push) Has been cancelled

Introduced a new cleanup_lxc function in core.func to standardize and enhance system cleanup across scripts. Updated debian.sh and debian-install.sh to use this function instead of inline cleanup commands, improving maintainability and consistency. Also updated author and copyright information.
This commit is contained in:
CanbiZ 2025-10-30 12:21:58 +01:00
parent 67d5281add
commit d60c38a32d
3 changed files with 58 additions and 17 deletions

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func) source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func)
# Copyright (c) 2021-2025 tteck # Copyright (c) 2021-2025 community-scripts ORG
# Author: tteck (tteckster) # Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://www.debian.org/ # Source:
APP="Debian" APP="Debian"
var_tags="${var_tags:-}" var_tags="${var_tags:-}"
@ -30,9 +30,10 @@ function update_script() {
exit exit
fi fi
msg_info "Updating $APP LXC" msg_info "Updating $APP LXC"
$STD apt-get update $STD apt update
$STD apt-get -y upgrade $STD apt upgrade -y
msg_ok "Updated $APP LXC" msg_ok "Updated $APP LXC"
cleanup_lxc
exit exit
} }

View File

@ -1,10 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: Test Suite for tools.func # Author: MickLesk (CanbiZ)
# License: MIT # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # Source:
# Purpose: Run comprehensive test suite for all setup_* functions from tools.func
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color color
@ -18,14 +17,10 @@ msg_info "Installing Base Dependencies"
$STD apt-get install -y curl wget ca-certificates $STD apt-get install -y curl wget ca-certificates
msg_ok "Installed Base Dependencies" msg_ok "Installed Base Dependencies"
msg_info "Downloading and executing tools.func test suite" # msg_info "Downloading and executing tools.func test suite"
bash <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/test-tools-func.sh) # bash <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/test-tools-func.sh)
msg_ok "Test suite completed" # msg_ok "Test suite completed"
motd_ssh motd_ssh
customize customize
cleanup_lxc
msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"

View File

@ -407,6 +407,51 @@ function msg_debug() {
fi fi
} }
cleanup_lxc() {
msg_info "Cleaning up"
if is_alpine; then
$STD apk cache clean || true
rm -rf /var/cache/apk/*
else
$STD apt -y autoremove || true
$STD apt -y autoclean || true
$STD apt -y clean || true
fi
rm -rf /tmp/* /var/tmp/*
# Remove temp files created by mktemp/tempfile
find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true
find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true
find /var/log -type f -exec truncate -s 0 {} +
# Python pip
if command -v pip &>/dev/null; then pip cache purge || true; fi
# Python uv
if command -v uv &>/dev/null; then uv cache clear || true; fi
# Node.js npm
if command -v npm &>/dev/null; then npm cache clean --force || true; fi
# Node.js yarn
if command -v yarn &>/dev/null; then yarn cache clean || true; fi
# Node.js pnpm
if command -v pnpm &>/dev/null; then pnpm store prune || true; fi
# Go
if command -v go &>/dev/null; then go clean -cache -modcache || true; fi
# Rust cargo
if command -v cargo &>/dev/null; then cargo clean || true; fi
# Ruby gem
if command -v gem &>/dev/null; then gem cleanup || true; fi
# Composer (PHP)
if command -v composer &>/dev/null; then composer clear-cache || true; fi
if command -v journalctl &>/dev/null; then
journalctl --rotate
journalctl --vacuum-time=10m
fi
msg_ok "Cleaned"
}
check_or_create_swap() { check_or_create_swap() {
msg_info "Checking for active swap" msg_info "Checking for active swap"