Bash: UT-Citrix


I developed the Ubuntu version Citrix thin client. To follow the same naming convention as TC-Citrix, I name it UT-Citrix.

image

Here are the key scripts:

checkip

#!/bin/bash

#wait for the DHCP ready
while ! ifconfig eth0 | grep ‘inet addr’ >/dev/null 2>&1
do
echo
sleep 2
done

sysprep

#!/bin/bash
#rename the computer
echo
HOSTNAME=UT-`ifconfig | grep ‘eth0’ | tr -s ‘ ‘ | cut -d ‘ ‘ -f5 | sed ‘s/://g’`
rm -f /etc/hostname
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname
rm -f /etc/hosts
echo “127.0.0.1 localhost” > /etc/hosts
echo “127.0.0.1 $HOSTNAME” >> /etc/hosts

#generate new SSH key
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

sleep 3

launch_ica

#!/bin/bash

#check hostname if not running from CD-ROM
HOSTNAME=UT-`ifconfig | grep ‘eth0’ | tr -s ‘ ‘ | cut -d ‘ ‘ -f5 | sed ‘s/://g’`
PC=`hostname`
if [ -d /rofs ]; then
echo “running from live CD”
sudo hostname $HOSTNAME
elif [ $PC != $HOSTNAME ]; then
sudo /usr/local/sw/sysprep | zenity –progress –pulsate –text=”Computer needs to be renamed at the first time, reboot shortly…” –auto-close –no-cancel
sudo reboot
else
echo “The PC name is correct.”
fi

#wait for network ready
/usr/local/sw/checkip | zenity –progress –pulsate –text=”Network is initializing, please wait…” –auto-close –no-cancel

#check the IP address 10.* or 192.* or 172.*
ip=`ifconfig eth0 | grep ‘inet addr’ | cut -d’:’ -f2 | cut -d’ ‘ -f1 | cut -d’.’ -f1`
while [[ “$ip” != “10” && “$ip” != “192” && “$ip” != “172” ]];
do
ip1=`ifconfig eth0 | grep ‘inet addr’ | cut -d’:’ -f2 | cut -d’ ‘ -f1`
zenity –error –text=”Invalid IP address: $ip1 \n\nPlease check your network settings.” –no-wrap
sleep 5
ip=`ifconfig eth0 | grep ‘inet addr’ | cut -d’:’ -f2 | cut -d’ ‘ -f1 | cut -d’.’ -f1`
done

# check the timezone
sudo chmod 777 /etc/timezone
location=`cat $(ls -t /var/lib/dhcp/*eth0* | head -1) | grep ftp-root | cut -d’ ‘ -f5 | cut -d’\’ -f3`
case $location in
act|vic|nsw|qld|tas)
echo “You are in EST”
sudo echo “Australia/Sydney” > /etc/timezone
sudo cp -f /usr/share/zoneinfo/Australia/NSW /etc/localtime
;;
sa|nt)
echo “You are in CST”
sudo echo “Australia/Adelaide” > /etc/timezone
sudo cp -f /usr/share/zoneinfo/Australia/South /etc/localtime
;;
wa)
echo “You are in WST”
sudo echo “Australia/Perth” > /etc/timezone
sudo cp -f /usr/share/zoneinfo/Australia/West /etc/localtime
;;
*)
zenity –error –text=”Failed to detect your timezone, please set it manually.” –no-wrap
gnome-control-center indicator-datetime
;;
esac

# Wait for ica
sleep 1
(for((i=0; i<=100; i+=25)); do sleep 1 && echo $i; done;) | zenity –progress –text=”Launching Citrix client…” –auto-close –no-cancel
#xdotool search –name “Citrix Receiver” windowactivate –sync key –clearmodifiers Alt+F9 &

#launch ica authentication
/opt/Citrix/ICAClient/wfcmgr

#remove last user’s desktop cache
rm -rf /home/generic/Desktop/*
#rm -rf /home/generic/.ICAClient/cache/Desktop/*
#rm -rf /home/generic/.ICAClient/cache/Programs/*

# shutdown computer
sudo poweroff

~/.conkyrc (conky conf file)

# Conky configuration
alignment top_right
background yes
use_xft yes
xftfont Monospace:size=9
xftalpha 0.8
out_to_console no
update_interval 2
total_run_times 0
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders yes
stippled_borders 5
border_margin 4
border_width 1
default_color grey
default_shade_color black
default_outline_color black
alignment top_right
gap_x 10
gap_y 47
no_buffers no
uppercase no
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
use_spacer no

TEXT
${alignc}${color white}SERVICE DESK SUPPORT
${alignc}${color white}XXXX XXX XXX
$color$stippled_hr
${color}Date: ${color white}${time %A,%d %B}
${color}Time: ${color white}${time %k:%M:%S}
${color}Timezone: ${color white}${exec date | cut -d’ ‘ -f6}
$color$stippled_hr
${color}Hostname: ${color white}$nodename
${color}Uptime: ${color white}$uptime
${color}CPU:${color white} ${cpu cpu0}% ${cpubar cpu0}
${color}RAM:${color white} $memperc%  $mem/$memmax $membar
${color}Swap: ${color white}$swapperc% $swap/$swapmax ${swapbar}
${color}HDD:${color white} ${fs_used_perc /}% ${fs_used /}/${fs_size /} ${fs_bar /}
${color}IP: ${color white}$alignc${exec ifconfig eth0 | grep ‘inet addr’ | cut -d’:’ -f2 | cut -d’ ‘ -f1}

Advertisements

2 thoughts on “Bash: UT-Citrix

  1. Can you give more details on how to create this Ubuntu based thin client? Also, can you include how to make it a PXE bootable package?

    1. Hi Douglas, I have wrote comments for each section. So just spend some time to understand what the script does, and you may need to modify some of them to fit your environment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s