-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·67 lines (56 loc) · 1.84 KB
/
start.sh
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
#!/bin/bash
cleanup() {
# Stop service-connect
PS_ID=$(ps aux | grep "edgevpn service-connect PairingSSH" | grep -v grep | awk '{print $2}')
if [ -n "${PS_ID}" ]; then
kill $(ps aux | grep "edgevpn service-connect PairingSSH" | grep -v grep | awk '{print $2}')
fi
command="docker stop pairing-station"
if [[ -z "${VM_CONNECT}" ]]; then
eval "${command}"
else
ssh -t "${VM_CONNECT}" "${command}" || true
fi
}
start() {
cleanup
command="docker run -d --name pairing-station \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
--rm --user 1000:1001 \
-it -v "${PWD}":/home/dev/workspace \
-e GITHUB_USERS="${GITHUB_USERS}" \
-e EDGEVPNTOKEN=${EDGEVPNTOKEN} \
ghcr.io/spectrocloud-labs/pairing-station:main /bin/bash"
if [[ -z "${VM_CONNECT}" ]]; then
eval "${command}"
else
ssh -t "${VM_CONNECT}" "${command}"
fi
}
export TOKEN_FILE=$(mktemp)
if [[ -z "${EDGEVPNTOKEN}" ]]; then
echo "EDGEVPNTOKEN env variable not defined."
echo "Check out: https://mudler.github.io/edgevpn/docs/getting-started/cli/#generate-a-network-token"
echo "Will generate one"
export EDGEVPNTOKEN=$(edgevpn -g -b)
fi
echo "Writing token to ${TOKEN_FILE}"
echo $EDGEVPNTOKEN > "${TOKEN_FILE}"
if [[ -z "${GITHUB_USERS}" ]]; then
echo "GITHUB_USERS should be set to a comma separated list of github users"
exit 1
fi
start
echo "Done!"
echo "Connect with these commands:"
echo
echo 'export EDGEVPNTOKEN=$(cat '"${TOKEN_FILE}"')'
echo 'edgevpn service-connect "PairingSSH" "127.0.0.1:2222" > /tmp/pairing-edgevpn.logs 2>&1 &'
echo 'ssh [email protected] -p 2222'
echo
echo '(the last command might take a few retries before it succeeds)'
echo 'Run `tmux attach` after you succesfully ssh to the box`'
echo
echo "Send over ${TOKEN_FILE} to the other devs (${GITHUB_USERS}) so they can connect too using the same commands."
echo