-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
198 lines (170 loc) · 6 KB
/
install.sh
File metadata and controls
198 lines (170 loc) · 6 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
#!/bin/bash
# Smart Elections Parser - Linux/macOS Installation Script
# Automates dependency installation on Unix-like systems
set -e # Exit on error
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_header() {
echo -e "\n${BLUE}======================================================================${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}======================================================================${NC}\n"
}
print_success() {
echo -e "${GREEN}? $1${NC}"
}
print_warning() {
echo -e "${YELLOW}? $1${NC}"
}
print_error() {
echo -e "${RED}? $1${NC}"
}
print_info() {
echo -e "${BLUE}? $1${NC}"
}
# Parse arguments
DEV_MODE=false
WITH_TESTS=false
SKIP_SYSTEM_DEPS=false
while [[ $# -gt 0 ]]; do
case $1 in
--dev)
DEV_MODE=true
shift
;;
--with-tests)
WITH_TESTS=true
shift
;;
--skip-system-deps)
SKIP_SYSTEM_DEPS=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--dev] [--with-tests] [--skip-system-deps]"
exit 1
;;
esac
done
print_header "Smart Elections Parser - Installation"
# Check Python version
print_header "Checking Python Version"
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is not installed"
exit 1
fi
PYTHON_VERSION=$(python3 --version | awk '{print $2}')
print_info "Python version: $PYTHON_VERSION"
# Check if version is >= 3.12
REQUIRED_VERSION="3.12"
if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 12) else 1)"; then
print_error "Python 3.12 or higher is required!"
print_info "Please upgrade Python: https://www.python.org/downloads/"
exit 1
fi
print_success "Python version is compatible"
# Upgrade pip
print_header "Upgrading pip"
python3 -m pip install --upgrade pip
print_success "pip upgraded successfully"
# Install system dependencies
if [ "$SKIP_SYSTEM_DEPS" = false ]; then
print_header "Installing System Dependencies"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
print_info "Linux detected - Installing system packages"
if command -v apt-get &> /dev/null; then
print_info "Using apt-get package manager"
sudo apt-get update
sudo apt-get install -y poppler-utils tesseract-ocr ghostscript
print_success "System dependencies installed"
elif command -v yum &> /dev/null; then
print_info "Using yum package manager"
sudo yum install -y poppler-utils tesseract ghostscript
print_success "System dependencies installed"
else
print_warning "Unknown package manager - please install manually:"
print_warning " - poppler-utils"
print_warning " - tesseract-ocr"
print_warning " - ghostscript"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
print_info "macOS detected - Installing system packages"
if command -v brew &> /dev/null; then
brew install poppler tesseract ghostscript
print_success "System dependencies installed"
else
print_warning "Homebrew not found - please install manually:"
print_warning " brew install poppler tesseract ghostscript"
fi
else
print_warning "Unknown OS - please install system dependencies manually"
fi
else
print_info "Skipping system dependencies installation"
fi
# Install Python requirements
print_header "Installing Production Dependencies"
python3 -m pip install -r requirements.txt
print_success "Production dependencies installed"
# Install dev requirements if requested
if [ "$DEV_MODE" = true ]; then
print_header "Installing Development Dependencies"
if [ -f "requirements-dev.txt" ]; then
python3 -m pip install -r requirements-dev.txt
print_success "Development dependencies installed"
else
print_warning "requirements-dev.txt not found"
fi
fi
# Install testing dependencies if requested
if [ "$WITH_TESTS" = true ] || [ "$DEV_MODE" = true ]; then
print_header "Installing Testing Dependencies"
python3 -m pip install pytest pytest-cov pytest-mock
print_success "Testing dependencies installed"
fi
# Install Playwright browsers
print_header "Installing Playwright Browsers"
if command -v playwright &> /dev/null; then
playwright install chromium
print_success "Playwright browsers installed"
else
print_warning "Playwright command not found, trying alternative..."
python3 -m playwright install chromium || print_warning "Failed to install Playwright browsers"
fi
# Verify spaCy model
print_header "Verifying spaCy Model"
if python3 -c "import spacy; spacy.load('en_core_web_sm')" 2>/dev/null; then
print_success "spaCy model is installed"
else
print_info "Downloading spaCy model..."
python3 -m spacy download en_core_web_sm
print_success "spaCy model downloaded"
fi
# Verify installation
print_header "Verifying Installation"
python3 -c "import flask_socketio, spacy, playwright; print('OK')" && \
print_success "Core packages import successfully" || \
print_error "Some packages failed to import"
# Run security tests if testing dependencies were installed
if [ "$WITH_TESTS" = true ] || [ "$DEV_MODE" = true ]; then
print_header "Running Security Tests"
if python3 -m pytest webapp/tests/test_path_security.py -v; then
print_success "Security tests passed!"
else
print_warning "Some security tests failed"
fi
fi
# Final summary
print_header "Installation Complete!"
print_success "All dependencies have been installed"
echo ""
print_info "Next steps:"
print_info " 1. Configure your .env file"
print_info " 2. Run security tests: pytest webapp/tests/test_*_security.py -v"
print_info " 3. Run security audit: python3 security_audit.py"
print_info " 4. Start application: python3 webapp/Smart_Elections_Parser_Webapp.py"
echo ""