From d60c38a32d649b19ecc3e9613e612818d912ac06 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 30 Oct 2025 12:21:58 +0100 Subject: [PATCH] Add and use cleanup_lxc function for system cleanup 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. --- ct/debian.sh | 11 +++++----- install/debian-install.sh | 19 ++++++----------- misc/core.func | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/ct/debian.sh b/ct/debian.sh index 78010dc3d..198a0bf01 100644 --- a/ct/debian.sh +++ b/ct/debian.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func) -# Copyright (c) 2021-2025 tteck -# Author: tteck (tteckster) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: MickLesk (CanbiZ) # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE -# Source: https://www.debian.org/ +# Source: APP="Debian" var_tags="${var_tags:-}" @@ -30,9 +30,10 @@ function update_script() { exit fi msg_info "Updating $APP LXC" - $STD apt-get update - $STD apt-get -y upgrade + $STD apt update + $STD apt upgrade -y msg_ok "Updated $APP LXC" + cleanup_lxc exit } diff --git a/install/debian-install.sh b/install/debian-install.sh index b5864b09c..aedf72fc0 100644 --- a/install/debian-install.sh +++ b/install/debian-install.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash # Copyright (c) 2021-2025 community-scripts ORG -# Author: Test Suite for tools.func -# License: MIT -# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE -# Purpose: Run comprehensive test suite for all setup_* functions from tools.func +# Author: MickLesk (CanbiZ) +# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE +# Source: source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" color @@ -18,14 +17,10 @@ msg_info "Installing Base Dependencies" $STD apt-get install -y curl wget ca-certificates msg_ok "Installed Base Dependencies" -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) -msg_ok "Test suite completed" +# 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) +# msg_ok "Test suite completed" motd_ssh customize - -msg_info "Cleaning up" -$STD apt-get -y autoremove -$STD apt-get -y autoclean -msg_ok "Cleaned" +cleanup_lxc diff --git a/misc/core.func b/misc/core.func index c2c1ea0c6..333b0bac2 100644 --- a/misc/core.func +++ b/misc/core.func @@ -407,6 +407,51 @@ function msg_debug() { 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() { msg_info "Checking for active swap"