2020-12-24 20:54:58 +01:00
|
|
|
#!/bin/bash
|
|
|
|
### every exit != 0 fails the script
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# should also source $STARTUPDIR/generate_container_user
|
|
|
|
source $HOME/.bashrc
|
|
|
|
|
|
|
|
## correct forwarding of shutdown signal
|
|
|
|
cleanup () {
|
|
|
|
kill -s SIGTERM $!
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
trap cleanup SIGINT SIGTERM
|
|
|
|
|
2021-01-07 11:10:04 +01:00
|
|
|
detect_www_dir() {
|
|
|
|
local package_www_dir="/usr/share/kasmvnc/www"
|
|
|
|
if [[ -d "$package_www_dir" ]]; then
|
|
|
|
package_www_dir_option="-httpd $package_www_dir"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-14 11:15:17 +01:00
|
|
|
detect_cert_location() {
|
|
|
|
local tarball_cert="$HOME/.vnc/self.pem"
|
2021-02-12 06:11:27 +01:00
|
|
|
local deb_cert="/etc/ssl/certs/ssl-cert-snakeoil.pem"
|
|
|
|
local deb_key="/etc/ssl/private/ssl-cert-snakeoil.key"
|
|
|
|
local rpm_cert="/etc/pki/tls/private/kasmvnc.pem"
|
2021-01-14 11:15:17 +01:00
|
|
|
|
2021-02-12 06:11:27 +01:00
|
|
|
if [[ -f "$deb_cert" ]]; then
|
|
|
|
cert_option="-cert $deb_cert -key $deb_key"
|
|
|
|
elif [[ -f "$rpm_cert" ]]; then
|
|
|
|
cert_option="-cert $rpm_cert"
|
2021-01-14 11:15:17 +01:00
|
|
|
else
|
2021-01-20 11:56:50 +01:00
|
|
|
cert_option="-cert $tarball_cert"
|
2021-01-14 11:15:17 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:54:58 +01:00
|
|
|
## resolve_vnc_connection
|
|
|
|
VNC_IP=$(hostname -i)
|
|
|
|
|
|
|
|
# first entry is control, second is view (if only one is valid for both)
|
|
|
|
mkdir -p "$HOME/.vnc"
|
|
|
|
PASSWD_PATH="$HOME/.vnc/passwd"
|
2021-02-25 11:13:32 +01:00
|
|
|
kasmvncpasswd -w -u $VNC_USER $HOME/.kasmpasswd
|
2020-12-24 20:54:58 +01:00
|
|
|
chmod 0600 $HOME/.kasmpasswd
|
|
|
|
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $HOME/.vnc/self.pem -out $HOME/.vnc/self.pem -subj "/C=US/ST=VA/L=None/O=None/OU=DoFu/CN=kasm/emailAddress=none@none.none"
|
|
|
|
|
|
|
|
vncserver :1 -interface 0.0.0.0
|
|
|
|
vncserver -kill :1
|
|
|
|
|
|
|
|
if [[ -f $PASSWD_PATH ]]; then
|
|
|
|
rm -f $PASSWD_PATH
|
|
|
|
fi
|
|
|
|
|
|
|
|
#echo "$VNC_PW" | vncpasswd -f > $PASSWD_PATH
|
|
|
|
#echo "$VNC_VIEW_ONLY_PW" | vncpasswd -f >> $PASSWD_PATH
|
|
|
|
#chmod 600 $PASSWD_PATH
|
|
|
|
|
|
|
|
unset VNC_VIEW_ONLY_PW
|
|
|
|
unset VNC_PW
|
|
|
|
|
|
|
|
if [[ $DEBUG == true ]]; then
|
|
|
|
echo -e "\n------------------ start VNC server ------------------------"
|
|
|
|
echo "remove old vnc locks to be a reattachable container"
|
|
|
|
fi
|
|
|
|
vncserver -kill $DISPLAY &> $HOME/.vnc/vnc_startup.log \
|
|
|
|
|| rm -rfv /tmp/.X*-lock /tmp/.X11-unix &> $HOME/.vnc/vnc_startup.log \
|
|
|
|
|| echo "no locks present"
|
|
|
|
|
2021-01-07 11:10:04 +01:00
|
|
|
|
|
|
|
detect_www_dir
|
2021-01-14 11:15:17 +01:00
|
|
|
detect_cert_location
|
2021-01-07 11:10:04 +01:00
|
|
|
|
2020-12-24 20:54:58 +01:00
|
|
|
echo -e "start vncserver with param: VNC_COL_DEPTH=$VNC_COL_DEPTH, VNC_RESOLUTION=$VNC_RESOLUTION\n..."
|
2021-02-25 11:14:50 +01:00
|
|
|
vncserver $DISPLAY -depth $VNC_COL_DEPTH -geometry $VNC_RESOLUTION -FrameRate=$MAX_FRAME_RATE -websocketPort $VNC_PORT $cert_option -sslOnly -interface 0.0.0.0 $VNCOPTIONS $package_www_dir_option #-log *:stderr:100 #&> $STARTUPDIR/no_vnc_startup.log
|
2020-12-24 20:54:58 +01:00
|
|
|
|
|
|
|
PID_SUN=$!
|
|
|
|
|
|
|
|
echo -e "start window manager\n..."
|
|
|
|
$STARTUPDIR/window_manager_startup.sh #&> $STARTUPDIR/window_manager_startup.log
|
|
|
|
|
|
|
|
## log connect options
|
|
|
|
echo -e "\n\n------------------ VNC environment started ------------------"
|
|
|
|
echo -e "\nVNCSERVER started on DISPLAY= $DISPLAY \n\t=> connect via VNC viewer with $VNC_IP:$VNC_PORT"
|
|
|
|
echo -e "\nnoVNC HTML client started:\n\t=> connect via http://$VNC_IP:$NO_VNC_PORT/?password=...\n"
|
|
|
|
echo "WEB PID: $PID_SUB"
|
|
|
|
|
|
|
|
# tail vncserver logs
|
|
|
|
tail -f $HOME/.vnc/*$DISPLAY.log &
|
|
|
|
|
|
|
|
eval "$@"
|
|
|
|
|
|
|
|
wait $PID_SUB
|
|
|
|
|
|
|
|
echo "Exiting Kasm container"
|