#!/bin/sh
# Ce script est à lancer une fois en début de semestre :
#   * Il archive les anciens TP
#   * Il crée les nouveaux : cisco1 et cisco2
#   * Il lance les nouveaux : cisco1 et cisco2
# NE PAS LE LANCER DEUX FOIS !
# Le nom des admins est en dur dans le code
#
# Il tient compte de la variable shell LDAP:
# LDAP="('ldap.domain.org',636,'login','password')"

cd
cd QUENLIG

if [ "" != "$LDAP" ]
then
    LDAP="ldap $LDAP"
fi

for TP in 1 2
do
    SESSION=cisco$TP
    echo "
###########################################################################
###########################################################################
# ARRET de l'ancienne session
###########################################################################
###########################################################################"
    ./main.py $SESSION stop
    echo "
###########################################################################
# Archive l'ancienne session de Students/cisco$TP
###########################################################################"
    if [ -d Students/cisco$TP ]
    then
	mv Students/cisco$TP Students/cisco$TP.$(date "+%Y%m%d")
    fi
    echo "
###########################################################################
# CREATION de la session 'cisco$TP'
###########################################################################"
    [ ! -d Students/$SESSION ] && mkdir Students/$SESSION
    echo 16 >Students/$SESSION/nr_hosts
    ./main.py $SESSION create Questions/cisco$TP 300$TP \
	admin thierry.excoffier \
	admin yves.caniou \
	admin jacques.bonneville \
	admin olivier.gluck \
	url "http://demo710.univ-lyon1.fr/LIF8TP$TP" \
	plot \
        $LDAP
    (cd Questions/cisco$TP/HTML ; make)
    if [ ! -d Students/$SESSION/Logs/Default ]
    then
	mkdir Students/$SESSION/Logs/Default
    fi
    if [ ! -d Students/$SESSION/Logs/Student ]
    then
	mkdir Students/$SESSION/Logs/Student
    fi
    echo "{'session_deconnection':('!executable',),
'session_start': ('!executable',),
'session_stop': ('!executable',),
'courses': ('!executable',),
'session_duration':('!executable',),
'statmenu_smiley':('!executable',),
'statmenu_rank':('!executable',)}
" >Students/$SESSION/Logs/Student/acls
    echo "
###########################################################################
# LANCEMENT de la session en arrière plan
###########################################################################"
    ./main.py $SESSION start >>Students/$SESSION/log 2>&1 </dev/null &
    echo "
###########################################################################
# Création du sujet de TP (TRES TRES lent)
# Normalement FireFox affiche $(pwd)/Questions/cisco1/HTML/sujet.html
###########################################################################"

    cp Questions/cisco$TP/HTML/sujet.html Students/cisco$TP/HTML
    firefox Students/cisco$TP/HTML/sujet.html

done




