This repository has been archived by the owner on Feb 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
travis-tmate-edge.bash.in
82 lines (63 loc) · 1.97 KB
/
travis-tmate-edge.bash.in
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -o errexit
main() {
__write_tmate_config
__setup_papertrail_rsyslog
__write_tmate_ssh_keys
__write_proxy_config
__restart_tmate
}
__restart_tmate() {
stop tmate-remote-tmux || true
start tmate-remote-tmux || true
stop tmate-proxy || true
start tmate-proxy || true
}
__write_tmate_config() {
cat > /etc/default/tmate-config <<EOF
___ENV___
EOF
}
__s3_download() {
local bucket access_id access_token date signature file
access_id=$1
access_token=$2
bucket=$3
file=$4
date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
signature="$(echo -en "GET\n\n\n$date\n/$bucket/$file" | openssl sha1 -binary -hmac $access_token | base64)"
curl -Ssl -H "Host: $bucket.s3.amazonaws.com" -H "Date: $date" -H "Authorization: AWS $access_id:$signature" https://$bucket.s3.amazonaws.com/$file
}
__s3_tmate_download() {
source /etc/default/tmate-config
__s3_download $TRAVIS_TMATE_SSH_KEYS_S3_ACCESS_ID \
$TRAVIS_TMATE_SSH_KEYS_S3_ACCESS_TOKEN \
$TRAVIS_TMATE_SSH_KEYS_S3_BUCKET \
$1
}
__write_tmate_ssh_keys() {
local key_dir=/etc/ssh/tmate-keys
mkdir -p $key_dir
for f in ssh_host_rsa_key ssh_host_rsa_key.pub ssh_host_ecdsa_key ssh_host_ecdsa_key.pub; do
__s3_tmate_download $f > $key_dir/$f
chmod 600 $key_dir/$f
done
}
__write_proxy_config() {
source /etc/default/tmate-config
local config_file=/srv/tmate-proxy/releases/*/sys.config
sed -i "s^TMATE_HMAC_KEY_PLACEHOLDER^$TRAVIS_TMATE_HMAC_KEY^g" $config_file
sed -i "s^TMATE_WEBHOOK_URL_PLACEHOLDER^$TRAVIS_TMATE_WEBHOOK_URL^g" $config_file
}
__setup_papertrail_rsyslog() {
source /etc/default/tmate-config
local pt_port="${TRAVIS_PAPERTRAIL_REMOTE_PORT}"
if [[ ! "${pt_port}" ]] ; then
return
fi
local match='logs.papertrailapp.com:'
local repl="\*\.\* @logs.papertrailapp.com:${pt_port}"
sed -i "/${match}/s/.*/${repl}/" '/etc/rsyslog.d/65-papertrail.conf'
restart rsyslog || start rsyslog
}
main "$@"