VMWare Horizon Client - Dedicated Thin Client

From Michael's Information Zone
Jump to navigation Jump to search

With the cost of zero clients being as much as a standard computer, it made more sense to purchase commodity hardware and build from scratch.
This is my endeavor into building a poor man's zero client.

Requirements

  • Audio, Video, and user input must work.
  • USB Redirection must work for webcam usage.
  • The only window the user's see is the Horizon Client.
  • If the client is closed, it must auto-open again.

Install Script

CentOS6 32bit

WIP[1]

yum -y install epel-release
yum -y update
yum install -y chrony wget yum-cron fail2ban bind-utils htop bzip2 nano openbox xorg-x11-* gnome-terminal alsa-utils libXScrnSaver
useradd publicuser
sed -i 's|exec\ /sbin/mingetty\ \$TTY|exec\ /sbin/mingetty\ --autologin\ publicuser\ \$TTY|' /etc/init/tty.conf

CentOS7

WIP

yum -y install epel-release
yum clean all
yum makecache
yum -y update
yum -y install wget chrony wget yum-cron firewalld fail2ban oddjob oddjob-mkhomedir sssd samba-common realmd bind-utils htop bzip2 nano libao libv4l speex setroubleshoot setools openbox xorg-x11-* gnome-terminal alsa-utils pcsc-lite-libs-1.8.8-6.el7 glibmm24 gstreamer-plugins-base-0.10.36-10.el7 libpng12 libXScrnSaver
useradd publicuser
cp /usr/lib/systemd/system/getty@.service ./
sed -i -e "s/\/sbin\/agetty/\0 --autologin publicuser/" /etc/systemd/system/getty.target.wants/getty@tty1.service
cat << EOF >>/home/publicuser/.bash_profile
if [[ -z \$DISPLAY ]] && [[ \$(tty) = /dev/tty1 ]]; then # Check if we have a display and we're on TTY1
startx
else
echo "Please contact the help desk and provide the following"
echo "IP : "
echo "Hostname : $hostname"
fi
EOF
cat << EOF > /home/publicuser/.xinitrc
/home/publicuser/display.sh
exec openbox
EOF
cat << EOF > /home/publicuser/display.sh
#!/bin/bash
displaycheck ()
{
if grep -qi \$1 <<<\$line; then
        if grep -qi \$1\1 <<<\$line; then
                if [ -z "\$d1" ]; then
                       	d1=\$1\1
                elif [ -z "\$d2" ]; then
                        d2=\$1\1
                fi
        fi
        if grep -qi \$1\2 <<<\$line; then
                if [ -z "\$d1" ]; then
                        d1=\$1\2
                elif [ -z "\$d2" ]; then
                        d2=\$1\2
                fi
        fi
fi
}

xrandr > /tmp/xout
adisplay=\$(sed '/disconnected/ d; /LVDS/ d' /tmp/xout | grep connected | awk '{print $1}')

while read line
do
displaycheck VGA
displaycheck DVI
displaycheck HDMI
displaycheck DP
done <<<\$adisplay
xrandr --output \$d1 --left-of \$d2
EOF
chmod +x /home/publicuser/display.sh
cat << EOF > /root/vdi_keep_alive.sh
#!/bin/bash
pidview=\$(/usr/sbin/pidof vmware-view)
if [ "\$pidview" = "" ]; then
killall vmware-view
killall vmware-usbarbitrator
killall vmware-view-usbd
su publicuser -c 'DISPLAY=:0.0 vmware-view -s <yourserver> -d csp --allmonitors'
else
echo "keep running" >> /dev/null
fi
EOF
chmod 700 /root/vdi_keep_alive.sh
echo "* * * * * /root/vdi_keep_alive.sh" | crontab
ln -s /usr/lib64/libudev.so.1.6.2 /usr/lib64/libudev.so.0
ln -s /usr/lib64/libffi.so.6.0.1 /usr/lib64/libffi.so.5
wget https://download3.vmware.com/software/view/viewclients/CART18FQ3/VMware-Horizon-Client-4.6.0-6617224.x64.bundle
chmod +x VMware-Horizon-Client-4.6.0-6617224.x64.bundle
./VMware-Horizon-Client-4.6.0-6617224.x64.bundle --eulas-agreed --required

Notes

From the most awesome technical resource in these projects, Tanner said

Okay, I just thought of a much more minimal way to handle this.  Let's systemctl disable gdm and directly modify the getty service to autologin your user at the TTY level.  You'll need to install the Xorg xinit package.  Then in the user's .bash_profile we run startx upon login.  This way you can use xrandr to configure the display in the user's ~/.xinitrc.  Let me break it down:
First we override the getty systemd service with /etc/systemd/system/getty@tty1.service.d/override.conf:
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin user_name --noclear %I $TERM

Then we add these lines to the end of /home/user_name/.bash_profile:
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then # Check if we have a display and we're on TTY1
startx
fi

And finally, make /home/user_name/.xinitrc look like this:
xrandr --output HDMI2 --whatever_other_options_you_need --right-of HDMI1
exec openbox # or whatever DE/WM you use


This method will use less resources and IMO XrandR is *much* better at configuring displays than xorg.conf.
Also, I would uninstall the xorg-x11-drv-intel, the modesetting drivers work with intel display thingies just fine

Display Script

This is used for checking the currently detected displays and sorting them left to right based on the connection used. VGA -> DVI -> HDMI -> DP (the script is currently looking for dual monitors)

#!/bin/bash
displaycheck ()
{
if grep -qi $1 <<<$line; then
        if grep -qi $1\1 <<<$line; then
                if [ -z "$d1" ]; then
                       	d1=$1\1
                elif [ -z "$d2" ]; then
                        d2=$1\1
                fi
        fi
        if grep -qi $1\2 <<<$line; then
                if [ -z "$d1" ]; then
                        d1=$1\2
                elif [ -z "$d2" ]; then
                        d2=$1\2
                fi
        fi
fi
}

xrandr > /tmp/xout
adisplay=$(sed '/disconnected/ d; /LVDS/ d' /tmp/xout | grep connected | awk '{print $1}')

while read line
do
displaycheck VGA
displaycheck DVI
displaycheck HDMI
displaycheck DP
done <<<$adisplay
xrandr --output $d1 --left-of $d2
exit 0

####For Reference
Screen 0: minimum 8 x 8, current 3360 x 1050, maximum 32767 x 32767
LVDS1 connected (normal left inverted right x axis y axis)
   1280x800      60.05 +
   1024x768      60.00  
   800x600       60.32    56.25  
   640x480       59.94  
   640x400       60.00  
DP1 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
HDMI1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 474mm x 296mm
   1680x1050     59.88*+
   1280x1024     75.02    60.02  
   1152x864      75.00  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   640x480       75.00    59.94  
   720x400       70.08  
HDMI2 connected 1680x1050+1680+0 (normal left inverted right x axis y axis) 474mm x 296mm
   1680x1050     59.88*+
   1280x1024     75.02    60.02  
   1152x864      75.00  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   640x480       75.00    59.94  
   720x400       70.08  
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)