-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtmate-shell
executable file
·34 lines (28 loc) · 1.28 KB
/
tmate-shell
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
#!/usr/bin/env bash
YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh
echo_info "Install 'tmate' via 'brew install tmate'."
TMP_TMATE_SOCKET=$(mktemp -t yplatform.XXXXXXXXXX)
echo_info "tmate socket: ${TMP_TMATE_SOCKET}"
AUTHENTICATED_KEYS=${1:-}
AUTHENTICATED_KEYS_ARG="-a ${AUTHENTICATED_KEYS}"
[[ -n "${AUTHENTICATED_KEYS}" ]] || {
AUTHENTICATED_KEYS_ARG=
echo_warn "No authenticated keys given, thus this session is unrestricted."
echo_info "Consider running"
echo_info "mkdir -p ${HOME}/.ssh"
echo_info "chmod 700 ${HOME}/.ssh"
echo_info "ssh-keygen -q -t ed25519 -a 100 -N '' -C '$(whoami)@$(hostname)' -f ${HOME}/.ssh/id_ed25519"
echo_info "and calling 'tmate-shell ${HOME}/.ssh/id_ed25519.pub' instead."
}
echo_info "authenticated keys: ${AUTHENTICATED_KEYS:-none}"
rm -rf ${TMP_TMATE_SOCKET}
exe tmate -S ${TMP_TMATE_SOCKET} ${AUTHENTICATED_KEYS_ARG} new-session -d "${SHELL} -l"
tmate -S ${TMP_TMATE_SOCKET} wait tmate-ready
while [[ -e ${TMP_TMATE_SOCKET} ]] && tmate -S ${TMP_TMATE_SOCKET} has-session; do
echo
tmate -S ${TMP_TMATE_SOCKET} display -p "#{tmate_ssh}"
# NOTE skip web interface. it's convenient but buggy
# tmate -S ${TMP_TMATE_SOCKET} display -p "#{tmate_web}"
sleep 60
done