mirror of
https://github.com/buildplan/du_setup.git
synced 2025-12-29 16:14:59 +00:00
Merge pull request #72 from buildplan/improve_builtin_bashrc
improved memory and system updates logic in .bashrc
This commit is contained in:
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
**Version:** v0.72
|
**Version:** v0.73
|
||||||
|
|
||||||
**Last Updated:** 2025-10-20
|
**Last Updated:** 2025-10-22
|
||||||
|
|
||||||
**Compatible With:**
|
**Compatible With:**
|
||||||
|
|
||||||
@@ -87,12 +87,12 @@ sha256sum du_setup.sh
|
|||||||
|
|
||||||
Compare the output hash to the one below. They must match exactly.
|
Compare the output hash to the one below. They must match exactly.
|
||||||
|
|
||||||
`e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18`
|
`63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e`
|
||||||
|
|
||||||
Or echo the hash to check, it should output: `du_setup.sh: OK`
|
Or echo the hash to check, it should output: `du_setup.sh: OK`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18 du_setup.sh | sha256sum --check
|
echo 63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e du_setup.sh | sha256sum --check
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Run the Script
|
### 3. Run the Script
|
||||||
|
|||||||
36
du_setup.sh
36
du_setup.sh
@@ -1,8 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Debian and Ubuntu Server Hardening Interactive Script
|
# Debian and Ubuntu Server Hardening Interactive Script
|
||||||
# Version: 0.72 | 2025-10-20
|
# Version: 0.73 | 2025-10-22
|
||||||
# Changelog:
|
# Changelog:
|
||||||
|
# - v0.73: Revised/improved logic in .bashrc for memory and system updates.
|
||||||
# - v0.72: Added configure_custom_bashrc() function that creates and installs a feature-rich .bashrc file during user creation.
|
# - v0.72: Added configure_custom_bashrc() function that creates and installs a feature-rich .bashrc file during user creation.
|
||||||
# - v0.71: Simplify test backup function to work reliably with Hetzner storagebox
|
# - v0.71: Simplify test backup function to work reliably with Hetzner storagebox
|
||||||
# - v0.70.1: Fix SSH port validation and improve firewall handling during SSH port transitions.
|
# - v0.70.1: Fix SSH port validation and improve firewall handling during SSH port transitions.
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# --- Update Configuration ---
|
# --- Update Configuration ---
|
||||||
CURRENT_VERSION="0.72"
|
CURRENT_VERSION="0.73"
|
||||||
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
|
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
|
||||||
CHECKSUM_URL="${SCRIPT_URL}.sha256"
|
CHECKSUM_URL="${SCRIPT_URL}.sha256"
|
||||||
|
|
||||||
@@ -227,7 +228,7 @@ print_header() {
|
|||||||
printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}"
|
printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}"
|
||||||
printf '%s\n' "${CYAN}║ ║${NC}"
|
printf '%s\n' "${CYAN}║ ║${NC}"
|
||||||
printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}"
|
printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}"
|
||||||
printf '%s\n' "${CYAN}║ v0.72 | 2025-10-20 ║${NC}"
|
printf '%s\n' "${CYAN}║ v0.73 | 2025-10-22 ║${NC}"
|
||||||
printf '%s\n' "${CYAN}║ ║${NC}"
|
printf '%s\n' "${CYAN}║ ║${NC}"
|
||||||
printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}"
|
printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}"
|
||||||
printf '\n'
|
printf '\n'
|
||||||
@@ -1410,7 +1411,13 @@ sysinfo() {
|
|||||||
printf "${CYAN}%-15s${RESET} %s\n" "Uptime:" "$(uptime -p 2>/dev/null || uptime | sed 's/.*up //' | sed 's/,.*//')"
|
printf "${CYAN}%-15s${RESET} %s\n" "Uptime:" "$(uptime -p 2>/dev/null || uptime | sed 's/.*up //' | sed 's/,.*//')"
|
||||||
printf "${CYAN}%-15s${RESET} %s\n" "Server time:" "$(date '+%Y-%m-%d %H:%M:%S %Z')"
|
printf "${CYAN}%-15s${RESET} %s\n" "Server time:" "$(date '+%Y-%m-%d %H:%M:%S %Z')"
|
||||||
printf "${CYAN}%-15s${RESET} %s\n" "CPU:" "$cpu_info"
|
printf "${CYAN}%-15s${RESET} %s\n" "CPU:" "$cpu_info"
|
||||||
printf "${CYAN}%-15s${RESET} %s\n" "Memory:" "$(free -h | awk '/^Mem:/ {printf "%s / %s (%d%% used)", $3, $2, $3/$2*100}')"
|
printf "${CYAN}%-15s${RESET} " "Memory:"
|
||||||
|
free -m | awk '/Mem/ {
|
||||||
|
used = $3; total = $2; percent = int((used/total)*100);
|
||||||
|
if (used >= 1024) { used_fmt = sprintf("%.1fGi", used/1024); } else { used_fmt = sprintf("%dMi", used); }
|
||||||
|
if (total >= 1024) { total_fmt = sprintf("%.1fGi", total/1024); } else { total_fmt = sprintf("%dMi", total); }
|
||||||
|
printf "%s / %s (%d%% used)\n", used_fmt, total_fmt, percent;
|
||||||
|
}'
|
||||||
printf "${CYAN}%-15s${RESET} %s\n" "Disk (/):" "$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 " used)"}')"
|
printf "${CYAN}%-15s${RESET} %s\n" "Disk (/):" "$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 " used)"}')"
|
||||||
|
|
||||||
# --- Reboot Status ---
|
# --- Reboot Status ---
|
||||||
@@ -1425,14 +1432,25 @@ sysinfo() {
|
|||||||
local total security
|
local total security
|
||||||
local upgradable_all upgradable_list security_list
|
local upgradable_all upgradable_list security_list
|
||||||
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
||||||
IFS=';' read -r total security < <(/usr/lib/update-notifier/apt-check 2>/dev/null)
|
local apt_check_output
|
||||||
elif [ -r /var/lib/update-notifier/updates-available ]; then
|
apt_check_output=$(/usr/lib/update-notifier/apt-check 2>/dev/null)
|
||||||
total=$(awk '/packages can be updated/ {print $1}' /var/lib/update-notifier/updates-available)
|
if [ -n "$apt_check_output" ]; then
|
||||||
security=$(awk '/security updates/ {print $1}' /var/lib/update-notifier/updates-available)
|
total="${apt_check_output%%;*}"
|
||||||
else
|
security="${apt_check_output##*;}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# Fallback if apt-check didn't provide values
|
||||||
|
if [ -z "$total" ] && [ -r /var/lib/update-notifier/updates-available ]; then
|
||||||
|
total=$(awk '/[0-9]+ (update|package)s? can be (updated|applied|installed)/ {print $1; exit}' /var/lib/update-notifier/updates-available 2>/dev/null)
|
||||||
|
security=$(awk '/[0-9]+ (update|package)s? .*security/ {print $1; exit}' /var/lib/update-notifier/updates-available 2>/dev/null)
|
||||||
|
fi
|
||||||
|
# Final fallback
|
||||||
|
if [ -z "$total" ]; then
|
||||||
total=$(apt list --upgradable 2>/dev/null | grep -c upgradable)
|
total=$(apt list --upgradable 2>/dev/null | grep -c upgradable)
|
||||||
security=$(apt list --upgradable 2>/dev/null | grep -ci security)
|
security=$(apt list --upgradable 2>/dev/null | grep -ci security)
|
||||||
fi
|
fi
|
||||||
|
total="${total:-0}"
|
||||||
|
security="${security:-0}"
|
||||||
|
|
||||||
if [ -n "$total" ] && [ "$total" -gt 0 ] 2>/dev/null; then
|
if [ -n "$total" ] && [ "$total" -gt 0 ] 2>/dev/null; then
|
||||||
printf "${CYAN}%-15s${RESET} " "Updates:"
|
printf "${CYAN}%-15s${RESET} " "Updates:"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
e402db17ee1738ec96b2f4e2bcd1d1756df8b6a7e49de0953681a49f7f42fe18 du_setup.sh
|
63695b2b18219e9fed579ae2545ed413c04fbf024cd181d72139409ba1811c1e du_setup.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user