From 67f309f32ef62e6ada8069e5af2ce5e7592cd9eb Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sun, 6 Jul 2025 16:30:16 +0200 Subject: [PATCH] Update post-install --- scripts/post_install/auto_post_install.sh | 15 ++- .../post_install/customizable_post_install.sh | 109 ++++++++++++++++++ 2 files changed, 119 insertions(+), 5 deletions(-) diff --git a/scripts/post_install/auto_post_install.sh b/scripts/post_install/auto_post_install.sh index 86158fb..5d2c00e 100644 --- a/scripts/post_install/auto_post_install.sh +++ b/scripts/post_install/auto_post_install.sh @@ -717,9 +717,9 @@ install_log2ram_auto() { SYSTEM_DISK=${SYSTEM_DISK:-sda} if [[ "$SYSTEM_DISK" == nvme* || "$(cat /sys/block/$SYSTEM_DISK/queue/rotational 2>/dev/null)" == "0" ]]; then - msg_ok "$(translate "System disk ($SYSTEM_DISK) is SSD or M.2. Proceeding with log2ram setup.")" + msg_ok "$(translate "System disk ($SYSTEM_DISK) is SSD or M.2. Proceeding with Log2RAM setup.")" else - msg_warn "$(translate "System disk ($SYSTEM_DISK) is not SSD/M.2. Skipping log2ram installation.")" + msg_warn "$(translate "System disk ($SYSTEM_DISK) is not SSD/M.2. Skipping Log2RAM installation.")" return 0 fi @@ -737,14 +737,19 @@ install_log2ram_auto() { msg_info "$(translate "Installing log2ram from GitHub...")" + if ! command -v git >/dev/null 2>&1; then + apt-get update -qq >/dev/null 2>&1 + apt-get install -y git >/dev/null 2>&1 + fi + git clone https://github.com/azlux/log2ram.git /tmp/log2ram >/dev/null 2>>/tmp/log2ram_install.log cd /tmp/log2ram || return 1 bash install.sh >>/tmp/log2ram_install.log 2>&1 if [[ -f /etc/log2ram.conf ]] && systemctl list-units --all | grep -q log2ram; then - msg_ok "$(translate "log2ram installed successfully")" + msg_ok "$(translate "Log2RAM installed successfully")" else - msg_error "$(translate "Failed to install log2ram. See /tmp/log2ram_install.log")" + msg_error "$(translate "Failed to install Log2RAM. See /tmp/log2ram_install.log")" return 1 fi @@ -763,7 +768,7 @@ install_log2ram_auto() { CRON_HOURS=6 fi - msg_ok "$(translate "Detected RAM:") $RAM_SIZE_GB GB — $(translate "log2ram size set to:") $LOG2RAM_SIZE" + msg_ok "$(translate "Detected RAM:") $RAM_SIZE_GB GB — $(translate "Log2RAM size set to:") $LOG2RAM_SIZE" sed -i "s/^SIZE=.*/SIZE=$LOG2RAM_SIZE/" /etc/log2ram.conf rm -f /etc/cron.hourly/log2ram diff --git a/scripts/post_install/customizable_post_install.sh b/scripts/post_install/customizable_post_install.sh index 58a301e..7373a60 100644 --- a/scripts/post_install/customizable_post_install.sh +++ b/scripts/post_install/customizable_post_install.sh @@ -2834,6 +2834,113 @@ update_pve_appliance_manager() { + + +configure_log2ram() { + + msg_info2 "$(translate "Preparing Log2RAM configuration")" + sleep 2 + + RAM_SIZE_GB=$(free -g | awk '/^Mem:/{print $2}') + [[ -z "$RAM_SIZE_GB" || "$RAM_SIZE_GB" -eq 0 ]] && RAM_SIZE_GB=4 + + if (( RAM_SIZE_GB <= 8 )); then + DEFAULT_SIZE="128" + DEFAULT_HOURS="1" + elif (( RAM_SIZE_GB <= 16 )); then + DEFAULT_SIZE="256" + DEFAULT_HOURS="3" + else + DEFAULT_SIZE="512" + DEFAULT_HOURS="6" + fi + + + USER_SIZE=$(whiptail --title "Log2RAM" --inputbox "$(translate "Enter the maximum size (in MB) to allocate for /var/log in RAM (e.g. 128, 256, 512):")\n\n$(translate "Recommended for $RAM_SIZE_GB GB RAM:") ${DEFAULT_SIZE}M" 12 70 "$DEFAULT_SIZE" 3>&1 1>&2 2>&3) || return 0 + LOG2RAM_SIZE="${USER_SIZE}M" + + + CRON_HOURS=$(whiptail --title "Log2RAM" --radiolist "$(translate "Select the sync interval (in hours):")\n\n$(translate "Suggested interval: every $DEFAULT_HOURS hour(s)")" 15 70 5 \ + "1" "$(translate "Every hour")" OFF \ + "3" "$(translate "Every 3 hours")" OFF \ + "6" "$(translate "Every 6 hours")" OFF \ + "12" "$(translate "Every 12 hours")" OFF \ + 3>&1 1>&2 2>&3) || return 0 + + # Activar auto-sync si se pasa del 90% + if whiptail --title "Log2RAM" --yesno "$(translate "Enable auto-sync if /var/log exceeds 90% of its size?")" 10 60; then + ENABLE_AUTOSYNC=true + else + ENABLE_AUTOSYNC=false + fi + + # Instalación + msg_info "$(translate "Installing Log2RAM from GitHub...")" + rm -rf /tmp/log2ram + + # Ensure git is available + if ! command -v git >/dev/null 2>&1; then + msg_info "$(translate "Installing required package: git")" + apt-get update -qq >/dev/null 2>&1 + apt-get install -y git >/dev/null 2>&1 + fi + + git clone https://github.com/azlux/log2ram.git /tmp/log2ram >/dev/null 2>&1 + cd /tmp/log2ram || return 1 + bash install.sh >/dev/null 2>&1 + + if [[ -f /etc/log2ram.conf ]] && systemctl list-units --all | grep -q log2ram; then + msg_ok "$(translate "Log2RAM installed successfully")" + else + msg_error "$(translate "Failed to install Log2RAM.")" + return 1 + fi + + # Aplicar configuración + sed -i "s/^SIZE=.*/SIZE=$LOG2RAM_SIZE/" /etc/log2ram.conf + rm -f /etc/cron.hourly/log2ram + echo "0 */$CRON_HOURS * * * root /usr/sbin/log2ram write" > /etc/cron.d/log2ram + msg_ok "$(translate "Log2RAM write scheduled every") $CRON_HOURS $(translate "hour(s)")" + + # Auto-sync + if [[ "$ENABLE_AUTOSYNC" == true ]]; then + cat << 'EOF' > /usr/local/bin/log2ram-check.sh +#!/bin/bash +CONF_FILE="/etc/log2ram.conf" +LIMIT_KB=$(grep '^SIZE=' "$CONF_FILE" | cut -d'=' -f2 | tr -d 'M')000 +USED_KB=$(df /var/log --output=used | tail -1) +THRESHOLD=$(( LIMIT_KB * 90 / 100 )) +if (( USED_KB > THRESHOLD )); then + /usr/sbin/log2ram write +fi +EOF + chmod +x /usr/local/bin/log2ram-check.sh + echo "*/5 * * * * root /usr/local/bin/log2ram-check.sh" > /etc/cron.d/log2ram-auto-sync + msg_ok "$(translate "Auto-sync enabled when /var/log exceeds 90% of") $LOG2RAM_SIZE" + else + rm -f /usr/local/bin/log2ram-check.sh /etc/cron.d/log2ram-auto-sync + msg_info2 "$(translate "Auto-sync was not enabled")" + fi + + msg_success "$(translate "Log2RAM installation and configuration completed successfully.")" + + register_tool "log2ram" true +} + + + + + + + +# ========================================================== + + + + + + + # ========================================================== # Auxiliary help functions # ========================================================== @@ -3017,6 +3124,7 @@ main_menu() { "Optional|Add Proxmox testing repository|REPOTEST" "Optional|Enable High Availability services|ENABLE_HA" "Optional|Install Figurine|FIGURINE" + "Optional|Install and Log2RAM|LOG2RAM" ) IFS=$'\n' sorted_options=($(for option in "${options[@]}"; do @@ -3168,6 +3276,7 @@ done REPOTEST) add_repo_test ;; ENABLE_HA) enable_ha ;; FIGURINE) configure_figurine ;; + LOG2RAM) configure_log2ram ;; PVEAM) update_pve_appliance_manager ;; *) echo "Option $function_name not implemented yet" ;; esac