-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry-local.sh
More file actions
executable file
·45 lines (36 loc) · 1.14 KB
/
Copy pathtry-local.sh
File metadata and controls
executable file
·45 lines (36 loc) · 1.14 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
#!/bin/sh
set -eu
cd "$(dirname "$0")" || exit 1
if [ "$#" -ne 0 ]; then
echo "usage: ./try-local.sh" >&2
exit 2
fi
cargo build --release
out="$(mktemp)"
./target/release/tenax-server --detach-ttl 3600 >"$out" 2>/dev/null &
server_pid="$!"
# Poll for the token line the server prints on startup, up to ~10 s.
line=""
i=0
while [ "$i" -lt 10 ]; do
line="$(head -n 1 "$out" 2>/dev/null || true)"
if [ -n "$line" ]; then
break
fi
sleep 1
i=$((i + 1))
done
if [ -z "$line" ]; then
echo "try-local: server did not print its address within 10 s" >&2
kill "$server_pid" 2>/dev/null || true
exit 1
fi
addr="$(printf '%s\n' "$line" | cut -d ' ' -f 1)"
fp="$(printf '%s\n' "$line" | cut -d ' ' -f 2)"
secret="$(printf '%s\n' "$line" | cut -d ' ' -f 3)"
echo "tenax-server pid $server_pid on $addr"
echo "it exits with the session or after the 1 h detach TTL; after a client kill, \`tenax $addr\` resumes from the state bundle"
# Become the client. No trap kills the server: it must outlive this client
# so the resume demo works.
export TENAX_SECRET="$secret"
exec ./target/release/tenax "$addr" --fingerprint "$fp"