VNC Server on Clear Linux

I tried VNC Server. It works great. The following is not officially supported, but steps taken to installing VNC Server on Clear Linux.

Download VNC Server (Generic script x64) from https://www.realvnc.com/.

cd ~/Downloads
tar xf VNC-Server-7.0.1-Linux-x64-ANY.tar.gz
cd VNC-Server-7.0.1-Linux-x64

I created a wrapper script named cl_vncinstall.sh. That modifies vncinstall and vncinitconfig for compatibility on Clear Linux. Be sure, you’re in the VNC-Server-7.0.1-Linux-x64 folder. In a nutshell, this sets paths to /usr/local, disables automatic VNC updates (that will not work), removes selinux bits, and replaces xterm with gnome-session.

tee "cl_vncinstall.sh" >/dev/null <<'EOF'
#!/bin/bash

# Make backups.
[[ -f vncinstall.orig    ]] || cp -a vncinstall    vncinstall.orig
[[ -f vncinitconfig.orig ]] || cp -a vncinitconfig vncinitconfig.orig

# Vncviewer is not included in the VNC Server tar file.
# Disable SELinux installation bits.
# Update paths.
sed -i \
  -e 's!vncviewer vncserver-x11!vncserver-x11!' \
  -e 's!installSELinux=1!installSELinux=0!' \
  -e 's!dst=/usr/bin!dst=/usr/local/bin!' \
  -e 's!lib=/usr/lib!lib=/usr/local/lib!' \
  -e 's!mandst=/usr/share/man!mandst=/usr/local/share/man!' \
  -e 's!cupsdst=/usr/lib/cups!cupsdst=/etc/cups!' \
  -e 's!share=/usr/share!share=/usr/local/share!' \
vncinstall

# Update vncinitconfig.
sed -i \
  -e 's!cups_backend_dir=/usr/lib/cups/backend!cups_backend_dir=/etc/cups/backend!' \
  -e 's!init_updates=1!init_updates=0!' \
  -e 's!init_firewalld=1!init_firewalld=0!' \
  -e 's!init_seLinux=1!init_seLinux=0!' \
  -e 's!libvnc=/usr/lib/vnc!libvnc=/usr/local/lib/vnc!' \
  -e 's!libsecurity=.*$!libsecurity=/usr/lib64/security!' \
  -e 's!share=/usr/share!share=/usr/local/share!' \
  -e 's!/usr/lib/systemd/system!/etc/systemd/system!' \
  -e 's!ExecStart=/usr/bin!ExecStart=/usr/local/bin!' \
  -e 's!XTERM_COMMAND=.*$!gnome-session!' \
  -e '/Notice: the installed init template/d' \
  -e '/^$1 is not installed in $bin/d' \
  -e '/pam_selinux\.so/d' \
vncinitconfig

# Remove sed backups.
rm -f vncinstalle vncinitconfige

# Make installation paths.
sudo mkdir -p /etc/cups/backend
sudo mkdir -p /etc/pam.d
sudo mkdir -p /etc/systemd/system
sudo mkdir -p /usr/local/bin
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/share/man/man1
sudo mkdir -p /usr/local/share/vnc
sudo ln -sf /usr/local/share/vnc /usr/share/

# Install x11-server x11-tools bundles if missing.
installed_bundles=$(sudo swupd bundle-list | grep '^ - ' | sed 's/$/ /g')
add_list=""
for bundle_name in x11-server x11-tools; do
  if [[ ! ${installed_bundles} == *" ${bundle_name} "* ]]; then
    add_list+=" ${bundle_name}"
  fi
done
if [[ -n ${add_list} ]]; then
  echo "Installing $add_list..."
  sudo swupd bundle-add --quiet $add_list || exit $?
fi

# Install VNC Server.
sudo ./vncinstall
EOF

Run the wrapper script to install VNC Server.

bash cl_vncinstall.sh

How to use VNC Server is beyond the scope of this thread. This topic was created for folks familiar with VNC Server. You will need VNC Viewer on the client machine.

VNC Server has two modes (Service and Virtual). No further action is needed for VNC Service mode. Simply start the service. You will need to create an account at realvnc.com to get set up. The trial period last two weeks.

systemctl start vncserver-x11-serviced.service

Running Virtual mode requires additional software xorg-x11-drv-dummy and xorg-x11-drv-void. I had to build these, which required a dependency xorg-x11-util-macros and Clear Linux bundles c-basic, package-utils, devpkg-elfutils, devpkg-libpciaccess, devpkg-xorgproto, and devpkg-xorg-server.

I obtained Fedora 37 xorg-x11-drv-dummy, xorg-x11-drv-void source RPMs (src.rpm) from pkgs.org. Also, Fedora 37 xorg-x11-util-macros (noarch.rpm).

a. sudo swupd bundle-add c-basic package-utils devpkg...
b. sudo rpm -ivh --nodeps xorg-x11-util-macros*noarch.rpm
c. (as user) rpm -ivh xorg-x11-drv-dummy*src.rpm xorg-x11-drv-void*src.rpm
d. change folder to ~/rpmbuild/SPECS
e. delete `BuildRequires` and `Requires` lines inside *.spec files
f. rpmbuild -bb xorg-x11-drv-dummy.spec
g. rpmbuild -bb xorg-x11-drv-void.spec
h. cd ../RPMS/x86_64
i. rm *debug*.rpm
j. sudo rpm -ivh --nodeps xorg-x11-drv-dummy*rpm xorg-x11-drv-void*rpm

Running Virtual mode requires applying an offline license to VNC Connect. See also, Beginner’s guide to Virtual Mode.

That’s about all. I am not affiliated with realvnc.com. This is something I tried, wondering if possible on Clear Linux. Yes, indeed. VNC Server works wonderfully. Run VNC Viewer on the client machine.

Hi @marioroy, thanks for all the hard work!

If I might give you some feedback:

  • you can run an executable (I.E. a text file that starts with #!) by specifying it via it’s full or relative path. so, ./cl_vncinstall.sh will work just as well as calling bash. Furthermore, it’s preferable in the event that you have a script that has a shebang other than bash, this will allow it to be interpreted rather than trying to parse it with bash
  • as you are writing a bash script, you should always use [[ instead of [ - the latter basically exists for legacy reasons only
  • you are using the file names vncinstall, vcininitconfig a whole lot, could be candidate to replace with a variable
  • it is better practice to require a user to run the script via some means of elevation rather than to hardcode sudo
    • they may not have sudo, but may have an alternative, like doas
    • they may be running as root (and could not have sudo installed at all, which would throw an error)
    • they may have sudo configured with extremely low - or non-existent - credential caching, meaning they would have to enter their password on every command
    • They may only be allowed to sudo specific commands or scripts. In fact, if you make your script run as root and expect to be elevated, then an admin could specifically make your script a sudo exception for a user
  • you have a lot of the same code. Most of the sed commands, and all the mkdir commands could be replaced with a for loop. This would make it easier to maintain too E.G.
directories=(
/etc/cups/backend
/etc/pam.d
/etc/systemd/system
/usr/local/{bin,lib,share/man/man1,share/vnc}
)
for dir in "${directories[@]}"; do
  mkdir -p "${dir}"
done
  • shorter code isn’t more efficient and harder for people to read - it’s better to break your error checking out. Even better if you have a function. Something like this:
#!/bin/bash
die() {
  local string="$1"
  printf "%s\n" "${string}"
  exit 2
}
foo() {
  return 0
}
bar() {
  return 1
}
main() {
  if ! foo; then
    die "foo was unsuccessful"
  else
    printf "%s\n" "foo was successful"
  fi

  if ! bar; then
    die "bar was unsuccessful"
  else
    printf "%s\n" "bar was successful"
  fi
}
main "$@"

Interesting! Looks like the RealVNC “Virtual” mode does what xpra does, and the latter is free, and also available for Clear Linux(!). Unfortunately, I, for one, could not make xpra work on CL. @marioroy, would you care to try your hand at CL xpra? :smiling_face:

Unfortunately, Xpra involves a lot of dependencies.

There is TurboVNC, providing virtual display capabilities, without involving a lot of dependencies. In fact, unnecessary to launch the C compiler. :slight_smile:

I created a topic: TurboVNC on Clear Linux.

1 Like

Thank you! Will give it a try and report back.

As for xpra, my thinking was that whoever put in the time to port it to CL should be able to give us a hint as to how he made it work. If only we could tell who built the bundle