-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
185 lines (167 loc) · 4.74 KB
/
Copy pathsetup.sh
File metadata and controls
185 lines (167 loc) · 4.74 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
#!/bin/bash
# MammoViewer - Setup Script
# Automates the installation and configuration process
set -e
echo "================================================"
echo "MammoViewer - Setup"
echo "================================================"
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check Python
echo "Checking Python installation..."
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version)
echo -e "${GREEN}✓ Found: $PYTHON_VERSION${NC}"
PYTHON_CMD=python3
elif command -v python &> /dev/null; then
PYTHON_VERSION=$(python --version)
echo -e "${GREEN}✓ Found: $PYTHON_VERSION${NC}"
PYTHON_CMD=python
else
echo -e "${RED}✗ Python not found!${NC}"
echo "Please install Python 3.8 or higher from https://www.python.org/downloads/"
exit 1
fi
# Check pip
echo ""
echo "Checking pip installation..."
if command -v pip3 &> /dev/null; then
echo -e "${GREEN}✓ pip is installed${NC}"
PIP_CMD=pip3
elif command -v pip &> /dev/null; then
echo -e "${GREEN}✓ pip is installed${NC}"
PIP_CMD=pip
else
echo -e "${RED}✗ pip not found!${NC}"
exit 1
fi
# Create virtual environment
echo ""
echo "Creating Python virtual environment..."
if [ -d "venv" ]; then
echo -e "${YELLOW}⚠ Virtual environment already exists${NC}"
read -p "Remove and recreate? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf venv
$PYTHON_CMD -m venv venv
echo -e "${GREEN}✓ Virtual environment recreated${NC}"
fi
else
$PYTHON_CMD -m venv venv
echo -e "${GREEN}✓ Virtual environment created${NC}"
fi
# Activate virtual environment
echo ""
echo "Activating virtual environment..."
source venv/bin/activate
echo -e "${GREEN}✓ Virtual environment activated${NC}"
# Install dependencies
echo ""
echo "Installing Python dependencies..."
cd backend
pip install --upgrade pip
pip install -r requirements.txt
echo -e "${GREEN}✓ Dependencies installed${NC}"
cd ..
# Create directories
echo ""
echo "Creating necessary directories..."
mkdir -p uploads
mkdir -p outputs
mkdir -p temp
mkdir -p logs
mkdir -p slicer_scripts
echo -e "${GREEN}✓ Directories created${NC}"
# Create .env file
echo ""
echo "Setting up environment configuration..."
if [ ! -f ".env" ]; then
cp .env.example .env
echo -e "${GREEN}✓ Created .env file from template${NC}"
echo -e "${YELLOW}⚠ Please edit .env and update SLICER_PATH${NC}"
else
echo -e "${YELLOW}⚠ .env file already exists${NC}"
fi
# Detect 3D Slicer
echo ""
echo "Searching for 3D Slicer installation..."
SLICER_FOUND=false
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
if [ -f "/Applications/Slicer.app/Contents/MacOS/Slicer" ]; then
SLICER_PATH="/Applications/Slicer.app/Contents/MacOS/Slicer"
SLICER_FOUND=true
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
SLICER_LOCATIONS=(
"/usr/local/Slicer-*/Slicer"
"$HOME/Slicer-*/Slicer"
)
for loc in "${SLICER_LOCATIONS[@]}"; do
if ls $loc 1> /dev/null 2>&1; then
SLICER_PATH=$(ls $loc | head -1)
SLICER_FOUND=true
break
fi
done
fi
if [ "$SLICER_FOUND" = true ]; then
echo -e "${GREEN}✓ Found 3D Slicer at: $SLICER_PATH${NC}"
# Update config.py
if [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "linux-gnu"* ]]; then
sed -i.bak "s|SLICER_PATH = .*|SLICER_PATH = os.environ.get('SLICER_PATH', '$SLICER_PATH')|" backend/config.py
rm backend/config.py.bak
echo -e "${GREEN}✓ Updated config.py with Slicer path${NC}"
fi
else
echo -e "${YELLOW}⚠ 3D Slicer not found automatically${NC}"
echo "Please install 3D Slicer from: https://download.slicer.org/"
echo "Then update SLICER_PATH in backend/config.py"
fi
# Test configuration
echo ""
echo "Testing configuration..."
cd backend
$PYTHON_CMD config.py
cd ..
# Final instructions
echo ""
echo "================================================"
echo -e "${GREEN}Setup Complete!${NC}"
echo "================================================"
echo ""
echo "Next steps:"
echo ""
echo "1. If 3D Slicer path wasn't auto-detected:"
echo " Edit backend/config.py and set SLICER_PATH"
echo ""
echo "2. Start the application:"
echo " cd backend"
echo " python app.py"
echo ""
echo "3. Open your browser:"
echo " http://localhost:5000"
echo ""
echo "4. For detailed instructions, see:"
echo " - QUICKSTART.md"
echo " - README.md"
echo ""
echo "================================================"
echo ""
# Ask to start server
read -p "Start the server now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "Starting server..."
echo "Press Ctrl+C to stop"
echo ""
cd backend
$PYTHON_CMD app.py
fi