Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-25 08:29:12

0001 #!/bin/bash
0002 # Set up swf-remote development environment.
0003 # Creates symlinks to swf-monitor shared templates and validates dependencies.
0004 
0005 set -euo pipefail
0006 
0007 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
0008 SRC_DIR="$SCRIPT_DIR/src"
0009 
0010 # swf-monitor location (sibling repo)
0011 SWF_MONITOR="${SWF_MONITOR:-$(dirname "$SCRIPT_DIR")/swf-monitor}"
0012 
0013 echo "=== swf-remote dev setup ==="
0014 
0015 # ── Validate swf-monitor ────────────────────────────────────────────────────
0016 
0017 if [ ! -d "$SWF_MONITOR/src/monitor_app/templates/monitor_app" ]; then
0018     echo "ERROR: swf-monitor not found at $SWF_MONITOR"
0019     echo "Set SWF_MONITOR env var to the swf-monitor repo root."
0020     exit 1
0021 fi
0022 
0023 echo "swf-monitor: $SWF_MONITOR"
0024 
0025 # ── Shared templates ────────────────────────────────────────────────────────
0026 
0027 MONITOR_TEMPLATES="$SRC_DIR/monitor_templates"
0028 LINK_TARGET="$SWF_MONITOR/src/monitor_app/templates/monitor_app"
0029 
0030 mkdir -p "$MONITOR_TEMPLATES"
0031 
0032 if [ -L "$MONITOR_TEMPLATES/monitor_app" ]; then
0033     CURRENT=$(readlink "$MONITOR_TEMPLATES/monitor_app")
0034     if [ "$CURRENT" = "$LINK_TARGET" ]; then
0035         echo "Templates symlink OK: monitor_app -> $LINK_TARGET"
0036     else
0037         echo "Updating templates symlink (was: $CURRENT)"
0038         rm "$MONITOR_TEMPLATES/monitor_app"
0039         ln -s "$LINK_TARGET" "$MONITOR_TEMPLATES/monitor_app"
0040         echo "Templates symlink: monitor_app -> $LINK_TARGET"
0041     fi
0042 elif [ -e "$MONITOR_TEMPLATES/monitor_app" ]; then
0043     echo "ERROR: $MONITOR_TEMPLATES/monitor_app exists but is not a symlink."
0044     echo "Remove it and re-run."
0045     exit 1
0046 else
0047     ln -s "$LINK_TARGET" "$MONITOR_TEMPLATES/monitor_app"
0048     echo "Templates symlink created: monitor_app -> $LINK_TARGET"
0049 fi
0050 
0051 # Symlink shared base templates (base.html lives in swf-monitor's top templates dir)
0052 BASE_LINK="$MONITOR_TEMPLATES/base_monitor.html"
0053 BASE_TARGET="$SWF_MONITOR/src/templates/base.html"
0054 if [ -L "$BASE_LINK" ]; then
0055     echo "Base template symlink OK"
0056 elif [ -f "$BASE_TARGET" ]; then
0057     ln -s "$BASE_TARGET" "$BASE_LINK"
0058     echo "Base template symlink created: base_monitor.html -> $BASE_TARGET"
0059 fi
0060 
0061 # ── Static files ───────────────────────────────────────────────────────────
0062 # swf-remote has its own static/css/style.css (not symlinked from swf-monitor).
0063 # Remove legacy symlink if present.
0064 
0065 STATIC_DIR="$SRC_DIR/remote_app/static"
0066 if [ -L "$STATIC_DIR" ]; then
0067     echo "Removing legacy static symlink (swf-remote now has its own static files)"
0068     rm "$STATIC_DIR"
0069 fi
0070 echo "Static files: $STATIC_DIR (own copy)"
0071 
0072 # ── Python venv ─────────────────────────────────────────────────────────────
0073 
0074 VENV="$SCRIPT_DIR/.venv"
0075 if [ ! -d "$VENV" ]; then
0076     echo "Creating Python venv..."
0077     python3 -m venv "$VENV"
0078     "$VENV/bin/pip" install --upgrade pip
0079     "$VENV/bin/pip" install -r "$SCRIPT_DIR/requirements/dev.txt"
0080     echo "Venv created and dependencies installed."
0081 else
0082     echo "Venv exists: $VENV"
0083 fi
0084 
0085 echo ""
0086 echo "=== Setup complete ==="
0087 echo "Activate venv:  source $VENV/bin/activate"
0088 echo "Run dev server: cd src && python manage.py runserver"