-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-tkey-qemu
executable file
·61 lines (48 loc) · 1.48 KB
/
run-tkey-qemu
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
#!/bin/sh
# SPDX-FileCopyrightText: 2023 Tillitis AB <tillitis.se>
# SPDX-License-Identifier: BSD-2-Clause
image=ghcr.io/tillitis/tkey-qemu-tk1-23.03.1:latest
if [ "$(uname -s)" != Linux ]; then
printf "Currently this only works on Linux (not when using podman machine)\n"
exit 1
fi
if ! hash 2>/dev/null socat; then
printf "Please install socat. Ubuntu: apt install socat\n"
exit 1
fi
printf "Using image: %s\n" "$image"
if [ "${1:-}" = "-p" ]; then
shift
podman pull $image || true
else
printf "You can pass argument '-p' to pull any update to this image.\n"
fi
hostside=$(pwd)/tkey-qemu-pty
containerside=/tmp/tkey-qemu-$(id -u)-pty-for-container
for pty in "$hostside" "$containerside"; do
if [ -e "$pty" ]; then
printf "%s already exists, bailing out\n" "$pty"
exit 1
fi
done
socat "pty,raw,echo=0,link=$hostside" \
"pty,raw,echo=0,link=$containerside" &
socatpid=$$
cleanup() {
trap - EXIT INT HUP TERM
kill -1 $socatpid || true
rm -f "$hostside" "$containerside"
}
trap cleanup EXIT INT HUP TERM
while true; do
printf "\033[32m"
printf "Running TKey/QEMU container using image: %s\n" "$image"
printf "Let your TKey client app talk to it by passing: --port %s\n" "$hostside"
printf "Stop QEMU by typing 'Ctrl-a' and then 'x'. It will then restart.\n"
printf "\033[0m"
podman run --rm -it --device "$containerside:/pty-on-host" $image
printf "\033[33m"
printf "Restarting in 1s... Type 'Ctrl-c' now to quit!\n"
printf "\033[0m"
sleep 1s
done