Skip to content

Commit 103abb8

Browse files
authored
Merge pull request #72 from buildplan/improve_builtin_bashrc
improved memory and system updates logic in .bashrc
2 parents a0d0229 + 677e2ff commit 103abb8

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
-----
99

10-
**Version:** v0.72
10+
**Version:** v0.73
1111

12-
**Last Updated:** 2025-10-20
12+
**Last Updated:** 2025-10-22
1313

1414
**Compatible With:**
1515

@@ -87,12 +87,12 @@ sha256sum du_setup.sh
8787

8888
Compare the output hash to the one below. They must match exactly.
8989

90-
`e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18`
90+
`63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e`
9191

9292
Or echo the hash to check, it should output: `du_setup.sh: OK`
9393

9494
```bash
95-
echo e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18 du_setup.sh | sha256sum --check
95+
echo 63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e du_setup.sh | sha256sum --check
9696
```
9797

9898
### 3. Run the Script

du_setup.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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.
@@ -76,7 +77,7 @@
7677
set -euo pipefail
7778

7879
# --- Update Configuration ---
79-
CURRENT_VERSION="0.72"
80+
CURRENT_VERSION="0.73"
8081
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
8182
CHECKSUM_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:"

du_setup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18 du_setup.sh
1+
63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e du_setup.sh

0 commit comments

Comments
 (0)