11#! /bin/bash
22
33#  Debian and Ubuntu Server Hardening Interactive Script
4- #  Version: 0.72  | 2025-10-20 
4+ #  Version: 0.73  | 2025-10-22 
55#  Changelog:
6+ #  - v0.73: Revised/improved logic in .bashrc for memory and system updates.
67#  - v0.72: Added configure_custom_bashrc() function that creates and installs a feature-rich .bashrc file during user creation.
78#  - v0.71: Simplify test backup function to work reliably with Hetzner storagebox
89#  - v0.70.1: Fix SSH port validation and improve firewall handling during SSH port transitions.
7677set  -euo pipefail
7778
7879#  --- Update Configuration ---
79- CURRENT_VERSION=" 0.72 " 
80+ CURRENT_VERSION=" 0.73 " 
8081SCRIPT_URL=" https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh" 
8182CHECKSUM_URL=" ${SCRIPT_URL} .sha256" 
8283
@@ -227,7 +228,7 @@ print_header() {
227228    printf  ' %s\n' " ${CYAN} ╔═════════════════════════════════════════════════════════════════╗${NC} " 
228229    printf  ' %s\n' " ${CYAN} ║                                                                 ║${NC} " 
229230    printf  ' %s\n' " ${CYAN} ║       DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT           ║${NC} " 
230-     printf  ' %s\n' " ${CYAN} ║                      v0.72  | 2025-10-20                          ║${NC} " 
231+     printf  ' %s\n' " ${CYAN} ║                      v0.73  | 2025-10-22                          ║${NC} " 
231232    printf  ' %s\n' " ${CYAN} ║                                                                 ║${NC} " 
232233    printf  ' %s\n' " ${CYAN} ╚═════════════════════════════════════════════════════════════════╝${NC} " 
233234    printf  ' \n' 
@@ -1410,7 +1411,13 @@ sysinfo() {
14101411    printf "${CYAN}%-15s${RESET} %s\n" "Uptime:" "$(uptime -p 2>/dev/null || uptime | sed 's/.*up //' | sed 's/,.*//')" 
14111412    printf "${CYAN}%-15s${RESET} %s\n" "Server time:" "$(date '+%Y-%m-%d %H:%M:%S %Z')" 
14121413    printf "${CYAN}%-15s${RESET} %s\n" "CPU:" "$cpu_info" 
1413-     printf "${CYAN}%-15s${RESET} %s\n" "Memory:" "$(free -h | awk '/^Mem:/ {printf "%s / %s (%d%% used)", $3, $2, $3/$2*100}')" 
1414+     printf "${CYAN}%-15s${RESET} " "Memory:" 
1415+     free -m | awk '/Mem/ { 
1416+         used = $3; total = $2; percent = int((used/total)*100); 
1417+         if (used >= 1024) { used_fmt = sprintf("%.1fGi", used/1024); } else { used_fmt = sprintf("%dMi", used); } 
1418+         if (total >= 1024) { total_fmt = sprintf("%.1fGi", total/1024); } else { total_fmt = sprintf("%dMi", total); } 
1419+         printf "%s / %s (%d%% used)\n", used_fmt, total_fmt, percent; 
1420+     }' 
14141421    printf "${CYAN}%-15s${RESET} %s\n" "Disk (/):" "$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 " used)"}')" 
14151422
14161423    # --- Reboot Status --- 
@@ -1425,14 +1432,25 @@ sysinfo() {
14251432        local total security 
14261433        local upgradable_all upgradable_list security_list 
14271434        if [ -x /usr/lib/update-notifier/apt-check ]; then 
1428-             IFS=';' read -r total security < <(/usr/lib/update-notifier/apt-check 2>/dev/null) 
1429-         elif [ -r /var/lib/update-notifier/updates-available ]; then 
1430-             total=$(awk '/packages can be updated/ {print $1}' /var/lib/update-notifier/updates-available) 
1431-             security=$(awk '/security updates/ {print $1}' /var/lib/update-notifier/updates-available) 
1432-         else 
1435+             local apt_check_output 
1436+             apt_check_output=$(/usr/lib/update-notifier/apt-check 2>/dev/null) 
1437+             if [ -n "$apt_check_output" ]; then 
1438+                 total="${apt_check_output%%;*}" 
1439+                 security="${apt_check_output##*;}" 
1440+             fi 
1441+         fi 
1442+         # Fallback if apt-check didn't provide values 
1443+         if [ -z "$total" ] && [ -r /var/lib/update-notifier/updates-available ]; then 
1444+             total=$(awk '/[0-9]+ (update|package)s? can be (updated|applied|installed)/ {print $1; exit}' /var/lib/update-notifier/updates-available 2>/dev/null) 
1445+             security=$(awk '/[0-9]+ (update|package)s? .*security/ {print $1; exit}' /var/lib/update-notifier/updates-available 2>/dev/null) 
1446+         fi 
1447+         # Final fallback 
1448+         if [ -z "$total" ]; then 
14331449            total=$(apt list --upgradable 2>/dev/null | grep -c upgradable) 
14341450            security=$(apt list --upgradable 2>/dev/null | grep -ci security) 
14351451        fi 
1452+         total="${total:-0}" 
1453+         security="${security:-0}" 
14361454
14371455        if [ -n "$total" ] && [ "$total" -gt 0 ] 2>/dev/null; then 
14381456            printf "${CYAN}%-15s${RESET} " "Updates:" 
0 commit comments