-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvita_cmd.sh
More file actions
executable file
·64 lines (51 loc) · 1.58 KB
/
vita_cmd.sh
File metadata and controls
executable file
·64 lines (51 loc) · 1.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
#!/usr/bin/env bash
# Run a command on the Vita via serial and print its output.
# Blocks until the shell prompt returns (or timeout).
# Requires serial_log.py to be running (provides /tmp/serial.pipe and logs/latest.log).
set -euo pipefail
LOGFILE="logs/latest.log"
PIPE="/tmp/serial.pipe"
TIMEOUT="${2:-10}"
PROMPT_PATTERN='# $' # root prompt (no trailing newline, so appears at end of file)
if [[ -z "${1:-}" ]]; then
echo "Usage: vita_cmd.sh <command> [timeout_secs]" >&2
exit 1
fi
if [[ ! -p "$PIPE" ]]; then
echo "No pipe at $PIPE — is serial_log.py running?" >&2
exit 1
fi
if [[ ! -f "$LOGFILE" ]]; then
echo "No $LOGFILE found — is serial_log.py running?" >&2
exit 1
fi
# Snapshot log position (bytes) before sending command
start_bytes=$(wc -c < "$LOGFILE" | tr -d ' ')
# Send command
printf '%s\n' "$1" > "$PIPE"
# Wait for output, print it, exit when prompt returns
start_time=$(date +%s)
printed=0
while true; do
current_bytes=$(wc -c < "$LOGFILE" | tr -d ' ')
if (( current_bytes > start_bytes )); then
# Read new bytes
new_data=$(tail -c +"$((start_bytes + 1))" "$LOGFILE")
new_len=${#new_data}
# Print only the portion we haven't printed yet
if (( new_len > printed )); then
echo -n "${new_data:$printed}"
printed=$new_len
fi
# Check if prompt has returned (last bytes are "# ")
if [[ "$new_data" =~ $PROMPT_PATTERN ]]; then
echo # newline after prompt
exit 0
fi
fi
if (( $(date +%s) - start_time >= TIMEOUT )); then
echo -e "\n(timed out after ${TIMEOUT}s)" >&2
exit 1
fi
sleep 0.1
done