Merge pull request 'Enhance acquirevnc script' (#1) from rany/vnc:master into master

Reviewed-on: #1
This commit is contained in:
ubergeek 2020-12-19 21:23:14 +00:00
commit bf1e9d4cdb
1 changed files with 15 additions and 12 deletions

View File

@ -1,23 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
USER=$(whoami) USER="$(whoami)"
# get new display # get new display
DISPLAY=0 TAKEN_PORTS=( $(cat /var/lib/vnc/* | sort -n) )
for file in /var/lib/vnc/* ; do [ -f "/var/lib/vnc/${USER}" ] && TAKEN_PORTS=( "${TAKEN_PORTS[@]/$(<"/var/lib/vnc/${USER}")}" )
if [ $(cat $file) -gt $DISPLAY ] ; then DISPLAY=0; for TAKEN_PORT in ${TAKEN_PORTS[@]}; do
DISPLAY=$(cat $file) if [ "$TAKEN_PORT" -le "$DISPLAY" ];then
fi DISPLAY=$((DISPLAY + 1))
fi
done done
let "DISPLAY++" unset TAKEN_PORTS TAKEN_PORT
# add user file # add user file
echo "$DISPLAY" > /var/lib/vnc/${USER} OLD_UMASK="$(umask)"
chmod 644 /var/lib/vnc/${USER} umask 0022
echo "$DISPLAY" > "/var/lib/vnc/${USER}"
umask $OLD_UMASK
PORT=$((DISPLAY + 5900))
unset DISPLAY OLD_UMASK
/usr/local/bin/startvnc /usr/local/bin/startvnc
PORT=$((DISPLAY + 5900))
echo echo
echo "Your port number is ${PORT}; please note it down." echo "Your port number is ${PORT}; please note it down."
echo "You might like to see https://wiki.thunix.net/wiki/vnc for further information." echo "You might like to see https://wiki.thunix.net/wiki/vnc for further information."