|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# setup-environment.sh - Sets up Python virtual environment and installs all dependencies |
| 4 | + |
| 5 | +# Define color codes |
| 6 | +GREEN='\033[0;32m' |
| 7 | +YELLOW='\033[1;33m' |
| 8 | +RED='\033[0;31m' |
| 9 | +NC='\033[0m' # No Color |
| 10 | + |
| 11 | +# Store initial directory |
| 12 | +INITIAL_DIR=$(pwd) |
| 13 | + |
| 14 | +# Function to handle errors |
| 15 | +handle_error() { |
| 16 | + echo -e "${RED}Error: $1${NC}" |
| 17 | + cd "$INITIAL_DIR" |
| 18 | + exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +echo -e "${GREEN}Setting up development environment...${NC}" |
| 22 | + |
| 23 | +# Check if we're in scripts directory and navigate accordingly |
| 24 | +if [[ $(basename $(pwd)) == "scripts" ]]; then |
| 25 | + cd .. |
| 26 | +fi |
| 27 | + |
| 28 | +# Verify we're in the project root |
| 29 | +if [[ ! -d "server" ]] || [[ ! -d "client" ]]; then |
| 30 | + handle_error "Not in project root directory. Please run from the project root or scripts directory." |
| 31 | +fi |
| 32 | + |
| 33 | +echo -e "${YELLOW}Setting up Python virtual environment...${NC}" |
| 34 | + |
| 35 | +# Check OS and use appropriate Python command |
| 36 | +if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then |
| 37 | + # Windows |
| 38 | + if ! py -m venv server/venv; then |
| 39 | + handle_error "Failed to create Python virtual environment" |
| 40 | + fi |
| 41 | + |
| 42 | + if ! source server/venv/Scripts/activate; then |
| 43 | + handle_error "Failed to activate Python virtual environment" |
| 44 | + fi |
| 45 | +else |
| 46 | + # macOS/Linux |
| 47 | + if ! python3 -m venv server/venv; then |
| 48 | + handle_error "Failed to create Python virtual environment" |
| 49 | + fi |
| 50 | + |
| 51 | + if ! source server/venv/bin/activate; then |
| 52 | + handle_error "Failed to activate Python virtual environment" |
| 53 | + fi |
| 54 | +fi |
| 55 | + |
| 56 | +echo -e "${YELLOW}Installing Python dependencies...${NC}" |
| 57 | +if ! pip install -r server/requirements.txt; then |
| 58 | + handle_error "Failed to install Python dependencies" |
| 59 | +fi |
| 60 | + |
| 61 | +echo -e "${YELLOW}Installing npm dependencies...${NC}" |
| 62 | +cd client || handle_error "client directory not found" |
| 63 | + |
| 64 | +if ! npm install; then |
| 65 | + handle_error "Failed to install npm dependencies" |
| 66 | +fi |
| 67 | + |
| 68 | +cd .. |
| 69 | + |
| 70 | +echo -e "${GREEN}Environment setup completed successfully!${NC}" |
| 71 | +echo -e "${GREEN}Python virtual environment: server/venv${NC}" |
| 72 | +echo -e "${GREEN}All dependencies installed.${NC}" |
| 73 | +echo "" |
| 74 | +echo -e "${YELLOW}To activate the Python environment manually:${NC}" |
| 75 | +if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then |
| 76 | + echo " source server/venv/Scripts/activate" |
| 77 | +else |
| 78 | + echo " source server/venv/bin/activate" |
| 79 | +fi |
| 80 | + |
| 81 | +# Return to initial directory |
| 82 | +cd "$INITIAL_DIR" |
0 commit comments