#!/bin/sh # iTalc client launcher using avahi # Written by St├ęphane Graber ICA_LTSP=`xprop -root ica_ltsp | sed 's/^.* //' 2> /dev/null` if [ "$ICA_LTSP" = "1" ] then echo "ICA already running on the thin client." exit 0 fi # Set default ports ISDPORTDEF=5800 IVSPORTDEF=5900 HOSTNAME=`hostname` MD5_3=`md5sum /etc/italc/keys/public/teacher/key 2> /dev/null | awk '{print \$1}'` MD5_2=`md5sum /etc/italc/keys/public/admin/key 2> /dev/null | awk '{print \$1}'` MD5_1=`md5sum /etc/italc/keys/public/supporter/key 2> /dev/null | awk '{print \$1}'` if [ -n "$1" ]; then ROLE=$1 else ROLE="other" fi # Get session number SESSION=`echo $DISPLAY | sed -r 's/^.*:([0-9]+)(|[^0-9].*)$/\1/'` if [ "$LTSP_CLIENT" ]; then echo LTSP environement detected PORT=`echo $LTSP_CLIENT | awk -F . '{print \$4}'` ISDPORT=$((($SESSION * 2 + 11) * 1000 + $PORT)) IVSPORT=$((($SESSION * 2 + 10) * 1000 + $PORT)) else ISDPORT=$(($ISDPORTDEF + $SESSION)) IVSPORT=$(($IVSPORTDEF + $SESSION)) fi # Create script for awk # First pattern AWKSCRIPT='($5 ~ /^(\/usr\/bin\/|)ica/) && ($1 ~ /^[0-9]+$/)' # Add pattern for -isdport AWKSCRIPT="$AWKSCRIPT"' && (/[[:space:]]-isdport[[:space:]]+'$ISDPORT'([[:space:]]|$)/' if [ "$ISDPORT" = "$ISDPORTDEF" ]; then AWKSCRIPT="$AWKSCRIPT"' || ! /[[:space:]]-isdport[[:space:]]/' fi AWKSCRIPT="$AWKSCRIPT"')' # Add pattern for -ivsport and -rfbport AWKSCRIPT="$AWKSCRIPT"' && (/[[:space:]]-(ivs|rfb)port[[:space:]]+'$IVSPORT'([[:space:]]|$)/' if [ "$IVSPORT" = "$IVSPORTDEF" ]; then AWKSCRIPT="$AWKSCRIPT"' || ! /[[:space:]]-(ivs|rfb)port[[:space:]]/' fi AWKSCRIPT="$AWKSCRIPT"')' # Add action: print PID only AWKSCRIPT="$AWKSCRIPT"' {print $1}' RUNNING_ICA=`ps x | gawk --source "$AWKSCRIPT" | sort -bg` if [ "$RUNNING_ICA" ] then for processus in $RUNNING_ICA do kill $processus done echo ICA already running, killing it. sleep 1s fi AVAHIPUBLISHSERVICE="/usr/bin/avahi-publish-service" if [ -f $AVAHIPUBLISHSERVICE ] && [ ! -f /etc/ltsp/getltscfg-cluster.conf ] then echo Announce the service on avahi $AVAHIPUBLISHSERVICE "italc $USER" _italc._tcp $IVSPORT $MD5_1 $MD5_2 $MD5_3 "$HOSTNAME" > /dev/null & fi echo Starting ICA ica -noshm -isdport $ISDPORT -ivsport $IVSPORT -role $ROLE 2> /dev/null if [ -f $AVAHIPUBLISHSERVICE ] && [ ! -f /etc/ltsp/getltscfg-cluster.conf ] then echo Stopping avahi kill `ps ux | grep avahi-publish-service | grep italc | grep $IVSPORT | grep $USER | awk '{print \$2}'` fi