forked from acmpesuecc/SCB-Vulnerability-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_env_linux.sh
More file actions
95 lines (77 loc) · 2.98 KB
/
setup_env_linux.sh
File metadata and controls
95 lines (77 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
set -e
set -o pipefail
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
# Function to check if a command exists
check_command() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}[ERROR] $1 is not installed. Please install it before running this script.${NC}"
exit 1
else
echo -e "${GREEN}[OK] $1 is installed.${NC}"
fi
}
# Check required tools
echo -e "\n${GREEN}--- Checking required tools ---${NC}"
check_command minikube
check_command helm
check_command kubectl
echo -e "\n${GREEN}--- Starting Minikube cluster ---${NC}"
if ! minikube status | grep -q "Running"; then
minikube start --driver=docker
else
echo -e "${GREEN}[OK] Minikube already running.${NC}"
fi
echo -e "\n${GREEN}--- Installing SecureCodeBox Operator ---${NC}"
retry=3
count=0
until helm --namespace securecodebox-system upgrade --install --create-namespace securecodebox-operator oci://ghcr.io/securecodebox/helm/operator; do
((count++))
echo -e "${RED}[ERROR] Helm install failed. Retrying ($count/$retry)...${NC}"
if [ "$count" -eq "$retry" ]; then
echo -e "${RED}[FAIL] Helm install failed after $retry attempts.${NC}"
exit 1
fi
sleep 5
done
echo -e "\n${GREEN}--- Installing SecureCodeBox Generic WebHook ---${NC}"
helm upgrade --install generic-webhook oci://ghcr.io/securecodebox/helm/generic-webhook \
--set="webhookUrl=http://mobsf-webapp.default.svc.cluster.local:8000/webhook/findings"
echo -e "\n${GREEN}--- Packaging Helm chart from ./mobsf ---${NC}"
if [ ! -d "./mobsf" ]; then
echo -e "${RED}[ERROR] Chart directory './mobsf' not found.${NC}"
exit 1
fi
helm package ./mobsf
PACKAGE_FILE=$(ls mobsf-*.tgz | sort -r | head -n1)
if [ ! -f "$PACKAGE_FILE" ]; then
echo -e "${RED}[ERROR] Packaged chart file not found.${NC}"
exit 1
fi
echo -e "\n${GREEN}--- Installing or Upgrading MobSF Helm chart ---${NC}"
if helm list -n default | grep -q "mobsf"; then
helm upgrade mobsf "./$PACKAGE_FILE"
else
helm install mobsf "./$PACKAGE_FILE"
fi
echo -e "\n${GREEN}--- Port-forwarding mobsf-webapp service to localhost:8088 ---${NC}"
# Function to clean up background jobs on exit
cleanup() {
if [[ -n "$PF_PID" ]] && kill -0 "$PF_PID" 2>/dev/null; then
echo -e "\n${GREEN}Cleaning up port-forward (PID: $PF_PID)...${NC}"
kill "$PF_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT SIGINT
# Start port-forward in background
kubectl port-forward svc/mobsf-webapp 8088:8088 -n default &
PF_PID=$!
echo -e "${GREEN}Port-forwarding is running in the background (PID: $PF_PID). Access the webapp at http://localhost:8088${NC}"
echo -e "${GREEN}To stop port-forwarding, just exit the script (Ctrl+C) or close the terminal.${NC}"
# Wait for port-forward to keep running until user exits
wait $PF_PID
echo -e "\n${GREEN}✅ Setup complete. MobSF, SecureCodeBox and GUI tool are deployed inside your cluster.${NC}"
echo -e "${GREEN}You can now open GUI tool at localhost:8088 and start triggering APK/IPA scans${NC}"