-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetscreen
More file actions
executable file
·68 lines (60 loc) · 1.97 KB
/
Copy pathgetscreen
File metadata and controls
executable file
·68 lines (60 loc) · 1.97 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
#!/usr/bin/env bash
# Capture screenshot from AMI MegaRAC BMC HTML5 KVM
# Usage: getscreen [--wait MS] <bmc-ip> [output.jpg]
# Env: BMC_USER (required), BMC_PASS (required), BMC_DEBUG=1 (optional)
#
# NOTE: ASPEED BMC video encoders can take surprisingly long to deliver the
# first frame after boot, resolution changes, or reconnection. The tool polls
# the KVM canvas for non-black content before capturing. If your screenshot
# comes back black, try increasing --wait (default: 5000ms). In production
# incidents, waiting even 60s is better than getting a false black screen.
set -euo pipefail
# Parse --wait argument
RENDER_WAIT=""
while [[ $# -gt 0 ]]; do
case "$1" in
--wait)
RENDER_WAIT="$2"
shift 2
;;
--wait=*)
RENDER_WAIT="${1#--wait=}"
shift
;;
-*)
echo "Unknown option: $1" >&2
echo "Usage: getscreen [--wait MS] <bmc-ip> [output.jpg]" >&2
exit 1
;;
*)
break
;;
esac
done
if [[ $# -lt 1 ]]; then
echo "Usage: getscreen [--wait MS] <bmc-ip> [output.jpg]" >&2
echo " --wait MS Max time to wait for video frame (default: 5000)" >&2
echo " Env: BMC_USER, BMC_PASS (required)" >&2
echo " Env: BMC_RENDER_WAIT (same as --wait), BMC_DEBUG=1" >&2
exit 1
fi
HOST="$1"
OUTPUT="${2:-/tmp/bmc-${HOST}.jpg}"
if [[ -z "${BMC_USER:-}" || -z "${BMC_PASS:-}" ]]; then
echo "ERROR: BMC_USER and BMC_PASS environment variables must be set" >&2
exit 1
fi
# --wait flag overrides env var
if [[ -n "$RENDER_WAIT" ]]; then
export BMC_RENDER_WAIT="$RENDER_WAIT"
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SUPPRESS="${BMC_DEBUG:+/dev/stderr}"
node "${SCRIPT_DIR}/kvm-capture.js" "$HOST" "$BMC_USER" "$BMC_PASS" "$OUTPUT" 2>"${SUPPRESS:-/dev/null}"
EXIT=$?
if [[ $EXIT -eq 0 && -s "$OUTPUT" ]]; then
echo "${OUTPUT}"
else
echo "ERROR: Screenshot capture failed for ${HOST}" >&2
exit 1
fi