shell-host/install/common/remote-desktop.mod

53 lines
1.5 KiB
Modula-2
Raw Normal View History

#!/bin/bash
# module to load some remote desktop server
tigervnc_install () {
local usesudo
[[ $EUID -ne 0 ]] && usesudo=sudo
pass=$1
[[ ! $pass ]] && echo password argument required && return 1
# TODO check for binary and if not go grab it
user=$2
[[ $usesudo ]] && user=${user:-$USER} || user=${user:-$(getent passwd 1000 | cut -f 1 -d ":")}
echo creating password file with $pass for user $user
echo "=========================="
mkdir /home/$user/.vnc
echo $pass | vncpasswd -f > /home/$user/.vnc/passwd
chown -R $user:$user /home/$user/.vnc
chmod 0600 /home/$user/.vnc/passwd
ls -la /home/$user/.vnc/
server=/bin/x0vncserver
# server=/bin/vncserver
service=/etc/systemd/system/tigervnc.service
machine=$(hostname | tr '[:lower:]' '[:upper:]')
echo creating systemd service $service
cat <<EOF | $usesudo tee $service
[Unit]
# https://tigervnc.org/doc/x0vncserver.html
Description=tigervnc remote desktop server
After=multi-user.target
[Service]
Type=simple
# User=${user}
Environment="XAUTHORITY=/var/run/lightdm/root/:0"
Environment="HOME=/home/${user}"
# Environment="USER=${user}"
# -desktop $machine
ExecStart=$server -display :0 -rfbauth /home/${user}/.vnc/passwd
# -localhost no
# Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
cat $service
[[ ! $(cat $service 2>/dev/null) ]] && echo unable to create service file && return 2
$usesudo systemctl daemon-reload
$usesudo systemctl restart tigervnc
$usesudo systemctl enable tigervnc
$usesudo systemctl status tigervnc
}