-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoVNC
109 lines (93 loc) · 2.66 KB
/
noVNC
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Make bashline configurations.
set -e
RESET='\033[0m'
COLOR='\033[1;32m'
COLOR_ERR='\033[1;31m'
COLOR_WARN='\033[1;33m'
function msg {
echo -e "${COLOR}$(date): $1${RESET}"
}
function msgerr {
echo -e "${COLOR_ERR}$(date): $1${RESET}"
}
function msgwarn {
echo -e "${COLOR_WARN}$(date): $1${RESET}"
}
function fail {
msgerr "Error : $?"
exit 1
}
PORT=0
IP=192.168.127.128:5901
PEM=""
GEN=""
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
PORT) PORT=${VALUE} ;;
IP) IP=${VALUE} ;;
PEM) PEM=${VALUE} ;;
GEN) GEN=${VALUE} ;;
*)
esac
done
MACHINE_IP=$(hostname -I | awk 'NR==1 {print $1}')
INSTALL_PATH=/usr/local/bin
echo "****************************"
echo "* noVNC Shortcut by Yuchen *"
echo "****************************"
if [ "$PORT" = "0" ]
then
SHOWPORT=6080
echo "Default listening port = 6080"
else
SHOWPORT=$PORT
fi
echo "Current container IP = $IP"
echo "---------------------"
echo "Note that you need to replace \"$HOSTNAME\" with \"$MACHINE_IP\" in the URL"
echo " http://$MACHINE_IP:$SHOWPORT/vnc.html?host=$MACHINE_IP&port=$SHOWPORT"
echo "---------------------"
if [ "$PORT" != "0" ]
then
PORT_OPTION="--listen $PORT"
else
PORT_OPTION=""
fi
if [ "x${GEN}" != "x" ]
then
if [ -s ~/vnccerts/${GEN}.pem ]; then
sudo cp -f ~/vnccerts/${GEN}.pem ${INSTALL_PATH}/noVNCbin/utils/websockify/${GEN}.pem || fail
else
if [ -s /etc/ssl/vncssl.cnf ]; then
mkdir -p ~/vnccerts || fail
openssl req -new -x509 -days 365 -nodes -config /etc/ssl/vncssl.cnf -out ~/vnccerts/${GEN}.pem -keyout ~/vnccerts/${GEN}.pem || fail
sudo cp -f ~/vnccerts/${GEN}.pem ${INSTALL_PATH}/noVNCbin/utils/websockify/${GEN}.pem || fail
else
msgerr "Fail to generate the SSL certs, because the config file is not copied to /etc/ssl/".
fi
fi
if [ "x${PEM}" = "x" ]
then
PEM="${INSTALL_PATH}/noVNCbin/utils/websockify/${GEN}.pem"
fi
fi
if [ "x${PEM}" != "x" ]
then
SSL_OPTION="--cert ${PEM} --key ${PEM}"
else
SSL_OPTION=""
fi
if [ -f "${INSTALL_PATH}/noVNCbin/utils/novnc_proxy" ]; then
${INSTALL_PATH}/noVNCbin/utils/novnc_proxy --vnc $IP ${PORT_OPTION} ${SSL_OPTION} || fail
else
if [ -f "${INSTALL_PATH}/noVNCbin/utils/launch.sh" ]; then
${INSTALL_PATH}/noVNCbin/utils/launch.sh --vnc $IP ${PORT_OPTION} ${SSL_OPTION} || fail
else
msgerr "Fail to find the launching script in the current noVNC build, maybe the repository has a wrong version."
exit 1
fi
fi