#!/bin/bash # Setup script for Django Manufacturing App on Linux # Exit on any error set -e # Check if Python 3 is installed if ! command -v python3 &> /dev/null; then echo "Python 3 is not installed. Please install Python 3.8 or higher." exit 1 fi # Check Python version PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') if [[ $(echo "$PYTHON_VERSION < 3.8" | bc -l) -eq 1 ]]; then echo "Python version 3.8 or higher is required. Current version: $PYTHON_VERSION" exit 1 fi echo "Setting up virtual environment for Django Manufacturing App..." # Create virtual environment python3 -m venv venv # Activate virtual environment source venv/bin/activate # Upgrade pip pip install --upgrade pip # Install requirements pip install -r requirements.txt # Create .env file if it doesn't exist if [ ! -f .env ]; then echo "Creating .env file..." cat > .env << EOF # Django Settings DEBUG=True SECRET_KEY=your-development-secret-key ALLOWED_HOSTS=localhost,127.0.0.1 # Database Settings (SQLite for development) # For PostgreSQL in production, uncomment and set these: # DATABASE_URL=postgres://user:password@host:port/dbname # DB_NAME=your_db_name # DB_USER=your_db_user # DB_PASSWORD=your_db_password # DB_HOST=your_db_host # DB_PORT=5432 # Email Settings (optional) # EMAIL_HOST=your_email_host # EMAIL_PORT=587 # EMAIL_USE_TLS=True # EMAIL_HOST_USER=your_email_user # EMAIL_HOST_PASSWORD=your_email_password EOF echo "Please update the .env file with your actual settings." fi # Create logs directory echo "Creating logs directory..." mkdir -p logs # Run migrations echo "Running database migrations..." python manage.py makemigrations python manage.py migrate # Create superuser (optional) echo "Creating superuser..." echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | python manage.py shell echo "Setup complete!" echo "To activate the virtual environment, run: source venv/bin/activate" echo "To start the development server, run: python manage.py runserver"