Files
MTCBD/dev.sh
__init__ 766a68e1cf dev.sh
2026-02-23 20:33:05 +05:30

136 lines
6.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ─────────────────────────────────────────────
# MTCBD Multi-Tenant Cloud Based Dashboard
# Development Startup Script
# ─────────────────────────────────────────────
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$PROJECT_DIR/.venv"
BACKEND_DIR="$PROJECT_DIR/backend"
FRONTEND_DIR="$PROJECT_DIR/frontend"
BACKEND_PID=""
FRONTEND_SKIP=true # Frontend disabled by default, run manually when needed
# ── Colours ──────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
NC='\033[0m'
# ── Cleanup on Ctrl+C / exit ─────────────────
cleanup() {
echo ""
echo -e "${YELLOW} Shutting down servers...${NC}"
[ -n "$BACKEND_PID" ] && kill "$BACKEND_PID" 2>/dev/null
[ -n "$FRONTEND_PID" ] && kill "$FRONTEND_PID" 2>/dev/null
wait 2>/dev/null
echo -e "${GREEN} All servers stopped.${NC}"
exit 0
}
trap cleanup INT TERM EXIT
# ── Banner ────────────────────────────────────
echo -e "${CYAN}"
echo " ███╗ ███╗████████╗ ██████╗██████╗ ██████╗ "
echo " ████╗ ████║╚══██╔══╝██╔════╝██╔══██╗██╔══██╗"
echo " ██╔████╔██║ ██║ ██║ ██████╔╝██║ ██║"
echo " ██║╚██╔╝██║ ██║ ██║ ██╔══██╗██║ ██║"
echo " ██║ ╚═╝ ██║ ██║ ╚██████╗██████╔╝██████╔╝"
echo " ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═════╝ ╚═════╝ "
echo -e " Multi-Tenant Cloud Based Dashboard${NC}"
echo ""
# ════════════════════════════════════════════════
# BACKEND SETUP
# ════════════════════════════════════════════════
# ── 1. Check / Create Virtual Environment ────
if [ ! -d "$VENV_DIR" ]; then
echo -e "${YELLOW}[1/6] Creating virtual environment...${NC}"
python3 -m venv "$VENV_DIR"
echo -e "${GREEN} ✓ Virtual environment created${NC}"
else
echo -e "${GREEN}[1/6] Virtual environment found${NC}"
fi
# ── 2. Activate Virtual Environment ──────────
echo -e "${YELLOW}[2/6] Activating virtual environment...${NC}"
source "$VENV_DIR/bin/activate"
echo -e "${GREEN} ✓ Activated: $VIRTUAL_ENV${NC}"
# ── 3. Install Python Dependencies ───────────
echo -e "${YELLOW}[3/6] Installing Python dependencies...${NC}"
pip install --upgrade pip --quiet
pip install -r "$PROJECT_DIR/requirements.txt" --quiet
echo -e "${GREEN} ✓ Dependencies installed${NC}"
# ── 4. Check .env File ───────────────────────
echo -e "${YELLOW}[4/6] Checking environment config...${NC}"
if [ ! -f "$PROJECT_DIR/.env" ]; then
echo -e "${RED} ⚠ No .env file found!${NC}"
if [ -f "$PROJECT_DIR/.env.example" ]; then
cp "$PROJECT_DIR/.env.example" "$PROJECT_DIR/.env"
echo -e "${YELLOW} ⚠ .env created from .env.example fill in your secrets.${NC}"
else
echo -e "${RED} ✗ No .env.example either. Please create .env manually.${NC}"
fi
else
echo -e "${GREEN} ✓ .env file found${NC}"
fi
# ── 5. Django Setup ───────────────────────────
echo -e "${YELLOW}[5/6] Running Django setup...${NC}"
if [ -d "$BACKEND_DIR" ]; then
(
cd "$BACKEND_DIR"
python manage.py collectstatic --noinput --quiet 2>/dev/null || true
python manage.py migrate --run-syncdb 2>/dev/null \
|| echo -e "${YELLOW} ⚠ Migrations skipped (DB may not be configured yet)${NC}"
)
echo -e "${GREEN} ✓ Django ready${NC}"
else
echo -e "${RED} ✗ backend/ directory not found${NC}"
fi
# ════════════════════════════════════════════════
# FRONTEND SETUP (SKIPPED)
# ════════════════════════════════════════════════
# Frontend is not started automatically. To run it manually:
# cd frontend && npm run dev
# FRONTEND_SKIP is set to true above to skip frontend launch.
# ════════════════════════════════════════════════
# LAUNCH BOTH SERVERS
# ════════════════════════════════════════════════
echo ""
echo -e "${GREEN}════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Starting MTCBD Development Servers ${NC}"
echo -e "${GREEN} ${NC}"
echo -e "${GREEN} Backend → http://127.0.0.1:8000 ${NC}"
echo -e "${YELLOW} Frontend → (not started, run manually: cd frontend && npm run dev)${NC}"
echo -e "${GREEN} ${NC}"
echo -e "${YELLOW} Press Ctrl+C to stop all servers ${NC}"
echo -e "${GREEN}════════════════════════════════════════════════════${NC}"
echo ""
# ── Start Backend ─────────────────────────────
(
source "$VENV_DIR/bin/activate"
cd "$BACKEND_DIR"
python manage.py runserver 2>&1 | while IFS= read -r line; do
echo -e "${GREEN}[BACKEND] ${NC} $line"
done
) &
BACKEND_PID=$!
# ── Start Frontend ────────────────────────────
# Skipped - start manually when needed
# ── Wait (keeps script alive until Ctrl+C) ────
wait