From f1c184a234a867697f80c92a7f03774be4224f0d Mon Sep 17 00:00:00 2001 From: SechPoint Date: Thu, 12 Mar 2026 09:25:51 +0000 Subject: [PATCH] update --- pre-deployment-test.sh | 54 +++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/pre-deployment-test.sh b/pre-deployment-test.sh index c6fe3bd..cf6e061 100644 --- a/pre-deployment-test.sh +++ b/pre-deployment-test.sh @@ -17,19 +17,24 @@ APP_PORT=${APP_PORT:-8080} # --- 2. SUDO & SYSTEM CHECK --- echo -e "\n${YELLOW}[1/4] Checking Sudo & OS Status...${NC}" -if sudo -n true 2>/dev/null; then - echo -e "${GREEN}[PASS]${NC} Sudo is active/passwordless." + +# Improved Sudo Check: Try a non-destructive command with sudo +echo "Checking sudo permissions (you may be prompted for a password)..." +if sudo -v; then + echo -e "${GREEN}[PASS]${NC} User has sudo privileges." else - echo -e "${RED}[FAIL]${NC} Sudo requires a password or user is not in sudoers." + echo -e "${RED}[FAIL]${NC} User is NOT in sudoers or password was incorrect." fi # Detect OS and try to update/install basics if [ -f /etc/debian_version ]; then - echo "OS: Debian/Ubuntu detected. Checking packages..." - sudo apt-get update -qq && sudo apt-get install -y curl wget git netcat-openbsd -qq > /dev/null + echo "OS: Debian/Ubuntu detected." + # sudo apt-get update -qq && sudo apt-get install -y curl wget git -qq > /dev/null elif [ -f /etc/redhat-release ]; then - echo "OS: RHEL/CentOS detected. Checking packages..." - sudo yum makecache -q && sudo yum install -y curl wget git nc -q > /dev/null + echo "OS: RHEL/CentOS detected." + # sudo yum makecache -q && sudo yum install -y curl wget git -q > /dev/null +else + echo "OS: Non-Linux (Mac/Other) detected. Network tests will use 'curl' fallback." fi # --- 3. TOOL VERIFICATION --- @@ -48,11 +53,22 @@ echo -e "\n${YELLOW}[3/4] Testing Wallarm Cloud Connectivity (Port 443)...${NC}" test_conn() { local target=$1 local desc=$2 - # Linux-native check. Note: Won't work on default macOS Bash, but perfect for Linux VMs. - if timeout 3 bash -c "cat < /dev/null > /dev/tcp/$target/443" 2>/dev/null; then - echo -e "${GREEN}[PASS]${NC} $desc ($target)" + + # Check if we are on Linux (which supports /dev/tcp) or Mac + if [[ "$OSTYPE" == "darwin"* ]]; then + # Mac Fallback: Use curl to check connection + if curl -sk --connect-timeout 3 "https://$target" > /dev/null 2>&1 || [ $? -eq 45 ] || [ $? -eq 35 ]; then + echo -e "${GREEN}[PASS]${NC} $desc ($target)" + else + echo -e "${RED}[FAIL]${NC} $desc ($target) - BLOCKED" + fi else - echo -e "${RED}[FAIL]${NC} $desc ($target) - BLOCKED" + # Linux Native: Faster and more reliable in locked-down environments + if timeout 3 bash -c "cat < /dev/null > /dev/tcp/$target/443" 2>/dev/null; then + echo -e "${GREEN}[PASS]${NC} $desc ($target)" + else + echo -e "${RED}[FAIL]${NC} $desc ($target) - BLOCKED" + fi fi } @@ -71,10 +87,20 @@ test_conn "35.235.115.105" "Extra US-3" # --- 5. INTERNAL APP CHECK --- echo -e "\n${YELLOW}[4/4] Testing Internal App Connectivity...${NC}" -if timeout 3 bash -c "cat < /dev/null > /dev/tcp/$APP_HOST/$APP_PORT" 2>/dev/null; then - echo -e "${GREEN}[PASS]${NC} Reached App at $APP_HOST:$APP_PORT" +if [[ "$OSTYPE" == "darwin"* ]]; then + # Mac check for the app port specifically + if curl -s --connect-timeout 3 "$APP_HOST:$APP_PORT" > /dev/null 2>&1 || [ $? -eq 52 ] || [ $? -eq 45 ]; then + echo -e "${GREEN}[PASS]${NC} Reached App at $APP_HOST:$APP_PORT" + else + echo -e "${RED}[FAIL]${NC} Cannot reach $APP_HOST on port $APP_PORT" + fi else - echo -e "${RED}[FAIL]${NC} CANNOT REACH $APP_HOST on port $APP_PORT" + # Linux native check + if timeout 3 bash -c "cat < /dev/null > /dev/tcp/$APP_HOST/$APP_PORT" 2>/dev/null; then + echo -e "${GREEN}[PASS]${NC} Reached App at $APP_HOST:$APP_PORT" + else + echo -e "${RED}[FAIL]${NC} CANNOT REACH $APP_HOST on port $APP_PORT" + fi fi echo -e "\n${YELLOW}-------------------------------------------------------"