summaryrefslogtreecommitdiff
path: root/tests/create-and-run.sh
blob: dfd4022b66fdae9e028bc938381826ae5aa56e0a (plain)
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
#!/bin/sh

# shellcheck disable=SC2086

set -ex

cleanup() {
	rm -f ssh_id ssh_id.pub test.ext2
}

trap cleanup EXIT INT TERM QUIT

ssh-keygen -f ssh_id -N ''
debvm-create -k ssh_id.pub -o test.ext2 "$@"

timeout 240s debvm-run -s 2222 -i test.ext2 &
timeout=5
sshopt="-o StrictHostKeyChecking=no $(if test "$2" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)"
ts=$(sleepenh 0 || [ $? -eq 1 ])
for i in $(seq 30); do
	rv=0
	ssh $sshopt -o ConnectTimeout="$timeout" -i ssh_id -p 2222 root@localhost echo success || rv=$?
	test $rv -eq 0 && break
	ts=$(sleepenh "$ts" "$timeout" || [ $? -eq 1 ]);
	if test "$i" -eq 30; then
		echo "timeout reached" >&2
		exit 1
	fi
done
ssh $sshopt -i ssh_id -p 2222 root@localhost poweroff