Update customizable_post_install.sh

This commit is contained in:
MacRimi 2025-05-02 19:11:17 +02:00
parent c8998c5ede
commit d05e01b0a1

View File

@ -2374,24 +2374,23 @@ add_repo_test() {
# Main menu function # Main menu function
main_menu() { main_menu() {
local HEADER=$(printf " %-56s %10s" "$(translate "Description")" "$(translate "Category")") local HEADER=$(printf " %-56s %10s" "$(translate "Description")" "Category")
# Define category order declare -A category_order=(
declare -A category_order ["Basic Settings"]=1
category_order["Basic Settings"]=1 ["System"]=2
category_order["System"]=2 ["Hardware"]=3
category_order["Hardware"]=3 ["Virtualization"]=4
category_order["Virtualization"]=4 ["Network"]=5
category_order["Network"]=5 ["Storage"]=6
category_order["Storage"]=6 ["Security"]=7
category_order["Security"]=7 ["Customization"]=8
category_order["Customization"]=8 ["Monitoring"]=9
category_order["Monitoring"]=9 ["Performance"]=10
category_order["Performance"]=10 ["Optional"]=11
category_order["Optional"]=11 )
# Define options with categories local options=(
local options=(
"Basic Settings|Update and upgrade system|APTUPGRADE" "Basic Settings|Update and upgrade system|APTUPGRADE"
"Basic Settings|Synchronize time automatically|TIMESYNC" "Basic Settings|Synchronize time automatically|TIMESYNC"
"Basic Settings|Skip downloading additional languages|NOAPTLANG" "Basic Settings|Skip downloading additional languages|NOAPTLANG"
@ -2427,241 +2426,124 @@ local options=(
"Optional|Add latest Ceph support|CEPH" "Optional|Add latest Ceph support|CEPH"
"Optional|Add Proxmox testing repository|REPOTEST" "Optional|Add Proxmox testing repository|REPOTEST"
"Optional|Enable High Availability services|ENABLE_HA" "Optional|Enable High Availability services|ENABLE_HA"
) )
IFS=$'\n' sorted_options=($(for option in "${options[@]}"; do
# Sort options based on category order
IFS=$'\n' sorted_options=($(for option in "${options[@]}"; do
IFS='|' read -r category description function_name <<< "$option" IFS='|' read -r category description function_name <<< "$option"
printf "%d|%s|%s|%s\n" "${category_order[$category]:-999}" "$category" "$description" "$function_name" printf "%d|%s|%s|%s\n" "${category_order[$category]:-999}" "$category" "$description" "$function_name"
done | sort -n | cut -d'|' -f2-)) done | sort -n | cut -d'|' -f2-))
unset IFS unset IFS
local max_desc_width=0 local total_width=65
local max_cat_width=0 local max_desc_width=50
local category_width=15
local category_position=$((total_width - category_width))
for option in "${sorted_options[@]}"; do local menu_items=()
local i=1
local previous_category=""
for option in "${sorted_options[@]}"; do
IFS='|' read -r category description function_name <<< "$option" IFS='|' read -r category description function_name <<< "$option"
translated_category=$(translate "$category") translated_description="$(translate "$description")"
cat_length=${#translated_category} # Cortar descripción si es muy larga
if [ "$cat_length" -gt "$max_cat_width" ]; then local max_cut=$((category_position - 3))
max_cat_width="$cat_length" [[ "$max_cut" -lt 10 ]] && max_cut=10
fi if [[ ${#translated_description} -gt $max_cut ]]; then
done translated_description="${translated_description:0:$((max_cut - 3))}..."
local total_width=65
for option in "${sorted_options[@]}"; do
IFS='|' read -r category description function_name <<< "$option"
translated_description=$(translate "$description")
desc_length=${#translated_description}
if [ "$desc_length" -gt "$max_desc_width" ]; then
max_desc_width="$desc_length"
fi
done
if [ "$max_desc_width" -gt 50 ]; then
max_desc_width=50
fi
local category_position=$((total_width - max_cat_width))
local menu_items=()
local i=1
local previous_category=""
for option in "${sorted_options[@]}"; do
IFS='|' read -r category description function_name <<< "$option"
translated_category=$(translate "$category")
translated_description=$(translate "$description")
local max_allowed_desc=$((category_position - 2))
if [ ${#translated_description} -gt "$max_allowed_desc" ]; then
translated_description="${translated_description:0:$((max_allowed_desc-3))}..."
fi fi
# Añadir separador si cambia de categoría y es la "Optional"
# Set OFF for todas las opciones if [[ "$category" != "$previous_category" && "$category" == "Optional" && -n "$previous_category" ]]; then
state="OFF"
# Add a separator before Optional category, but only once
if [ "$category" != "$previous_category" ] && [ "$category" = "Optional" ] && [ "$previous_category" != "" ]; then
menu_items+=("" "================================================================" "") menu_items+=("" "================================================================" "")
fi fi
local line="" # Construir línea alineada
line+="$translated_description" local line="$translated_description"
local spaces_needed=$((category_position - ${#translated_description}))
local current_length=${#line} for ((j = 0; j < spaces_needed; j++)); do
local spaces_needed=$((category_position - current_length))
for ((j=0; j<spaces_needed; j++)); do
line+=" " line+=" "
done done
line+="$category"
line+="$translated_category" menu_items+=("$i" "$line" "OFF")
i=$((i + 1))
menu_items+=("$i" "$line" "$state")
i=$((i+1))
previous_category="$category" previous_category="$category"
done done
cleanup
cleanup local selected_indices=$(whiptail --title "$(translate "ProxMenux Custom Script for Post-Installation")" \
local selected_indices=$(whiptail --title "$(translate "ProxMenux Custom Script for Post-Installation")" \
--checklist --separate-output \ --checklist --separate-output \
"\n$HEADER\n\n$(translate "Choose options to configure:")\n$(translate "Use [SPACE] to select/deselect and [ENTER] to confirm:")" \ "\n$HEADER\n\n$(translate "Choose options to configure:")\n$(translate "Use [SPACE] to select/deselect and [ENTER] to confirm:")" \
20 82 12 \ 20 82 12 \
"${menu_items[@]}" \ "${menu_items[@]}" \
3>&1 1>&2 2>&3) 3>&1 1>&2 2>&3)
# Permitir salir con ESC o cancelar
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "User cancelled. Exiting." echo "User cancelled. Exiting."
exit 0 exit 0
fi fi
# Continuar si hay selección
IFS=$'\n' read -d '' -r -a selected_options <<< "$selected_indices"
declare -A selected_functions
# Convert selected_indices to an array if [ -n "$selected_indices" ]; then
IFS=$'\n' read -d '' -r -a selected_options <<< "$selected_indices"
declare -A selected_functions
if [ -n "$selected_indices" ]; then
msg_title "$SCRIPT_TITLE" msg_title "$SCRIPT_TITLE"
for index in "${selected_options[@]}"; do
# Mark selected options and apply exclusion logic option=${sorted_options[$((index - 1))]}
for index in "${selected_options[@]}"; do
option=${sorted_options[$((index-1))]}
IFS='|' read -r category description function_name <<< "$option" IFS='|' read -r category description function_name <<< "$option"
selected_functions[$function_name]=1 selected_functions[$function_name]=1
# If FASTFETCH is selected, unmark MOTD # Lógica de exclusión
if [[ "$function_name" == "FASTFETCH" ]]; then [[ "$function_name" == "FASTFETCH" ]] && selected_functions[MOTD]=0
selected_functions[MOTD]=0 done
fi
done
# Process selected options for index in "${!sorted_options[@]}"; do
for index in "${!sorted_options[@]}"; do
option=${sorted_options[$index]} option=${sorted_options[$index]}
IFS='|' read -r category description function_name <<< "$option" IFS='|' read -r category description function_name <<< "$option"
if [[ ${selected_functions[$function_name]} -eq 1 ]]; then if [[ ${selected_functions[$function_name]} -eq 1 ]]; then
case $function_name in case $function_name in
APTUPGRADE) APTUPGRADE) apt_upgrade ;;
apt_upgrade TIMESYNC) configure_time_sync ;;
;; NOAPTLANG) skip_apt_languages ;;
TIMESYNC) UTILS) install_system_utils ;;
configure_time_sync JOURNALD) optimize_journald ;;
;; LOGROTATE) optimize_logrotate ;;
NOAPTLANG) LIMITS) increase_system_limits ;;
skip_apt_languages ENTROPY) configure_entropy ;;
;; MEMORYFIXES) optimize_memory_settings ;;
UTILS) KEXEC) enable_kexec ;;
install_system_utils KERNELPANIC) configure_kernel_panic ;;
;; KERNELHEADERS) install_kernel_headers ;;
JOURNALD) AMDFIXES) apply_amd_fixes ;;
optimize_journald GUESTAGENT) install_guest_agent ;;
;; VFIO_IOMMU) enable_vfio_iommu ;;
LOGROTATE) KSMTUNED) configure_ksmtuned ;;
optimize_logrotate APTIPV4) force_apt_ipv4 ;;
;; NET) apply_network_optimizations ;;
LIMITS) OPENVSWITCH) install_openvswitch ;;
increase_system_limits TCPFASTOPEN) enable_tcp_fast_open ;;
;; ZFSARC) optimize_zfs_arc ;;
ENTROPY) ZFSAUTOSNAPSHOT) install_zfs_auto_snapshot ;;
configure_entropy VZDUMP) optimize_vzdump ;;
;; DISABLERPC) disable_rpc ;;
MEMORYFIXES) FAIL2BAN) install_fail2ban ;;
optimize_memory_settings LYNIS) install_lynis ;;
;; BASHRC) customize_bashrc ;;
KEXEC) MOTD) setup_motd ;;
enable_kexec NOSUBBANNER) remove_subscription_banner ;;
;; OVHRTM) install_ovh_rtm ;;
KERNELPANIC) PIGZ) configure_pigz ;;
configure_kernel_panic FASTFETCH) configure_fastfetch ;;
;; CEPH) install_ceph ;;
KERNELHEADERS) REPOTEST) add_repo_test ;;
install_kernel_headers ENABLE_HA) enable_ha ;;
;; *) echo "Option $function_name not implemented yet" ;;
AMDFIXES)
apply_amd_fixes
;;
GUESTAGENT)
install_guest_agent
;;
VFIO_IOMMU)
enable_vfio_iommu
;;
KSMTUNED)
configure_ksmtuned
;;
APTIPV4)
force_apt_ipv4
;;
NET)
apply_network_optimizations
;;
OPENVSWITCH)
install_openvswitch
;;
TCPFASTOPEN)
enable_tcp_fast_open
;;
ZFSARC)
optimize_zfs_arc
;;
ZFSAUTOSNAPSHOT)
install_zfs_auto_snapshot
;;
VZDUMP)
optimize_vzdump
;;
DISABLERPC)
disable_rpc
;;
FAIL2BAN)
install_fail2ban
;;
LYNIS)
install_lynis
;;
BASHRC)
customize_bashrc
;;
MOTD)
setup_motd
;;
NOSUBBANNER)
remove_subscription_banner
;;
OVHRTM)
install_ovh_rtm
;;
PIGZ)
configure_pigz
;;
FASTFETCH)
configure_fastfetch
;;
CEPH)
install_ceph
;;
REPOTEST)
add_repo_test
;;
ENABLE_HA)
enable_ha
;;
*)
echo "Option $function_name not implemented yet"
;;
esac esac
fi fi
done done
@ -2670,6 +2552,8 @@ for index in "${!sorted_options[@]}"; do
if [ "$NECESSARY_REBOOT" -eq 1 ]; then if [ "$NECESSARY_REBOOT" -eq 1 ]; then
whiptail --title "Reboot Required" --yesno "$(translate "Some changes require a reboot to take effect. Do you want to restart now?")" 10 60 whiptail --title "Reboot Required" --yesno "$(translate "Some changes require a reboot to take effect. Do you want to restart now?")" 10 60
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then