Matches the other deploy/unraid/*.sh scripts; was committed 644 instead of 755, caught while running it directly against the Unraid deployment.
47 lines
1.7 KiB
Bash
Executable File
47 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
container_name="${1:-n8n}"
|
|
scan_url="${2:-http://192.168.10.150:1236/api/v1/integrations/n8n/scheduled-scan}"
|
|
source_workflow="${3:-n8n/mobilityops-scheduled-quality-scan.json}"
|
|
|
|
if [ ! -f .env ]; then
|
|
echo "Missing deployment .env" >&2
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$source_workflow" ]; then
|
|
echo "Missing workflow export: $source_workflow" >&2
|
|
exit 1
|
|
fi
|
|
if ! docker inspect "$container_name" >/dev/null 2>&1; then
|
|
echo "Existing n8n container not found: $container_name" >&2
|
|
exit 1
|
|
fi
|
|
|
|
callback_token="$(sed -n 's/^MOBILITYOPS_CALLBACK_TOKEN=//p' .env | tail -n 1)"
|
|
if [ -z "$callback_token" ]; then
|
|
echo "MOBILITYOPS_CALLBACK_TOKEN is empty" >&2
|
|
exit 1
|
|
fi
|
|
|
|
temporary_workflow="$(mktemp /tmp/mobilityops-n8n-workflow.XXXXXX.json)"
|
|
container_workflow="/tmp/mobilityops-scheduled-quality-scan.json"
|
|
cleanup() {
|
|
rm -f "$temporary_workflow"
|
|
docker exec "$container_name" rm -f "$container_workflow" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
jq --arg scan_url "$scan_url" --arg callback_token "$callback_token" '
|
|
(.nodes[] | select(.id == "scan-node") | .parameters.url) = $scan_url |
|
|
(.nodes[] | select(.id == "scan-node") | .parameters.headerParameters.parameters[] |
|
|
select(.name == "X-Service-Token") | .value) = $callback_token
|
|
' "$source_workflow" > "$temporary_workflow"
|
|
|
|
docker cp "$temporary_workflow" "$container_name:$container_workflow" >/dev/null
|
|
docker exec "$container_name" n8n import:workflow --input="$container_workflow"
|
|
docker exec "$container_name" n8n publish:workflow --id=mobilityops-scheduled-quality-scan
|
|
docker restart "$container_name" >/dev/null
|
|
|
|
echo "Published MobilityOps scheduled quality-scan workflow to existing container ${container_name}"
|