-
Notifications
You must be signed in to change notification settings - Fork 1
/
juju_browse_unit.sh
executable file
·51 lines (43 loc) · 1.13 KB
/
juju_browse_unit.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 -eux
L_PORT=8080
R_PORT=443
JUJU_UNIT=juju-gui
SSH_HOST=YOUR_HOST
SSH_PORT=22
SSH_USER=ubuntu
SSH_CONTROL=`basename $0`-control
PROTO=http
case $R_PORT in
443)
PROTO=https
;;
esac
echo "Finding the IP address for ${JUJU_UNIT}"
UNIT_IP=`ssh -l ${SSH_USER} -p ${SSH_PORT} ${SSH_HOST} juju status ${JUJU_UNIT} | grep public-address | head -1 | awk '{print $2}'`
if [[ -z ${UNIT_IP} ]]; then
echo "No IP address found for ${JUJU_UNIT}"
exit 1
fi
echo "Creating tunnel localhost:${L_PORT}->${UNIT_IP}:${R_PORT}"
ssh -M -S ${SSH_CONTROL} -fnNT -L ${L_PORT}:${UNIT_IP}:${R_PORT} -l ${SSH_USER} -p ${SSH_PORT} ${SSH_HOST}
echo "Opening browser to local tunnel"
open "${PROTO}://localhost:${L_PORT}"
echo "Close tunnel?"
select i in "yes" "no"; do
case $i in
yes)
echo "Closing tunnel"
ssh -S ${SSH_CONTROL} -O exit -l ${SSH_USER} -p ${SSH_PORT} ${SSH_HOST}
break
;;
no)
echo "Tunnel Status:"
ssh -S ${SSH_CONTROL} -O check -l ${SSH_USER} -p ${SSH_PORT} ${SSH_HOST}
echo "Close tunnel?"
;;
*)
echo "Pick 1..2"
echo "Close tunnel?"
;;
esac
done