#!/bin/bash # SecuBox Module Scaffold Script # Usage: ./new-module.sh "" [category] [icon] [order] set -e cd "$(dirname "$0")/.." NAME="$1" DESC="${2:-SecuBox $NAME module}" CATEGORY="${3:-apps}" ICON="${4:-📦}" ORDER="${5:-500}" if [ -z "$NAME" ]; then echo "Usage: $0 [description] [category] [icon] [order]" echo "Categories: dashboard, security, network, monitoring, publishing, apps" exit 1 fi PKG="packages/secubox-$NAME" if [ -d "$PKG" ]; then echo "Error: $PKG already exists" exit 1 fi NAME_UPPER=$(echo "$NAME" | sed 's/.*/\u&/') echo "Creating module: $NAME ($DESC)" # Create directory structure mkdir -p "$PKG"/{api,www/$NAME,menu.d,debian} # API main.py cat > "$PKG/api/__init__.py" << 'EOF' """SecuBox API Module""" EOF cat > "$PKG/api/main.py" << EOF """SecuBox $NAME_UPPER API""" from fastapi import FastAPI, Depends from secubox_core.auth import require_jwt from secubox_core.config import get_config app = FastAPI(title="SecuBox $NAME_UPPER") config = get_config("$NAME") @app.get("/status") async def status(): """Public status endpoint""" return { "module": "$NAME", "status": "ok", "version": "1.0.0" } @app.get("/info", dependencies=[Depends(require_jwt)]) async def info(): """Protected info endpoint""" return {"config": dict(config)} EOF # Frontend index.html cat > "$PKG/www/$NAME/index.html" << EOF SecuBox - $NAME_UPPER

$NAME_UPPER

Status

Loading...

EOF # Menu definition cat > "$PKG/menu.d/${ORDER}-$NAME.json" << EOF { "id": "$NAME", "name": "$NAME_UPPER", "category": "$CATEGORY", "icon": "$ICON", "path": "/$NAME/", "order": $ORDER, "description": "$DESC" } EOF # Debian control cat > "$PKG/debian/control" << EOF Source: secubox-$NAME Section: admin Priority: optional Maintainer: SecuBox Build-Depends: debhelper-compat (= 13) Standards-Version: 4.6.2 Package: secubox-$NAME Architecture: all Depends: \${misc:Depends}, secubox-core (>= 1.0.0) Description: SecuBox $NAME_UPPER Module $DESC EOF # Debian changelog cat > "$PKG/debian/changelog" << EOF secubox-$NAME (1.0.0-1~bookworm1) bookworm; urgency=medium * Initial release -- SecuBox $(date -R) EOF # Debian rules (compat handled by debhelper-compat in control) cat > "$PKG/debian/rules" << 'EOF' #!/usr/bin/make -f %: dh $@ override_dh_auto_install: install -d debian/secubox-MODULE/usr/lib/secubox/MODULE cp -r api debian/secubox-MODULE/usr/lib/secubox/MODULE/ install -d debian/secubox-MODULE/usr/share/secubox/www/MODULE cp -r www/MODULE/. debian/secubox-MODULE/usr/share/secubox/www/MODULE/ install -d debian/secubox-MODULE/usr/share/secubox/menu.d [ -d menu.d ] && cp -r menu.d/. debian/secubox-MODULE/usr/share/secubox/menu.d/ || true EOF sed -i "s/MODULE/$NAME/g" "$PKG/debian/rules" chmod +x "$PKG/debian/rules" # Debian postinst cat > "$PKG/debian/postinst" << EOF #!/bin/sh set -e if [ "\$1" = "configure" ]; then systemctl daemon-reload systemctl enable secubox-$NAME.service || true systemctl start secubox-$NAME.service || true fi #DEBHELPER# exit 0 EOF chmod +x "$PKG/debian/postinst" # Debian prerm cat > "$PKG/debian/prerm" << EOF #!/bin/sh set -e if [ "\$1" = "remove" ]; then systemctl stop secubox-$NAME.service || true systemctl disable secubox-$NAME.service || true fi #DEBHELPER# exit 0 EOF chmod +x "$PKG/debian/prerm" # Systemd service cat > "$PKG/debian/secubox-$NAME.service" << EOF [Unit] Description=SecuBox $NAME_UPPER API After=network.target secubox-core.service Requires=secubox-core.service [Service] Type=simple User=secubox Group=secubox WorkingDirectory=/usr/lib/secubox/$NAME ExecStart=/usr/bin/python3 -m uvicorn api.main:app --uds /run/secubox/$NAME.sock --log-level warning Restart=on-failure RestartSec=5 UMask=0000 PrivateTmp=true NoNewPrivileges=true ProtectSystem=strict ReadWritePaths=/run/secubox /var/lib/secubox /etc/secubox [Install] WantedBy=multi-user.target EOF echo "" echo "Created: $PKG" echo "" echo "Next steps:" echo "1. Implement API endpoints in $PKG/api/main.py" echo "2. Customize frontend in $PKG/www/$NAME/index.html" echo "3. Build: cd $PKG && dpkg-buildpackage -us -uc -b" echo "4. Add nginx location to common/nginx/secubox.conf:" echo "" echo " location /api/v1/$NAME/ {" echo " proxy_pass http://unix:/run/secubox/$NAME.sock:/;" echo " include /etc/nginx/snippets/secubox-proxy.conf;" echo " }"