-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake-systemd-xvnc
executable file
·112 lines (100 loc) · 2.92 KB
/
make-systemd-xvnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#
# Prompts for VNC screen resolutions and builds the appropriate xvnc .socket/.service files
# Must be run as root
#
function askyn() {
local ans
echo -n "$1" '[y/n]? ' ; read $2 ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
[[ ! $EUID -eq 0 ]] && notroot=0 || notroot=1
if [ "$1" == "" ]
then
[ $notroot -eq 0 ] && echo "? You must be root to write to the system" && echo " Or start with 'sudo $0'" && exit
sdir="/etc/systemd/system"
else
sdir="$1"
fi
# Which VNC server is installed?
#
vncsrv=""
extrasw=""
[ -f /usr/bin/Xtightvnc -a -f /usr/bin/Xtigervnc ] && echo "%% Both xtigervnc and xtightvnc are installed; using xtigervnc"
[ -f /usr/bin/Xtightvnc ] && vncsrv="/usr/bin/Xtightvnc"
[ -f /usr/bin/Xtigervnc ] && vncsrv="/usr/bin/Xtigervnc" && extrasw="-noreset -SecurityTypes None"
[ "$vncsrv" == "" ] && echo "? Cannot find either Xtigervnc or Xtightvnc" && echo " Please 'sudo apt install' a VNC Server (tigervnc-standalone-server or tightvncserver)" && exit
echo "% Configuring dynamic VNC to use '$vncsrv'"
#
# See if old xvnc*.socket files exist
#
n=1
if [ -f "$sdir/xvnc0.socket" -o -f "$sdir/xvnc1.socket" ]
then
echo "% xvnc* systemd socket/service pairs already exist"
echo " You can replace them or create new ones at the end of the 'list'"
echo " Enter Y to replace existing files or N to leave existing files and add new socket/service pairs"
if ! askyn " Do you want to replace the existing xvnc* socket/services?"
then
[ -f "$sdir/xvnc0.socket" ] && n=0
while [ -f "$sdir/xvnc$n.socket" ]
do
n=$(($n+1))
done
else
rm -f $sdir/xvnc*.socket $sdir/xvnc*@.service
n=1
fi
fi
echo ""
echo "Enter VNC resolutions as desired in the format WIDTHxHEIGHT (e.g. 1920x1080)"
echo "Each will be assigned a successive VNC port"
echo "Press Enter by itself to finish"
echo ""
while [ 0 ]
do
echo -n "VNC resolution for VNC$n: "
res=$(read ans; echo $ans)
[ "$res" == "" ] && break
echo "% Creating VNC socket/service pair for VNC$n with resolution $res"
port=$((5900+$n))
cat > $sdir/xvnc$n.socket <<EOF
[Unit]
Description=XVNC Server $n
[Socket]
ListenStream=$port
Accept=yes
[Install]
WantedBy=sockets.target
EOF
cat > $sdir/[email protected] <<EOF
[Unit]
Description=XVNC Per-Connection Daemon $n
[Service]
ExecStart=-$vncsrv $extrasw -inetd -query 127.0.0.1 -geometry $res -pn -once
StandardInput=socket
StandardOutput=socket
StandardError=journal
EOF
n=$(($n+1))
done
if [ $notroot -eq 1 ]
then
echo "systemctl daemon-reload"
systemctl daemon-reload
if askyn "Enable and start VNC sockets"
then
for (( i=1; i<$n; i++))
do
echo "systemctl stop xvnc$i.socket"
systemctl stop xvnc$i.socket
echo "systemctl enable --now xvnc$i.socket"
systemctl enable --now xvnc$i.socket
done
else
echo "% You must 'sudo systemctl enable' each of the xvnc sockets to enable them"
fi
fi