#!/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 CONFIGFILE="/etc/sysconfig/italc2.conf" # Provide a configuration file to enable switching off client autodetection # and/or specifying user-defined ports. if [ -f "$CONFIGFILE" ] then . $CONFIGFILE fi AVAHIPUBLISHSERVICE="/usr/bin/avahi-publish-service" PUBLISH_CLIENT=${PUBLISH_CLIENT:-True} # Set default ports ICAPORTDEF=11100 ICAFIRSTPORT=${ICAFIRSTPORT:-$ICAPORTDEF} HOSTNAME=`hostname` MD5_3=`md5sum @SYSCONFDIR@/@PACKAGE@/@KEYSDIRNAME@/@PUBKEYSDIRNAME@/@TEACHERROLENAME@/key 2> /dev/null | awk '{print \$1}'` MD5_2=`md5sum @SYSCONFDIR@/@PACKAGE@/@KEYSDIRNAME@/@PUBKEYSDIRNAME@/@ADMINROLENAME@/key 2> /dev/null | awk '{print \$1}'` MD5_1=`md5sum @SYSCONFDIR@/@PACKAGE@/@KEYSDIRNAME@/@PUBKEYSDIRNAME@/@SUPPORTERROLENAME@/key 2> /dev/null | awk '{print \$1}'` if [ -n "$1" ]; then ROLE=$1 fi if [ -z "$ROLE" ]; then ROLE="other" fi # Get session number SESSION=`echo $DISPLAY | sed -r 's/^.*:([0-9]+)(|[^0-9].*)$/\1/'` if [ -n "$LTSP_CLIENT" ] then echo LTSP environement detected PORT=`echo $LTSP_CLIENT | awk -F . '{print \$4}'` # Not much point in using the ports from /etc/sysconfig/italc2.conf for thin clients ICAPORT=$((($SESSION + 112) * 100 + $PORT)) HOSTNAME=${LTSP_CLIENT_HOSTNAME:-$HOSTNAME} else ICAPORT=$(($ICAFIRSTPORT + $SESSION)) fi # Create script for awk # First pattern AWKSCRIPT='($1 ~ /^[0-9]+$/)' # Add pattern for -port AWKSCRIPT="$AWKSCRIPT"' && (/[[:space:]]-port[[:space:]]+'$ICAPORT'([[:space:]]|$)/' if [ "$ICAPORT" = "$ICAFIRSTPORT" ]; then AWKSCRIPT="$AWKSCRIPT"' || ! /[[:space:]]-port[[:space:]]/' fi AWKSCRIPT="$AWKSCRIPT"')' # Add action: print PID only AWKSCRIPT="$AWKSCRIPT"' {print $1}' RUNNING_ICA=`ps -C ica -o pid,command | gawk --source "$AWKSCRIPT" | sort -bg` if [ -n "$RUNNING_ICA" ] then for processus in $RUNNING_ICA do kill $processus done echo ICA already running, killing it. sleep 1s fi if [ "$PUBLISH_CLIENT" = "True" ] && [ -f $AVAHIPUBLISHSERVICE ] && [ ! -f /etc/ltsp/getltscfg-cluster.conf ] then echo Announce the service on avahi $AVAHIPUBLISHSERVICE "italc $USER" _italc._tcp $ICAPORT $MD5_1 $MD5_2 $MD5_3 "$HOSTNAME" > /dev/null & fi echo Starting ICA # Store the port in an xprop, for italc-launcher to find it xprop -root -f ICA_PORT 16c -set ICA_PORT $ICAPORT #ica -noshm -port $ICAPORT -role $ROLE 2> /dev/null echo ica -noshm -port $ICAPORT -role $ROLE ica -noshm -port $ICAPORT -role $ROLE xprop -root -remove ICA_PORT if [ "$PUBLISH_CLIENT" = "True" ] [ -f $AVAHIPUBLISHSERVICE ] && [ ! -f /etc/ltsp/getltscfg-cluster.conf ] then echo Stopping avahi kill `ps -C "avahi-publish-service italc $USER _italc._tcp $ICAPORT" -o pid=` fi