From 5991c334b7dd3f6e7a06abd9ce9daeb6d069ddaa Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Tue, 14 Jul 2020 13:07:30 +0200
Subject: [PATCH] Skripte

---
 scripts/README                         |  34 ++++
 scripts/autojitsi                      | 161 ++++++++++++++++++
 scripts/autovnc                        | 220 +++++++++++++++++++++++++
 scripts/botamusique-pgerwinski.service |  13 ++
 scripts/jitsibot@.service              |  13 ++
 scripts/novnc@.service                 |  11 ++
 scripts/vncbot@.service                |  13 ++
 scripts/vncserver                      |  58 +++++++
 scripts/vncserver@.service             |  13 ++
 9 files changed, 536 insertions(+)
 create mode 100644 scripts/README
 create mode 100755 scripts/autojitsi
 create mode 100755 scripts/autovnc
 create mode 100644 scripts/botamusique-pgerwinski.service
 create mode 100644 scripts/jitsibot@.service
 create mode 100644 scripts/novnc@.service
 create mode 100644 scripts/vncbot@.service
 create mode 100755 scripts/vncserver
 create mode 100644 scripts/vncserver@.service

diff --git a/scripts/README b/scripts/README
new file mode 100644
index 0000000..28fdcbb
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,34 @@
+VNC without SSH tunnel, 14.07.2020, 12:42:42
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+To start a listening VNC client for VNC channel $x,
+open port 550$x and run the command:
+
+  DISPLAY=:$x ssvncviewer -listen &
+
+CVH-Bot, 14.07.2020, 12:42:51
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+To install CVH-Bot,
+ - install the Go language,
+ - create a directory $HOME/go/src,
+ - "git clone" the sources from https://gitlab.cvh-server.de/jvongehr/cvh-bot.git
+   to that directory,
+ - use "go get <...>", for instance
+     go get -v layeh.com/gopus
+   to install the required libraries,
+ - use "go build" to compile it.
+After that, use "./mumbleBot" to run it.
+
+Connecting Jitsi Meet to Mumble, 14.07.2020, 12:44:07
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+To connect the sound of Jitsi Meet connected to VNC channel $x
+to a Mumble channel,
+ - create ALSA loopback devices: modprobe -v snd-aloop,
+ - start the Jitsi Meet cliend used by autojits,
+   configure it to use the ALSA loopback device hw:0,0 for input and output
+   and close it again,
+ - manually start a Mumble client in the VNC display
+     DISPLAY=$x mumble
+   and configure it to to use the ALSA loopback device hw:0,1 for input and output,
+   make the audio input continuous (rather than push-to-talk etc.), then let it run.
+After that, this Mumble client will relay the audio stream of a Jitsi Meet session
+to Mumble, just like VNC is relaying its video stream to noVNC.
diff --git a/scripts/autojitsi b/scripts/autojitsi
new file mode 100755
index 0000000..9ab1f2b
--- /dev/null
+++ b/scripts/autojitsi
@@ -0,0 +1,161 @@
+#!/bin/bash
+
+url="https://jitsi.cvh-server.de"
+room="vnc$1"
+x="$1"
+y="$(($1 + 6))"
+browser="/usr/bin/chromium"
+user_data_dir="/home/pgerwinski/chromium$1"
+jitsi_width=1280
+jitsi_height=720
+jitsi_x=0
+jitsi_y=0
+jitsi_resolution="$jitsi_width"x"$jitsi_height"
+
+time=0
+lastrun=0
+counter=0
+bots=0
+bot_pid=0
+
+if [ "$x" = "6" ]; then
+  enable_experimental_features=true
+  vncviewer="ssvncviewer"
+  browser="/home/pgerwinski/jitsi-meet-x86_64.AppImage"
+  user_data_dir="/home/pgerwinski/jitsi$1"
+  jitsi_max_width="$jitsi_width"
+  jitsi_max_height="$jitsi_height"
+else
+  enable_experimental_features=false
+fi
+
+switch_to_resolution ()
+{
+  x="$1"
+  y="$2"
+  resolution="$3"
+  width=$(echo $resolution | cut -d x -f 1)
+  height=$(echo $resolution | cut -d x -f 2)
+  half_width=$((width / 2))
+  half_height=$((height / 2))
+  half_resolution="$half_width"x"$half_height"
+  echo "switch_to_resolution: $width"x"$height, $half_width"x"$half_height"
+
+  if DISPLAY=:"$x" xrandr | grep -q "$resolution"; then
+    echo "standard mode: $resolution"
+  else
+    timing=$(
+      gtf $width $height 60 \
+        | grep Modeline \
+        | (
+            read modeline name timing
+            echo $timing
+          )
+    )
+    echo DISPLAY=:$x xrandr --output VNC-0 --newmode "$resolution" $timing
+    DISPLAY=:$x xrandr --output VNC-0 --newmode "$resolution" $timing
+    DISPLAY=:$x xrandr --addmode VNC-0 "$resolution"
+  fi
+  DISPLAY=:"$x" xrandr --output VNC-0 --mode "$resolution" 2>&1
+  DISPLAY=:"$x" swarp 0 0
+
+  if DISPLAY=:"$y" xrandr | grep -q "$half_resolution"; then
+    echo "standard mode: $resolution"
+  else
+    timing=$(
+      gtf $half_width $half_height 60 \
+        | grep Modeline \
+        | (
+            read modeline name timing
+            echo $timing
+          )
+    )
+    echo DISPLAY=:$y xrandr --output VNC-0 --newmode "$half_resolution" $timing
+    DISPLAY=:$y xrandr --output VNC-0 --newmode "$half_resolution" $timing
+    DISPLAY=:$y xrandr --addmode VNC-0 "$half_resolution"
+  fi
+  DISPLAY=:"$y" xrandr --output VNC-0 --mode "$half_resolution" 2>&1
+  DISPLAY=:"$y" swarp 0 0
+}
+
+echo "$0 $* running ..."
+while read line; do \
+  if echo "$line" | grep -q "^Jicofo .* Member $room@muc\.meet\.jitsi/[0-9a-f]* joined\.$"; then
+    echo "counter = $counter, bots = $bots; member joined ..."
+    counter=$((counter + 1))
+    if [ $((counter - bots)) -gt "0" ] && [ "$bot_pid" = "0" ]; then
+      echo "starting bot ..."
+      server_resolution=$(DISPLAY=:"$x" xrandr | grep '\*' | awk {'print $1'})
+      echo "server resolution: $server_resolution / $server_half_resolution"
+      if $enable_experimental_features; then
+        vnc_resolution=$(DISPLAY=:"$x" xwininfo -root -children \
+                         | grep "$vncviewer" \
+                         | grep -o " [0-9x+-]*  * [0-9+-]* *$" \
+                         | sed -e 's/^ *//' -e 's/+.*$//')
+        if [ -z "$vnc_resolution" ]; then
+          jitsi_width="$jitsi_max_width"
+          jitsi_height="$jitsi_max_height"
+          jitsi_x=0
+          jitsi_y=0
+          switch_to_resolution "$x" "$y" "$jitsi_resolution"
+        else
+          vnc_width=$(echo $vnc_resolution | cut -d "x" -f 1)
+          vnc_height=$(echo $vnc_resolution | cut -d "x" -f 2)
+#          jitsi_width=415
+#          jitsi_height=311
+          jitsi_width=512
+          jitsi_height=384
+          jitsi_x=$((vnc_width - jitsi_width))
+          jitsi_y=$((vnc_height - jitsi_height))
+        fi
+        echo HOME="$user_data_dir" URL="$url/$room" DISPLAY=:"$x" "$browser" --no-sandbox \&
+        HOME="$user_data_dir" URL="$url/$room" DISPLAY=:"$x" "$browser" --no-sandbox &
+      else
+        switch_to_resolution "$x" "$y" "$jitsi_resolution"
+        echo DISPLAY=:"$x" "$browser" --user-data-dir="$user_data_dir" --start-fullscreen "$url/$room" \&
+        DISPLAY=:"$x" "$browser" --user-data-dir="$user_data_dir" --start-fullscreen "$url/$room" &
+      fi
+      bot_pid="$!"
+      bots=$((bots + 1))
+      echo "... done: $bot_pid."
+      sleep 2s
+      for window_id in $(DISPLAY=:"$x" xwininfo -root -children \
+                        | grep "Jitsi Meet" \
+                        | cut -b 6-14); do
+        echo "adjusting bot window ..."
+        if $enable_experimental_features; then
+          # connect to Mumble
+          sleep 2s
+          echo "unmuting ..."
+          DISPLAY=:"$x" xdotool windowsize "$window_id" "$jitsi_max_width" "$jitsi_max_height"
+          DISPLAY=:"$x" xdotool windowmove "$window_id" 0 0
+          DISPLAY=:"$x" xdotool mousemove  1267 632
+          DISPLAY=:"$x" xdotool click 1
+#          DISPLAY=:"$x" xdotool mousemove 575 680
+#          DISPLAY=:"$x" xdotool click 1
+        fi
+        DISPLAY=":$x" xdotool windowsize "$window_id" "$jitsi_width" "$jitsi_height"
+        DISPLAY=":$x" xdotool windowmove "$window_id" "$jitsi_x" "$jitsi_y"
+        DISPLAY=:"$x" xdotool mousemove $((jitsi_x + jitsi_width)) $((jitsi_y + jitsi_height / 3))
+      echo "... done: $window_id."
+      done
+    fi
+  elif echo "$line" | grep -q "^Jicofo .* Member $room@muc.meet.jitsi/[0-9a-f]* is leaving$"; then
+    echo "counter = $counter, bots = $bots; member is leaving ..."
+    if [ "$counter" -gt "0" ]; then
+      counter=$((counter - 1))
+    fi
+    if [ "$bot_pid" = "0" ] && [ "$bots" -gt "0" ]; then
+      bots=$((bots - 1))
+    fi
+    if [ "$counter" -le "1" ] && [ "$bot_pid" -ne "0" ]; then
+      echo "killing bot $bot_pid ..."
+      kill "$bot_pid"
+      switch_to_resolution "$x" "$y" "$server_resolution"
+      bot_pid=0
+      bots=$((bots - 1))
+      echo "... done."
+    fi
+  fi
+done
+echo "Bye!"
diff --git a/scripts/autovnc b/scripts/autovnc
new file mode 100755
index 0000000..a8138af
--- /dev/null
+++ b/scripts/autovnc
@@ -0,0 +1,220 @@
+#!/bin/bash
+
+vncviewer="ssvncviewer"
+vncopts="-autopass -viewonly -depth 24 -compresslevel 9 -quality 9 \
+         -geometry "
+#         -encodings raw,copyrect,tight,hextile,zlib,corre,rre
+vncserver="tigervncserver"
+vncserveropts="-depth 24"  # add "-localhost no" to make it listen on all IPs
+testfile="$HOME/vnc-testbild.pdf"
+browser="chromium"
+HOME="/home/pgerwinski"
+max_resolution="1920x1080"
+
+x="$1"
+case "$x" in
+  [1-6])
+    true
+    ;;
+  *)
+    echo "usage: $0 <channel>"
+    exit 1
+    ;;
+esac
+
+y=$((x + 6))
+z=$((x + 9500))
+
+case "$x" in
+  1) tunnel_port=5913; password="hsSS2020";;
+  2) tunnel_port=5917; password="student" ;;
+  3) tunnel_port=5916; password="cvh2020" ;;
+  4) tunnel_port=5914; password="student" ;;
+  5) tunnel_port=5915; password="student" ;;
+  6) tunnel_port=5918; password="testcvh" ;;
+esac
+
+if [ "$x" = "6" ]; then
+  enable_experimental_features=true
+  jitsi_max_width=1280
+  jitsi_max_height=720
+  jitsi_min_width=512
+  jitsi_min_height=384
+else
+  enable_experimental_features=false
+fi
+
+incoming_channel=$(echo "$tunnel_port" | cut -b 3-4)
+echo "channel = $x, tunnel_port = $tunnel_port, incoming_channel = $incoming_channel"
+
+switch_to_resolution ()
+{
+  x="$1"
+  y="$2"
+  resolution="$3"
+  width=$(echo $resolution | cut -d x -f 1)
+  height=$(echo $resolution | cut -d x -f 2)
+  half_width=$((width / 2))
+  half_height=$((height / 2))
+  half_resolution="$half_width"x"$half_height"
+  echo "switch_to_resolution: $width"x"$height, $half_width"x"$half_height"
+
+  if DISPLAY=:"$x" xrandr | grep -q "$resolution"; then
+    echo "standard mode: $resolution"
+  else
+    timing=$(
+      gtf $width $height 60 \
+        | grep Modeline \
+        | (
+            read modeline name timing
+            echo $timing
+          )
+    )
+    echo DISPLAY=:$x xrandr --output VNC-0 --newmode "$resolution" $timing
+    DISPLAY=:$x xrandr --output VNC-0 --newmode "$resolution" $timing
+    DISPLAY=:$x xrandr --addmode VNC-0 "$resolution"
+  fi
+  DISPLAY=:"$x" xrandr --output VNC-0 --mode "$resolution" 2>&1
+  DISPLAY=:"$x" swarp 0 0
+
+  if DISPLAY=:"$y" xrandr | grep -q "$half_resolution"; then
+    echo "standard mode: $resolution"
+  else
+    timing=$(
+      gtf $half_width $half_height 60 \
+        | grep Modeline \
+        | (
+            read modeline name timing
+            echo $timing
+          )
+    )
+    echo DISPLAY=:$y xrandr --output VNC-0 --newmode "$half_resolution" $timing
+    DISPLAY=:$y xrandr --output VNC-0 --newmode "$half_resolution" $timing
+    DISPLAY=:$y xrandr --addmode VNC-0 "$half_resolution"
+  fi
+  DISPLAY=:"$y" xrandr --output VNC-0 --mode "$half_resolution" 2>&1
+  DISPLAY=:"$y" swarp 0 0
+}
+
+while true; do
+
+  just_started=false
+  if nc -z localhost "$tunnel_port"; then
+    process=$(ps aux \
+                | grep "$vncviewer.*:$incoming_channel" \
+                | grep -v "grep")
+    if [ -z "$process" ]; then
+      vnc_answer=$(echo sorry | timeout 5 nc localhost "$tunnel_port")
+      case "$vnc_answer" in
+        "RFB "*)
+          echo "starting vncviewer ..."
+          switch_to_resolution "$x" "$y" "$max_resolution"
+          channel_directory="$HOME/vnc$x"
+
+          (echo "$password" \
+             | DISPLAY=:"$x" HOME="$x_directory" \
+             "$vncviewer" :"$incoming_channel" -autopass $vncopts+0+0 2>&1) &
+          just_started=true
+          DISPLAY=:"$x" swarp 0 0
+          sleep 1
+          echo "... done."
+          ;;
+        *)
+          echo -e "SSH tunnel open, VNC closed (answer = \"$vnc_answer\")."
+          ;;
+      esac
+    fi
+  fi
+
+  Ssvnc=$(DISPLAY=:"$x" xwininfo -root -children | grep "Ssvnc")
+  ssvnc=$(DISPLAY=:"$x" xwininfo -root -children | grep "ssvnc")
+  if [ -n "$Ssvnc" ] && [ -z "$ssvnc" ]; then
+    echo "killing hanging ssvncviewers ..."
+    for id in $(DISPLAY=:"$x" xwininfo -root -children \
+                  | grep "Ssvnc" \
+                  | awk '{print $1}'); do
+      echo "window $id ..."
+      DISPLAY=:"$x" xkill -frame -id "$id"
+    done
+    just_started=false
+    sleep 1
+    echo "... done."
+  elif [ -n "$ssvnc" ]; then
+    if echo "$ssvnc" | grep -q "+0+0$"; then
+      true
+    else
+      echo "moving VNC viewer to top left"
+      windowid=$(echo "$ssvnc" | awk '{ print $1; }')
+      DISPLAY=:"$x" xdotool windowmove "$windowid" 0 0
+    fi
+  fi
+
+  server_resolution=$(DISPLAY=:"$x" xrandr | grep '\*' | awk '{print $1'})
+  vnc_resolution=$(DISPLAY=:"$x" xwininfo -root -children \
+                   | grep "$vncviewer" \
+                   | grep -o " [0-9x+-]*  * [0-9+-]* *$" \
+                   | sed -e 's/^ *//' -e 's/+.*$//')
+  jitsi_resolution=$(DISPLAY=:"$x" xwininfo -root -children \
+                     | grep "Jitsi Meet" \
+                     | grep -o " [0-9x+-]*  * [0-9+-]* *$" \
+                     | sed -e 's/^ *//' -e 's/+.*$//')
+  if [ -z "$server_resolution" ]; then
+    echo "problem: cannot determine server resolution"
+  elif [ -z "$vnc_resolution" ]; then
+    if [ -z "$jitsi_resolution" ]; then
+      if [ "$server_resolution" != "$max_resolution" ]; then
+        echo "No VNC or Jitsi Meet session found. Resetting resolution ..."
+        switch_to_resolution "$x" "$y" "$max_resolution"
+      fi
+    else
+      if [ "$server_resolution" != "$jitsi_resolution" ]; then
+        echo "No VNC session found, but a Jitsi Meet session. Adjusting resolution."
+        if $enable_experimental_features; then
+          for window_id in $(DISPLAY=:"$x" xwininfo -root -children \
+                            | grep "Jitsi Meet" \
+                            | cut -b 6-14); do
+            DISPLAY=":$x" xdotool windowsize "$window_id" "$jitsi_max_width" "$jitsi_max_height"
+            DISPLAY=":$x" xdotool windowmove "$window_id" 0 0
+            jitsi_resolution="$jitsi_max_width"x"$jitsi_max_height"
+          done
+        fi
+        switch_to_resolution "$x" "$y" "$jitsi_resolution"
+      fi
+    fi
+  elif $just_started; then
+    if [ "$server_resolution" = "$vnc_resolution" ]; then
+      echo "Server resolution already matches the new VNC. Warping cursor."
+      DISPLAY=:"$x" swarp 0 0
+    else
+      echo "Adjusting resolution for new VNC ..."
+      switch_to_resolution "$x" "$y" "$vnc_resolution"
+    fi
+    if $enable_experimental_features; then
+      vnc_width=$(echo $vnc_resolution | cut -d "x" -f 1)
+      vnc_height=$(echo $vnc_resolution | cut -d "x" -f 2)
+      jitsi_x=$((vnc_width - jitsi_min_width))
+      jitsi_y=$((vnc_height - jitsi_min_height))
+      for window_id in $(DISPLAY=:"$x" xwininfo -root -children \
+                        | grep "Jitsi Meet" \
+                        | cut -b 6-14); do
+        DISPLAY=":$x" xdotool windowsize "$window_id" "$jitsi_min_width" "$jitsi_min_height"
+        DISPLAY=":$x" xdotool windowmove "$window_id" "$jitsi_x" "$jitsi_y"
+        DISPLAY=":$x" xdotool windowraise "$window_id"
+      done
+    fi
+  elif [ -z "$jitsi_resolution" ] && [ "$server_resolution" != "$vnc_resolution" ]; then
+    sleep 2s
+    jitsi_resolution=$(DISPLAY=:"$x" xwininfo -root -children \
+                       | grep "Jitsi Meet" \
+                       | grep -o " [0-9x+-]*  * [0-9+-]* *$" \
+                       | sed -e 's/^ *//' -e 's/+.*$//')
+    if [ -z "$jitsi_resolution" ]; then
+      echo "Adjusting resolution for old VNC ..."
+      switch_to_resolution "$x" "$y" "$vnc_resolution"
+    else
+      echo "There seems to be a Jitsi Meet session just starting. Waiting for it."
+    fi
+  fi
+  sleep 2
+
+done
diff --git a/scripts/botamusique-pgerwinski.service b/scripts/botamusique-pgerwinski.service
new file mode 100644
index 0000000..5e713e8
--- /dev/null
+++ b/scripts/botamusique-pgerwinski.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=botamusique Peter Gerwinski
+After=syslog.target network.target
+
+[Service]
+Type=simple
+User=pgerwinski
+ExecStart=/usr/local/bin/botamusique --config /home/pgerwinski/.config/botamusique/configuration.ini
+Restart=always
+RestartSec=15
+
+[Install]
+WantedBy=multi-user.target
diff --git a/scripts/jitsibot@.service b/scripts/jitsibot@.service
new file mode 100644
index 0000000..f9a4d37
--- /dev/null
+++ b/scripts/jitsibot@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Jitsi-Bot %i
+After=syslog.target apache2.target novnc@%i.target
+
+[Service]
+Type=simple
+User=root
+WorkingDirectory=/tmp
+ExecStart=/usr/local/bin/jitsibot %i
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/scripts/novnc@.service b/scripts/novnc@.service
new file mode 100644
index 0000000..8386606
--- /dev/null
+++ b/scripts/novnc@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description = start noVNC service %i
+After=syslog.target network.target
+
+[Service]
+Type=simple
+User=novnc
+ExecStart = /usr/local/sbin/hsbo_novnc %i
+
+[Install]
+WantedBy=multi-user.target
diff --git a/scripts/vncbot@.service b/scripts/vncbot@.service
new file mode 100644
index 0000000..6e8ba48
--- /dev/null
+++ b/scripts/vncbot@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=VNC-Bot %i
+After=syslog.target apache2.target vncserver@%i.target
+
+[Service]
+Type=simple
+User=pgerwinski
+WorkingDirectory=/home/pgerwinski
+ExecStart=/home/pgerwinski/autovnc %i
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/scripts/vncserver b/scripts/vncserver
new file mode 100755
index 0000000..92f5fb4
--- /dev/null
+++ b/scripts/vncserver
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+vncserver="tigervncserver"
+vncserveropts="-depth 24"  # add "-localhost no" to make it listen on all IPs
+testfile="$HOME/vnc-testbild.pdf"
+HOME="/home/pgerwinski"
+max_resolution="1920x1080"
+half_resolution="960x540"
+
+x="$1"
+case "$x" in
+  [1-6])
+    true
+    ;;
+  *)
+    echo "usage: $0 <channel>"
+    exit 1
+    ;;
+esac
+
+y=$((x + 6))
+z=$((x + 9500))
+
+cleanup ()
+{
+  HOME=$HOME/vnc$x "$vncserver" -kill :$x
+  HOME=$HOME/vnc$y "$vncserver" -kill :$y
+}
+
+trap cleanup exit
+
+HOME=$HOME/vnc$x "$vncserver" :$x $vncserveropts -geometry $max_resolution
+HOME=$HOME/vnc$y "$vncserver" :$y $vncserveropts -geometry $half_resolution
+sleep 2
+echo "Setting up full-resolution channel ..."
+DISPLAY=:$x xrandr --output VNC-0 --newmode 1916x1056  168.93  1920 2040 2248 2576  1056 1057 1060 1093  -HSync +Vsync
+DISPLAY=:$x xrandr --addmode VNC-0 1916x1056
+DISPLAY=:$x xrandr --output VNC-0 --newmode 1504x1000  125.19  1504 1600 1760 2016  1000 1001 1004 1035  -HSync +Vsync
+DISPLAY=:$x xrandr --addmode VNC-0 1504x1000
+DISPLAY=:$x xsetroot -cursor_name arrow
+DISPLAY=:$x swarp 10000 10000
+(HOME=$HOME/vnc$x DISPLAY=:$x xpdf -fullscreen "$testfile" $x &)
+(DISPLAY=:$x HOME=~/vnc$x/.vnc x11vnc -xrandr -localhost -scale 1/2 -rfbport $z &)
+sleep 10
+echo "Setting up half-resolution channel ..."
+DISPLAY=:$x xrandr --output VNC-0 --newmode 958x528  39.91  960 992 1088 1216  528 529 532 547  -HSync +Vsync
+DISPLAY=:$x xrandr --addmode VNC-0 960x528
+DISPLAY=:$y xrandr --output VNC-0 --newmode 752x500  29.34  752 776 848 944  500 501 504 518  -HSync +Vsync
+DISPLAY=:$y xrandr --addmode VNC-0 752x500
+DISPLAY=:$y xrandr --output VNC-0 --newmode 512x384  14.90  512 520 568 624  384 385 388 398  -HSync +VSync
+DISPLAY=:$y xrandr --addmode VNC-0 512x384
+DISPLAY=:$y xsetroot -cursor_name arrow
+DISPLAY=:$y swarp 10000 10000
+(DISPLAY=:$y xtightvncviewer -passwd $HOME/vnc$y/.vnc/passwd -depth 24 -geometry $half_resolution+0+0 :$z &)
+
+while true; do
+  sleep 1h
+done
diff --git a/scripts/vncserver@.service b/scripts/vncserver@.service
new file mode 100644
index 0000000..e4e1320
--- /dev/null
+++ b/scripts/vncserver@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=VNC-Server %i
+After=syslog.target apache2.target
+
+[Service]
+Type=simple
+User=pgerwinski
+WorkingDirectory=/home/pgerwinski
+ExecStart=/home/pgerwinski/vncserver %i
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
-- 
GitLab