#!/bin/bash set -e display=:10 interface=0.0.0.0 cert_group=ssl-cert xstartup_script=~/.vnc/xstartup declare -A all_desktop_environments=( [Cinnamon]=cinnamon-session [Mate]="XDG_CURRENT_DESKTOP=MATE dbus-launch --exit-with-session mate-session" [LXDE]=lxsession [Lxqt]=startlxqt [KDE]=startkde [Gnome]="XDG_CURRENT_DESKTOP=GNOME dbus-launch --exit-with-session /usr/bin/gnome-session" [XFCE]=xfce4-session) detected_desktop_environments=() declare -A numbered_desktop_environments debug() { if [ -z "$debug" ]; then return; fi echo "$@" } print_detected_desktop_environments() { declare -i i=1 echo "Please choose Desktop Environment to run:" for detected_de in "${detected_desktop_environments[@]}"; do echo "[$i] $detected_de" numbered_desktop_environments[$i]=$detected_de i+=1 done } detect_desktop_environments() { for de_name in "${!all_desktop_environments[@]}"; do local executable=${all_desktop_environments[$de_name]} executable=($executable) executable=${executable[-1]} if detect_desktop_environment "$de_name" "$executable"; then detected_desktop_environments+=("$de_name") fi done } detect_desktop_environment() { local de_name="$1" local executable="$2" if command -v "$executable" &>/dev/null; then return 0 fi return 1 } de_cmd_from_name() { de_cmd=${all_desktop_environments[$de_name]} } de_name_from_number() { local de_number_to_run="$1" de_name=${numbered_desktop_environments[$de_number_to_run]} } generate_xstartup() { local de_name="$1" de_cmd_from_name cat <<-SCRIPT > "$xstartup_script" #!/bin/sh exec $de_cmd SCRIPT chmod +x "$xstartup_script" } if [[ "$1" = "--help" ]]; then cat >&2 <<-USAGE Usage: `basename $0` [options] -d Debug output -kill Kill vncserver --help show this help USAGE exit fi if [[ "$1" = "-d" ]]; then debug=1 log_option="-log *:stderr:100" fi action=start if [[ "$1" = "-kill" ]]; then action=kill fi if groups | grep -qvw ssl-cert; then cat <<-EOF Can't access TLS certificate. Please add your user to $cert_group via 'addgroup ssl-cert' EOF exit 1 fi if [[ "$action" = "kill" ]]; then vncserver -kill $display exit fi detect_desktop_environments print_detected_desktop_environments read -r de_number_to_run de_name_from_number "$de_number_to_run" debug "You selected $de_name desktop environment" generate_xstartup "$de_name" vncserver $display -interface $interface vncserver -kill $display vncserver $display -depth 24 -geometry 1280x1050 -websocketPort 8443 \ -cert /etc/ssl/certs/ssl-cert-snakeoil.pem \ -key /etc/ssl/private/ssl-cert-snakeoil.key -sslOnly -FrameRate=24 \ -interface $interface -httpd /usr/share/kasmvnc/www $log_option