-xhost +local:
-sed -e 's/#VMNAME#/'$1'/g' ~/s/runvm.xbindkeysrc.template > ~/.xbindkeysrc.template.$1
-xbindkeys -f ~/.xbindkeysrc.template.$1
-/usr/bin/synergyc -f --debug ERROR --name fujivm 10.11.0.1:24800 &
-VirtualBox --startvm $1 --fullscreen
-rm ~/.xbindkeysrc.template.$1
+#!/bin/bash
+
+if [[ $1 == "startx" ]] ; then
+ VMNAME=$2
+ xhost +local:
+ sed -e 's/#VMNAME#/'$VMNAME'/g' ~/bin/runvm.xbindkeysrc.template > ~/.xbindkeysrc.template.$VMNAME
+ xbindkeys -f ~/.xbindkeysrc.template.$VMNAME
+# /usr/bin/synergyc -f --debug ERROR --name fujivm 10.11.0.1:24800 &
+ VirtualBox --startvm $VMNAME --fullscreen
+ rm ~/.xbindkeysrc.template.$VMNAME
+else
+ VMNAME=$1
+ if [[ $2 != "" ]] ; then
+ VMNAME="$(echo $1 | sed -e 's/^'$2'//')"
+ fi
+ reset
+ echo "Security check completed."
+ echo "Continue to boot ${VMNAME}?"
+ read unused
+ echo "Booting ${VMNAME}"
+ startx $0 startx $VMNAME >/tmp/runvm.$VMNAME.log 2>&1
+fi
--- /dev/null
+[Unit]
+Description=%p on %I
+
+[Service]
+Type=simple
+User=jan
+WorkingDirectory=/home/jan/
+ExecStart=-/bin/zsh -c '~/bin/runvm.sh %p runvm'
+ExecStop=-/bin/sh -c 'echo %p ended.'
+StandardInput=tty
+StandardOutput=tty
+TTYPath=/dev/%I
+Restart=always
+RestartSec=15
+
+[Install]
+WantedBy=multi-user.target
+