Files
nextcloud-nodered-agent/integrate-into-nodered.sh
T

119 lines
4.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# Integration script for node-red-contrib-nextcloud-agent
# Patches agent nodes into existing nextcloud-node-red Docker image
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NODERED_DIR="${NODERED_DIR:-/path/to/nextcloud-node-red}"
echo "=== Nextcloud Agent Node-RED Integration ==="
echo "Source: $SCRIPT_DIR"
echo "Target: $NODERED_DIR"
if [[ ! -d "$NODERED_DIR" ]]; then
echo "ERROR: NODERED_DIR not found: $NODERED_DIR"
echo "Set NODERED_DIR environment variable or edit this script"
exit 1
fi
if [[ ! -f "$NODERED_DIR/Dockerfile" ]]; then
echo "ERROR: No Dockerfile found in $NODERED_DIR"
exit 1
fi
# 1. Copy nodes to nextcloud-node-red nodes directory
NODES_TARGET="$NODERED_DIR/nodes/nextcloud-ocs"
echo "Copying agent nodes to $NODES_TARGET..."
mkdir -p "$NODES_TARGET"
cp "$SCRIPT_DIR/nodes"/*.js "$NODES_TARGET/"
cp "$SCRIPT_DIR/nodes"/*.html "$NODES_TARGET/"
echo "Nodes copied."
# 2. Patch Dockerfile to install agent CLI
DOCKERFILE="$NODERED_DIR/Dockerfile"
echo "Patching Dockerfile..."
if grep -q "agent-cli" "$DOCKERFILE"; then
echo "Dockerfile already contains agent CLI installation"
else
cp "$DOCKERFILE" "$DOCKERFILE.bak.$(date +%s)"
sed -i '/COPY nodes\//i\
# Install agent CLI (adjust for your specific agent)\
RUN npm install -g your-agent-cli@latest || \\\
(curl -fsSL https://your-agent.example.com/install.sh | bash && \\\
ln -sf ~/.agent/bin/agent /usr/local/bin/agent)\
' "$DOCKERFILE"
echo "Dockerfile patched with agent CLI installation (EDIT THE INSTALL COMMAND)."
fi
# 3. Patch entrypoint.sh to include agent nodes
ENTRYPOINT="$NODERED_DIR/entrypoint.sh"
echo "Patching entrypoint.sh..."
if [[ -f "$ENTRYPOINT" ]]; then
cp "$ENTRYPOINT" "$ENTRYPOINT.bak.$(date +%s)"
if ! grep -q "node-red-contrib-nextcloud-agent" "$ENTRYPOINT"; then
sed -i '/copy nodes/a\
# Install agent nodes\
if [ -d "/opt/nextcloud-nodes/node-red-contrib-nextcloud-agent" ]; then \
cp -r /opt/nextcloud-nodes/node-red-contrib-nextcloud-agent/* /data/node_modules/ 2>/dev/null || true \
fi' "$ENTRYPOINT"
echo "entrypoint.sh patched."
else
echo "entrypoint.sh already contains agent nodes."
fi
else
echo "WARNING: entrypoint.sh not found at $ENTRYPOINT"
fi
# 4. Create agent nodes package in /opt for entrypoint to copy
OPT_NODES_DIR="$NODERED_DIR/opt/nextcloud-nodes"
echo "Creating agent nodes package in $OPT_NODES_DIR..."
mkdir -p "$OPT_NODES_DIR/node-red-contrib-nextcloud-agent/nodes"
cp "$SCRIPT_DIR/nodes"/*.js "$OPT_NODES_DIR/node-red-contrib-nextcloud-agent/nodes/"
cp "$SCRIPT_DIR/nodes"/*.html "$OPT_NODES_DIR/node-red-contrib-nextcloud-agent/nodes/"
cp "$SCRIPT_DIR/package.json" "$OPT_NODES_DIR/node-red-contrib-nextcloud-agent/package.json"
echo "Agent nodes package created."
# 5. Update docker-compose.yml to add agent workspace volume
COMPOSE="$NODERED_DIR/docker-compose.yml"
if [[ -f "$COMPOSE" ]]; then
echo "Checking docker-compose.yml for agent workspace volume..."
if ! grep -q "agent-workspace" "$COMPOSE"; then
cp "$COMPOSE" "$COMPOSE.bak.$(date +%s)"
sed -i '/volumes:/a\
- agent-workspace:/data/agent-workspace' "$COMPOSE"
sed -i '/^volumes:/a\
agent-workspace:' "$COMPOSE"
echo "docker-compose.yml updated with agent-workspace volume."
else
echo "docker-compose.yml already has agent-workspace volume."
fi
fi
echo ""
echo "=== Integration Complete ==="
echo ""
echo "IMPORTANT: Edit the Dockerfile to install YOUR specific agent CLI:"
echo " $NODERED_DIR/Dockerfile"
echo ""
echo "Next steps:"
echo "1. Rebuild the Docker image:"
echo " cd $NODERED_DIR && docker compose build --no-cache"
echo ""
echo "2. Restart the container:"
echo " docker compose up -d"
echo ""
echo "3. In Node-RED, configure an 'agent config' node with:"
echo " - CLI Command: agent (your installed agent binary)"
echo " - Workspace Directory: /data/agent-workspace"
echo " - API Endpoint: http://localhost:3000 (if using agent server mode)"
echo ""
echo "4. Import example flows from: $SCRIPT_DIR/flows/"