generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 549
/
script.sh
executable file
·51 lines (42 loc) · 1.41 KB
/
script.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
#!/bin/bash
set -e
if [[ ! -z "$SKIP_DEBUGGER" ]]; then
echo "Skipping debugger because SKIP_DEBUGGER enviroment variable is set"
exit
fi
# Install tmate on macOS or Ubuntu
echo Setting up tmate...
if [ -x "$(command -v brew)" ]; then
brew install tmate > /tmp/brew.log
fi
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get install -y tmate openssh-client > /tmp/apt-get.log
fi
# Generate ssh key if needed
[ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -N ""
# Run deamonized tmate
echo Running tmate...
tmate -S /tmp/tmate.sock new-session -d
tmate -S /tmp/tmate.sock wait tmate-ready
# Print connection info
echo ________________________________________________________________________________
echo
echo To connect to this session copy-n-paste the following into a terminal:
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'
echo After connecting you can run 'touch /tmp/keepalive' to disable the 15m timeout
if [[ ! -z "$SLACK_WEBHOOK_URL" ]]; then
MSG=$(tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}')
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"\`$MSG\`\"}" $SLACK_WEBHOOK_URL
fi
# Wait for connection to close or timeout in 15 min
timeout=$((15*60))
while [ -S /tmp/tmate.sock ]; do
sleep 1
timeout=$(($timeout-1))
if [ ! -f /tmp/keepalive ]; then
if (( timeout < 0 )); then
echo Waiting on tmate connection timed out!
exit 1
fi
fi
done