-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02_network.sh
More file actions
executable file
·81 lines (71 loc) · 3.65 KB
/
02_network.sh
File metadata and controls
executable file
·81 lines (71 loc) · 3.65 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
79
80
81
#!/usr/bin/env bash
# 02_network.sh — storescu / storescp / echoscu showcase
#
# Starts a Storage SCP on localhost:11112, sends all 5 ABDOM slices,
# then verifies the received files look correct.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$SCRIPT_DIR/../.."
DCMDUMP="$ROOT/target/debug/dcmdump"
ECHOSCU="$ROOT/target/debug/echoscu"
STORESCU="$ROOT/target/debug/storescu"
STORESCP="$ROOT/target/debug/storescp"
FILES="$SCRIPT_DIR/../testfiles"
for bin in "$DCMDUMP" "$ECHOSCU" "$STORESCU" "$STORESCP"; do
if [[ ! -x "$bin" ]]; then
echo "Binary not found: $bin — run: cargo build --bins"
exit 1
fi
done
PORT=11112
RECV_DIR="$(mktemp -d)"
SCP_PID=""
cleanup() {
if [[ -n "$SCP_PID" ]]; then
kill "$SCP_PID" 2>/dev/null || true
wait "$SCP_PID" 2>/dev/null || true
fi
rm -rf "$RECV_DIR"
}
trap cleanup EXIT
# ─────────────────────────────────────────────
echo "════════════════════════════════════════"
echo " Step 1 — Start Storage SCP on :$PORT"
echo "════════════════════════════════════════"
"$STORESCP" -v -a STORESCP -d "$RECV_DIR" "$PORT" &
SCP_PID=$!
sleep 0.5
if ! kill -0 "$SCP_PID" 2>/dev/null; then
echo "ERROR: storescp failed to start (port $PORT in use?)"
exit 1
fi
echo "storescp PID $SCP_PID → saving to $RECV_DIR"
# ─────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════"
echo " Step 2 — C-ECHO verification"
echo "════════════════════════════════════════"
"$ECHOSCU" -v -a DEMO_SCU -c STORESCP localhost "$PORT"
# ─────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════"
echo " Step 3 — Send 5 CT slices with storescu"
echo "════════════════════════════════════════"
"$STORESCU" -v -a DEMO_SCU -c STORESCP localhost "$PORT" "$FILES"/ABDOM_*.dcm
# ─────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════"
echo " Step 4 — Verify received files"
echo "════════════════════════════════════════"
RECEIVED=$(find "$RECV_DIR" -name "*.dcm" | sort)
COUNT=$(echo "$RECEIVED" | grep -c ".dcm" || true)
echo "Received $COUNT file(s):"
for f in $RECEIVED; do
echo ""
echo " File: $(basename "$f")"
"$DCMDUMP" "$f" | grep -E "^\(0010,0010\)|^\(0008,0016\)|^\(0020,0013\)|^\(0028,0010\)|^\(0028,0011\)" | sed 's/^/ /'
done
echo ""
echo "════════════════════════════════════════"
echo " Done — $COUNT/$( ls "$FILES"/ABDOM_*.dcm | wc -l | tr -d ' ') files transferred successfully"
echo "════════════════════════════════════════"