forked from jkef80/Filament-Management
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmock_sshpass.sh
More file actions
executable file
·53 lines (47 loc) · 1.44 KB
/
mock_sshpass.sh
File metadata and controls
executable file
·53 lines (47 loc) · 1.44 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
#!/usr/bin/env bash
# mock_sshpass.sh — fake sshpass that intercepts CFSync's SSH calls and fetches
# material_box_info.json from the mock server's HTTP endpoint instead.
#
# Usage: place this on PATH *before* the real sshpass when running CFSync:
#
# PATH="$PWD:$PATH" uvicorn main:app --reload --host 0.0.0.0 --port 8000
#
# CFSync calls:
# sshpass -p PASSWORD ssh -o ... root@HOST "cat FILE1 || cat FILE2"
#
# We extract HOST from the "root@HOST" argument and fetch:
# http://HOST:7125/mock/material_box_info
#
# The script must be named "sshpass" (copy or symlink it):
# cp mock_sshpass.sh sshpass && chmod +x sshpass
# Parse args: skip -p PASSWORD, find "root@HOST" pattern, ignore the rest.
HOST=""
skip_next=false
for arg in "$@"; do
if $skip_next; then
skip_next=false
continue
fi
# -p PASSWORD: skip -p and the next arg (password)
if [[ "$arg" == "-p" ]]; then
skip_next=true
continue
fi
# root@HOST
if [[ "$arg" =~ ^root@(.+)$ ]]; then
HOST="${BASH_REMATCH[1]}"
break
fi
done
if [[ -z "$HOST" ]]; then
echo "mock_sshpass: could not determine printer host from arguments: $*" >&2
exit 1
fi
URL="http://${HOST}:7125/mock/material_box_info"
response=$(curl -sf --max-time 5 "$URL" 2>/dev/null)
exit_code=$?
if [[ $exit_code -ne 0 || -z "$response" ]]; then
echo "mock_sshpass: failed to fetch $URL (curl exit $exit_code)" >&2
exit 1
fi
echo "$response"