#stone.sh #with error control as in guide/ #FIXME: translate all comments into english #params # proto# connexion_file plugin_port trustpeer_port PARAMNUMBER=4 #connexion contient 3 lignes et c'est tout: #connexion version# #machine_distante:port_distant/protocole #port_local/protocole #il suffit de remplacer protocole par ssl pour utiliser les facilités du paquet stone-ssl #TODO a sh include file with macros, you will use inside your shell scripts with the source command ERRPROG=1 ERRNORM=2 #d'abord on teste le nombre de parametres sinon usage sur stderr et return ERRPROG pour signaler precondition 1 fausse if test $# -ne $PARAMNUMBER then echo "stone.sh: PRECONDITION 1 ASSERTION FAILED: needs $PARAMNUMBER parameters: proto# connexion_file plugin_port trustpeer_port">&2 exit $ERRPROG fi #ensuite on lance un stone qui va forwarder de A/udp vers B/ssl, on retourne le code d'erreur de stone si il marche pas #first we need a handler for sigchld (a background job sends SIGCHLD when it finishes) trap "kill %1;kill %2;echo 'stone_tcptp.sh: INVARIANT 1 ASSERTION FAILED: a background stone aborts'>&2;return ERRPROG" SIGCHLD stone `head -n 3 $2|tail -n 1` localhost:$3/tcp & #what follows is of no use with background commands & #if [ $? -ne 0 ] # then ERR=$?;echo "stone.sh: first stone returns error $?">&2 # exit $ERR #fi #FIXME: we should return 3 when 2 connexion files have the same plugin server port, and ERRNORM when a connexion file is incorrect #PUIS de B/ssl vers A/udp, 4040 est arbitraire et est négociable pour chaque ami #c'est la valeur qui sera dans le connexion de l'ami stone localhost:$4/tcp localhost:`head -n 4 $2|tail -n 1` & #if [ $? -ne 0 ] # then ERR=$?;echo "stone.sh: 2nd stone returns error $?">&2 # exit $ERR #fi #a sleep is needed to get a SIGCHLD if a background stone aborts after a few seconds sleep 2 #no error exit 0