summaryrefslogtreecommitdiffstats
path: root/time_wizard/scripts/test_timeservers.sh
blob: 1e5ce41af1bf3270d84507af046fb87b43dfc07d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/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 <ln@mandrakesoft.com>
# <corporate@mandrakesoft.com> 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