add help flag

This commit is contained in:
buildplan
2025-10-13 23:06:01 +01:00
parent 7412fcf229
commit 595d40622d

View File

@@ -121,18 +121,6 @@ SSH_SERVICE=""
ID="" # This will be populated from /etc/os-release ID="" # This will be populated from /etc/os-release
FAILED_SERVICES=() FAILED_SERVICES=()
# --- PARSE ARGUMENTS ---
while [[ $# -gt 0 ]]; do
case $1 in
--quiet) VERBOSE=false; shift ;;
--cleanup-preview) CLEANUP_PREVIEW=true; shift ;;
--cleanup-only) CLEANUP_ONLY=true; shift ;;
--skip-cleanup) SKIP_CLEANUP=true; shift ;;
-h|--help) show_usage ;;
*) shift ;;
esac
done
show_usage() { show_usage() {
cat << EOF cat << EOF
${CYAN}Debian/Ubuntu Server Setup and Hardening Script${NC} ${CYAN}Debian/Ubuntu Server Setup and Hardening Script${NC}
@@ -165,6 +153,18 @@ EOF
exit 0 exit 0
} }
# --- PARSE ARGUMENTS ---
while [[ $# -gt 0 ]]; do
case $1 in
--quiet) VERBOSE=false; shift ;;
--cleanup-preview) CLEANUP_PREVIEW=true; shift ;;
--cleanup-only) CLEANUP_ONLY=true; shift ;;
--skip-cleanup) SKIP_CLEANUP=true; shift ;;
-h|--help) show_usage ;;
*) shift ;;
esac
done
# --- LOGGING & PRINT FUNCTIONS --- # --- LOGGING & PRINT FUNCTIONS ---
log() { log() {
@@ -237,18 +237,18 @@ detect_environment() {
local PRODUCT="" local PRODUCT=""
local IS_CLOUD_VPS=false local IS_CLOUD_VPS=false
# Method 1: systemd-detect-virt (most reliable) # systemd-detect-virt
if command -v systemd-detect-virt &>/dev/null; then if command -v systemd-detect-virt &>/dev/null; then
VIRT_TYPE=$(systemd-detect-virt 2>/dev/null || echo "none") VIRT_TYPE=$(systemd-detect-virt 2>/dev/null || echo "none")
fi fi
# Method 2: dmidecode for hardware info (requires root) # dmidecode for hardware info
if command -v dmidecode &>/dev/null && [[ $(id -u) -eq 0 ]]; then if command -v dmidecode &>/dev/null && [[ $(id -u) -eq 0 ]]; then
MANUFACTURER=$(dmidecode -s system-manufacturer 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown") MANUFACTURER=$(dmidecode -s system-manufacturer 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")
PRODUCT=$(dmidecode -s system-product-name 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown") PRODUCT=$(dmidecode -s system-product-name 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")
fi fi
# Method 3: Check /sys/class/dmi/id/ (fallback, doesn't require dmidecode) # Check /sys/class/dmi/id/ (fallback, doesn't require dmidecode)
if [[ -z "$MANUFACTURER" || "$MANUFACTURER" == "unknown" ]]; then if [[ -z "$MANUFACTURER" || "$MANUFACTURER" == "unknown" ]]; then
if [[ -r /sys/class/dmi/id/sys_vendor ]]; then if [[ -r /sys/class/dmi/id/sys_vendor ]]; then
MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown") MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")
@@ -278,7 +278,6 @@ detect_environment() {
"equinix metal" "equinix metal"
"lightsail" "lightsail"
"scaleway" "scaleway"
# Major Cloud Platforms # Major Cloud Platforms
"amazon" "amazon"
"amazon ec2" "amazon ec2"
@@ -292,7 +291,6 @@ detect_environment() {
"alibaba" "alibaba"
"tencent" "tencent"
"rackspace" "rackspace"
# Virtualization indicating cloud VPS # Virtualization indicating cloud VPS
"droplet" "droplet"
"linodekvm" "linodekvm"