#!/bin/sh
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

[ "$STTA" ] && . $STTA/envprofile 

TTAHOME="/opt/tarantella"
TTA=$TTAHOME"/bin/tarantella"
STTATOOLS=$TTAHOME/tools   
dn=/dev/null

msg_binpath="Path para ejecutables (links):"
msg_mkfiles="Creando Ficheros ..."
msg_mkdirs="Creando Directorios ..."
msg_mklinks="Creando Enlaces Simbolicos ..."

CONFTTA=/etc/webmin/stta/config
CRONTAB=/usr/spool/cron/tabs/root
[ ! -f $CRONTAB ] && CRONTAB=/usr/spool/cron/crontabs/root

has_monitor=`fgrep "has_monitor" $CONFTTA | sed 's/has_monitor=//g'`  
has_cronsess=`fgrep "has_cronsess" $CONFTTA | sed 's/has_cronsess=//g'`  

echo "PATH=$PATH"
echo -n -e "$msg_binpath"
read npath 

DIRTOOLS=$SETUPDIR/tools
DEST=$STTATOOLS

mkdir $DEST 2>$dn
chown root:bin $DEST
chmod 755 $DEST

echo "$msg_mkfiles"
for file in ` echo $LIST_STTACMDS $LIST_TTACMDS $LIST_TCLS `
do
    cp -p $DIRTOOLS/$file $DEST/$file 
    chown root:bin $DEST/$file
    chmod 555 $DEST/$file
done 

echo "$msg_mkdirs"
for dir in ` echo $LIST_DIRS ` 
do
    cp -pr $DIRTOOLS/$dir $DEST 
done 

[ "$npath" ] && [ -d $npath ] && {
   echo "$msg_mklinks"
   for file in ` echo $LIST_LNKCMDS `
   do
       rm $npath/$file 2>$dn
       ln -s $DEST/$file  $npath/$file
   done 
}

set_monline () {
   echo "#!/bin/sh" >$TTA
   echo "if [ -n \"$1\" ] ">>$STTA
   echo "then ">>$STTA
   echo "    case \"$1\" in ">>$STTA
   echo "        start) $TTAHOME/tools/monitor auto $1 ;; ">>$STTA
   echo "        stop) $TTAHOME/tools/monitor auto $1 ;; ">>$STTA
   echo "    esac ">>$STTA
   echo "fi ">>$STTA
   cat $TTAORG >>$TTA
   chown bin:bin $TTA
   chmod 755 $STTA
}

if [ $has_cronsess = "true" ] ; then
   line=`fgrep ttasess $CRONTAB`
   [ -z "$line" ] && echo "30 * * * * $STTATOOLS/ttasess -r 1>/dev/null 2>/dev/console ">>$CRONTAB
fi
if [ $has_monitor =  "true" ] ; then
   TTAORG=$TTA".org"
   [ ! -f $TTAORG ] &&  cp -p $TTA $TTAORG && set_monline
   line=`fgrep monitor $CRONTAB`
   [ -z "$line" ] && echo "59 * * * * $STTATOOLS/monitor task 1>/dev/null 2>/dev/console ">>$CRONTAB
fi
