File: postinst

package info (click to toggle)
xntp3 5.93-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 7,644 kB
  • ctags: 7,419
  • sloc: ansic: 59,474; perl: 3,633; sh: 2,623; awk: 417; makefile: 311; asm: 37
file content (153 lines) | stat: -rw-r--r-- 4,779 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash

NC="/etc/ntp.conf"
XI="/etc/init.d/xntp3"

TWEAK="no"

# only do this stuff if we're being called to configure a package
if [ "$1" != "configure" ]
then
	exit 0
fi

# make sure a couple of directories we need exist
mkdir -p /var/log/ntpstats /var/lib/ntp /etc/init.d

# make sure we have an /etc/init.d/xntp3
if [ -f $XI ]
then
	echo "An /etc/init.d/xntp3 file already exists, we'll give it a try."
	echo "If you're having problems, remove this file, and reinstall."
	echo ""
else

	echo "#! /bin/sh" > $XI
	echo "#	/etc/init.d/xntp: start xntp daemon." >> $XI
	echo "" >> $XI
	echo "test -f /usr/sbin/xntpd || exit 0" >> $XI
	echo "" >> $XI
	echo "case \"\$1\" in" >> $XI
  	echo "start)" >> $XI
    	echo "  #ntpdate" >> $XI
    	echo "  start-stop-daemon --start --verbose --exec /usr/sbin/xntpd" >> $XI
    	echo "  ;;" >> $XI
  	echo "stop)" >> $XI
    	echo "  start-stop-daemon --stop --quiet --exec /usr/sbin/xntpd" >> $XI
    	echo "  ;;" >> $XI
  	echo "restart|force-reload)" >> $XI
    	echo "  start-stop-daemon --stop --quiet --exec /usr/sbin/xntpd" >> $XI
    	echo "  sleep 2" >> $XI
    	echo "  start-stop-daemon --start --verbose --exec /usr/sbin/xntpd" >> $XI
    	echo "  ;;" >> $XI
  	echo "*)" >> $XI
    	echo "  echo \"Usage: /etc/init.d/xntp3 {start|stop|restart|force-reload}\"" >> $XI
    	echo "  exit 1" >> $XI
	echo "esac" >> $XI
	echo "" >> $XI
	echo "exit 0" >> $XI

	TWEAK="yes"
fi

# make sure we have an /etc/ntp.conf 
if [ -f $NC ]
then
	echo "An /etc/ntp.conf file already exists, and will be used to"
	echo "configure xntpd.  You may wish to review the contents of this"
	echo "file for accuracy."
	echo ""
else
	# there shouldn't be a daemon running if there's no config file, but
	# make sure before we go mucking...
	start-stop-daemon --stop --quiet --exec /usr/sbin/xntpd

	echo "# /etc/ntp.conf, configuration for xntpd" > $NC
	echo "" >> $NC
	echo "logfile /var/log/xntpd" >> $NC
	echo "driftfile /var/lib/ntp/ntp.drift" >> $NC
	echo "statsdir /var/log/ntpstats/" >> $NC
	echo "" >> $NC
	echo "statistics loopstats peerstats clockstats" >> $NC
	echo "filegen loopstats file loopstats type day enable" >> $NC
	echo "filegen peerstats file peerstats type day enable" >> $NC
	echo "filegen clockstats file clockstats type day enable" >> $NC
	echo "" >> $NC

	echo
	echo "Before xntpd can be started to syncronize your computer's clock,"
	echo "we need the address of at least one existing NTP server for the"
	echo "/etc/ntp.conf file.  If you don't know which server you want to"
	echo "use, just hit enter and edit /etc/ntp.conf later.  If you have"
	echo "a radio clock and/or want to establish peer instead of server"
	echo "relationships in xntpd, you will need to edit /etc/ntp.conf"
	echo "manually."
	echo

	echo "Please enter the address of an NTP server, or <enter> to end:"
	echo -n "> "
	read TMP
	if [ -z $TMP ]
	then	
		echo "#server" >> $NC
	else
        	while [ ! -z $TMP ]
		do
			echo "server $TMP" >> $NC
			echo "Another? (<enter> to end):"
			echo -n "> "
			read TMP
		done
	fi
	echo

	TWEAK="yes"
fi

# if we touched either ntp.conf or the init.d fragment, offer to run ntpdate
if [ "$TWEAK" = "yes" ]
then
	echo "The xntpd daemon will give up without synchronizing your clock"
	echo "if the difference between your clock and that of the server you"
	echo "specified is more than 1024 seconds when xntpd launches."
	echo
	echo "There is a command 'ntpdate' which can be run before xntpd is"
	echo "started, to warp your local clock to a close approximation of"
	echo "the time on the server(s) you specified above before xntpd is"
	echo "started.  If you trust the time on the servers above more"
	echo "than you trust the battery in your system's clock, then we can"
	echo "arrange for ntpdate to be added to the xntpd startup script."
	echo "Because 'ntpdate' is much less paranoid than xntpd about servers"
	echo "with bad clocks, some folks think this is a bad idea."
	echo
	echo -n "Should we run ntpdate every time xntpd starts? "

	read yn
	test -n "$yn" || yn="N"

	case "$yn" in
		[Yy]*)
		  TMP="`grep "server" $NC | awk '{ print $2 }' | tr "\n" " "`"
		  export TMP
		  awk '	BEGIN			{ state = 0 }
			/ntpdate/ && state == 0	{ 
				  printf "  /usr/sbin/ntpdate -b -s %s\n",
		  			ENVIRON["TMP"]
				  state = 1  
				  next }
			/ntpdate/ && state == 1	{ next }
						{ print }
		  ' < /etc/init.d/xntp3 > /etc/init.d/xntp3.new
		  mv -f /etc/init.d/xntp3.new /etc/init.d/xntp3
		;;
	esac
fi

# make sure the init.d fragment is properly linked and executable
update-rc.d xntp3 defaults >/dev/null
chmod 755 /etc/init.d/xntp3

# use the init.d script instead of calling start-stop-daemon directly, so that
# ntpdate gets run first if we're configured that way...
/etc/init.d/xntp3 start