forked from openclaw/AXorcist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxorc_runner.sh
More file actions
executable file
·78 lines (69 loc) · 2.58 KB
/
Copy pathaxorc_runner.sh
File metadata and controls
executable file
·78 lines (69 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Simple runner for axorc, taking a JSON file as input.
# AXORC_PATH should be the path to your axorc executable.
# If not set, it defaults to a path relative to this script.
# Determine the directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Set AXORC_PATH relative to the script's directory if not already set
: ${AXORC_PATH:="$SCRIPT_DIR/AXorcist/.build/debug/axorc"}
# Check if AXORC_PATH exists and is executable
if [ ! -x "$AXORC_PATH" ]; then
echo "Error: axorc executable not found or not executable at $AXORC_PATH"
echo "Please set AXORC_PATH environment variable or ensure it's built at the default location."
exit 1
fi
DEBUG_FLAG=""
POSITIONAL_ARGS=()
# Parse arguments for --debug and file/json payload
while [[ $# -gt 0 ]]; do
case "$1" in
--debug)
DEBUG_FLAG="--debug"
shift # past argument
;;
--file)
if [[ -z "$2" || ! -f "$2" ]]; then
echo "Error: File not provided or not found after --file argument."
exit 1
fi
INPUT_JSON=$(cat "$2")
USE_STDIN_FLAG=true
shift # past argument
shift # past value
;;
--json)
if [[ -z "$2" ]]; then
echo "Error: JSON string not provided after --json argument."
exit 1
fi
INPUT_JSON="$2"
USE_STDIN_FLAG=true
shift # past argument
shift # past value
;;
*)
POSITIONAL_ARGS+=("$1") # unknown option will be captured if axorc supports more
shift # past argument
;;
esac
done
if [ -z "$INPUT_JSON" ]; then
echo "Error: No JSON input provided via --file or --json."
echo "Usage: $0 [--debug] --file /path/to/command.json OR $0 [--debug] --json '{"command":"ping"}'"
exit 1
fi
echo "--- DEBUG_RUNNER: INPUT_JSON content before piping --- BEGIN"
printf "%s\n" "$INPUT_JSON"
echo "--- DEBUG_RUNNER: INPUT_JSON content before piping --- END"
echo "--- DEBUG_RUNNER: AXORC_PATH: $AXORC_PATH"
echo "--- DEBUG_RUNNER: DEBUG_FLAG: $DEBUG_FLAG"
# Execute axorc with the input JSON
if [ "$USE_STDIN_FLAG" = true ]; then
printf '%s' "$INPUT_JSON" | "$AXORC_PATH" --stdin $DEBUG_FLAG "${POSITIONAL_ARGS[@]}"
AXORC_EXIT_CODE=$?
echo "--- DEBUG_RUNNER: axorc exit code: $AXORC_EXIT_CODE ---"
else
# This case should not be reached if --file or --json is mandatory
echo "Error: USE_STDIN_FLAG was not set, programming error in runner script."
exit 1
fi