-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·348 lines (293 loc) · 9.65 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·348 lines (293 loc) · 9.65 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
# ShadowWall AI Setup Script
# Automated setup for development and deployment environments
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
PYTHON_MIN_VERSION="3.8"
PROJECT_NAME="ShadowWall AI"
VENV_NAME="shadowwall-env"
# Functions
print_banner() {
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ ShadowWall AI ║"
echo "║ Setup & Installation ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_python() {
log_info "Checking Python version..."
if ! command -v python3 &> /dev/null; then
log_error "Python 3 is not installed"
exit 1
fi
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
REQUIRED_VERSION=$(echo -e "$PYTHON_VERSION\n$PYTHON_MIN_VERSION" | sort -V | head -n1)
if [[ "$REQUIRED_VERSION" != "$PYTHON_MIN_VERSION" ]]; then
log_error "Python $PYTHON_MIN_VERSION or higher is required. Found: $PYTHON_VERSION"
exit 1
fi
log_info "Python $PYTHON_VERSION is available ✓"
}
check_system_dependencies() {
log_info "Checking system dependencies..."
# Check for package manager
if command -v apt &> /dev/null; then
PACKAGE_MANAGER="apt"
UPDATE_CMD="apt update"
INSTALL_CMD="apt install -y"
elif command -v yum &> /dev/null; then
PACKAGE_MANAGER="yum"
UPDATE_CMD="yum update -y"
INSTALL_CMD="yum install -y"
elif command -v dnf &> /dev/null; then
PACKAGE_MANAGER="dnf"
UPDATE_CMD="dnf update -y"
INSTALL_CMD="dnf install -y"
else
log_warning "Package manager not detected. Manual dependency installation may be required."
return
fi
# Required system packages
REQUIRED_PACKAGES=(
"python3-dev"
"python3-pip"
"python3-venv"
"libpcap-dev"
"build-essential"
"curl"
"git"
)
# Additional packages for different distributions
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
REQUIRED_PACKAGES+=("python3-distutils")
fi
# Check if running as root for system package installation
if [[ $EUID -ne 0 ]] && [[ "$1" != "--skip-system" ]]; then
log_warning "Root privileges required for system package installation"
log_info "Re-run with sudo or use --skip-system flag"
exit 1
fi
# Install missing packages
MISSING_PACKAGES=()
for package in "${REQUIRED_PACKAGES[@]}"; do
if ! dpkg -l | grep -q "^ii $package " 2>/dev/null && \
! rpm -q "$package" &>/dev/null && \
! command -v "$package" &>/dev/null; then
MISSING_PACKAGES+=("$package")
fi
done
if [[ ${#MISSING_PACKAGES[@]} -gt 0 ]]; then
log_info "Installing missing system packages: ${MISSING_PACKAGES[*]}"
$UPDATE_CMD
$INSTALL_CMD "${MISSING_PACKAGES[@]}"
else
log_info "All system dependencies are available ✓"
fi
}
check_docker() {
log_info "Checking Docker availability..."
if command -v docker &> /dev/null; then
if docker info &> /dev/null; then
log_info "Docker is available and running ✓"
return 0
else
log_warning "Docker is installed but not running"
log_info "Start Docker service: sudo systemctl start docker"
return 1
fi
else
log_warning "Docker is not installed"
log_info "Install Docker: https://docs.docker.com/engine/install/"
return 1
fi
}
setup_virtual_environment() {
log_info "Setting up Python virtual environment..."
if [[ -d "$VENV_NAME" ]]; then
log_warning "Virtual environment already exists. Removing..."
rm -rf "$VENV_NAME"
fi
python3 -m venv "$VENV_NAME"
source "$VENV_NAME/bin/activate"
# Upgrade pip
pip install --upgrade pip
log_info "Virtual environment created: $VENV_NAME ✓"
}
install_python_dependencies() {
log_info "Installing Python dependencies..."
# Ensure we're in the virtual environment
if [[ "$VIRTUAL_ENV" == "" ]]; then
log_warning "Virtual environment not activated. Activating..."
source "$VENV_NAME/bin/activate"
fi
# Install from requirements.txt
if [[ -f "requirements.txt" ]]; then
pip install -r requirements.txt
log_info "Python dependencies installed ✓"
else
log_error "requirements.txt not found"
exit 1
fi
}
setup_configuration() {
log_info "Setting up configuration..."
# Create config directory
mkdir -p config
# Copy example configuration if main config doesn't exist
if [[ ! -f "config/config.yaml" ]]; then
if [[ -f "config/config.example.yaml" ]]; then
cp "config/config.example.yaml" "config/config.yaml"
log_info "Created config/config.yaml from example"
else
log_warning "No example configuration found"
fi
fi
# Create additional directories
mkdir -p logs data/{models,honeypots,captures,reports} temp
log_info "Configuration setup completed ✓"
}
setup_docker_environment() {
log_info "Setting up Docker environment..."
if check_docker; then
# Build Docker image
if [[ -f "Dockerfile" ]]; then
docker build -t shadowwall-ai .
log_info "Docker image built ✓"
fi
# Check docker-compose
if command -v docker-compose &> /dev/null || command -v docker compose &> /dev/null; then
log_info "Docker Compose is available ✓"
else
log_warning "Docker Compose not found"
fi
else
log_warning "Skipping Docker setup - Docker not available"
fi
}
run_tests() {
log_info "Running basic tests..."
# Ensure we're in the virtual environment
if [[ "$VIRTUAL_ENV" == "" ]]; then
source "$VENV_NAME/bin/activate"
fi
# Test Python imports
python3 -c "
import sys
try:
import fastapi, uvicorn, sqlalchemy, scapy, sklearn
print('✓ All core dependencies can be imported')
except ImportError as e:
print(f'✗ Import error: {e}')
sys.exit(1)
"
# Test configuration loading
python3 -c "
try:
from src.core.config.settings import load_config
config = load_config('config/config.yaml')
print('✓ Configuration can be loaded')
except Exception as e:
print(f'✗ Configuration error: {e}')
"
log_info "Basic tests completed ✓"
}
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --help Show this help message"
echo " --skip-system Skip system package installation"
echo " --skip-docker Skip Docker setup"
echo " --skip-tests Skip running tests"
echo " --development Setup for development (include dev dependencies)"
echo ""
echo "Examples:"
echo " $0 # Full setup"
echo " $0 --skip-system # Skip system packages (if already installed)"
echo " $0 --development # Setup for development"
}
main() {
print_banner
# Parse command line arguments
SKIP_SYSTEM=false
SKIP_DOCKER=false
SKIP_TESTS=false
DEVELOPMENT=false
while [[ $# -gt 0 ]]; do
case $1 in
--help)
show_usage
exit 0
;;
--skip-system)
SKIP_SYSTEM=true
shift
;;
--skip-docker)
SKIP_DOCKER=true
shift
;;
--skip-tests)
SKIP_TESTS=true
shift
;;
--development)
DEVELOPMENT=true
shift
;;
*)
log_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
log_info "Starting $PROJECT_NAME setup..."
# Core setup steps
check_python
if [[ "$SKIP_SYSTEM" != true ]]; then
check_system_dependencies
fi
setup_virtual_environment
install_python_dependencies
setup_configuration
if [[ "$SKIP_DOCKER" != true ]]; then
setup_docker_environment
fi
if [[ "$SKIP_TESTS" != true ]]; then
run_tests
fi
# Show completion message
echo ""
log_info "Setup completed successfully! 🎉"
echo ""
echo -e "${BLUE}Next steps:${NC}"
echo "1. Activate virtual environment: source $VENV_NAME/bin/activate"
echo "2. Review configuration: config/config.yaml"
echo "3. Start ShadowWall AI: python init.py"
echo ""
echo -e "${BLUE}Alternative start methods:${NC}"
echo "• Development mode: python init.py --debug"
echo "• Simulation mode: python init.py --simulate"
echo "• Docker: docker-compose up"
echo ""
log_info "For help: python init.py --help"
}
# Run main function
main "$@"