Repository navigation
Expand file tree
/
Copy pathnproxy-run.sh
More file actions
executable file
·60 lines (51 loc) · 1.76 KB
/
Copy pathnproxy-run.sh
File metadata and controls
executable file
·60 lines (51 loc) · 1.76 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
#!/bin/bash
# nproxy-run.sh — Run any command through nproxy
#
# Usage:
# ./nproxy-run.sh [options] <command> [args...]
# ./nproxy-run.sh passthrough -- /usr/bin/someapp --flag
# ./nproxy-run.sh --pty myapp # PTY mode for interactive CLIs
# ./nproxy-run.sh passthrough --pty -- myapp
#
# Without a text-mode argument, defaults to NPROXY_TEXT=passthrough.
# If the first argument matches a known mode (passthrough|strip-ansi|transform),
# it is consumed as --text=. Otherwise passthrough is assumed.
#
# Environment:
# NPROXY_TEXT text mode override (takes precedence over positional arg)
MODE="passthrough"
PTY=""
COMMAND_ARGS=()
if [ "$#" -eq 0 ]; then
echo "Usage: $0 [passthrough|strip-ansi|transform] [--pty] -- <command> [args...]" >&2
exit 1
fi
case "$1" in
passthrough|strip-ansi|transform)
MODE="$1"
shift
;;
esac
# Handle --pty flag
if [ "$1" = "--pty" ]; then
PTY="--pty"
shift
fi
# Handle -- separator
if [ "$1" = "--" ]; then
shift
fi
COMMAND_ARGS=("$@")
if [ "${#COMMAND_ARGS[@]}" -eq 0 ]; then
echo "nproxy-run.sh: no command specified" >&2
exit 1
fi
cd "$(dirname "$0")" && SCRIPT_DIR="$(pwd -P)"
NODE_BIN="$(command -v node)"
# Auto-set max-old-space-size to 75% of total RAM (overridable via NODE_OPT_MAX_OLD env var)
NODE_OPT_MAX_OLD="${NODE_OPT_MAX_OLD:-$("$NODE_BIN" -e "console.log(Math.floor(require('os').totalmem() / 1024 / 1024 * 0.75))" 2>/dev/null)}"
: "${NODE_OPT_MAX_OLD:=2048}"
# Ensure node-pty can be resolved from global modules
NPM_GLOBAL_ROOT="$(npm root -g 2>/dev/null || echo /usr/local/lib/node_modules)"
export NODE_PATH="${NODE_PATH:-$NPM_GLOBAL_ROOT}"
exec "$NODE_BIN" --expose-gc "--max-old-space-size=${NODE_OPT_MAX_OLD}" "$SCRIPT_DIR/node/nproxy.js" "--text=$MODE" $PTY "${COMMAND_ARGS[@]}"