#!/bin/bash # # Wizard # # Copyright (C) 2000 Mandrakesoft. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # See file LICENSE for further informations on licensing terms. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi # icons: Helene Durosini # http://www.mandrakesoft.com # This script perform a test of the time servers whose names # can be found into the variables # - $server1 # - $typedserver1 # - $server2 # - $typesserver2 # The typed variables have precedence over the fixed, if they are not empty. # This test (ntpdate...) have a fixed timeout. # If the test succeeds, it calls the script save_config.sh and then outputs 'ciao' # else, it outputs 'server_not_responding' echo_debug "$(date)= begin $0" tout=30 typeset -i i if [ -n "${typedserver1}" ]; then tserver1=${typedserver1} else tserver1=${server1} fi if [ -n "${typedserver2}" ]; then tserver2=${typedserver2} else tserver2=${server2} fi echo_debug "tserver1=${tserver1} tserver2=${tserver2}" if [ -x /usr/sbin/ntpdate ] && [ -n "${tserver1}" -o -n "${tserver2}" ]; then echo_debug "launching /usr/sbin/ntpdate -q ${tserver1} ${tserver2}" TMPFILE=`mktemp -q /tmp/tmwiz.XXXXXX` if [ $? -ne 0 ];then echo_debug "$0 cant create tmpfile, exit 1" exit 1 fi /usr/sbin/ntpdate -q ${tserver1} ${tserver2} > ${TMPFILE} 2>&1 & pid=$! echo_debug "pid du process : ${pid}" i=0 ok=0 while [ $ok -eq 0 ]; do if [ `ps h ${pid} | wc -l` -eq 1 ]; then i=i+1 echo_debug "still running $i" if [ $i -ge ${tout} ]; then kill ${pid} >/dev/null 2>&1 echo_debug "killing process" echo_debug "server_not_responding" exit 1 else sleep 1 fi else echo_debug "ok end loop" ok=1 fi done # time server found? if [ `grep -c "no servers can be used" ${TMPFILE}` -ne 0 ];then echo_debug "bad server" echo_debug "$(cat ${TMPFILE})" else echo_debug "launching ${CWD}/scripts/save_config.sh" __WIZ_HOME__/time_wizard/scripts/save_config.sh echo_debug "exiting saying ciao" rm -f ${TMPFILE} exit 2 fi fi # some problem : rm -f ${TMPFILE} echo_debug "server_not_responding" exit 1