]> granicus.if.org Git - fcron/blob - script/boot-install
ca0c65862de7e3d664ea1cc9cbcd8b375d1f32ce
[fcron] / script / boot-install
1 #!/bin/sh
2 # Install fcron under SysV system.
3 #
4
5
6 # takes 6 arguments : the name of the BSD-like install program (with "-o" and the correct username)
7 #                    the DESTSBIN directory
8 #                    the value of DEBUG
9 #                    the value of FCRONTABS
10 #                    the automatic answer
11 #                    the src dir
12
13 PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
14 if test -d /usr/ucb; then
15     PATH=/usr/ucb:$PATH
16 fi
17
18 startdir=$PWD
19 if test $# -ne 6; then
20     echo "Too few/many arguments"
21     exit 1
22 fi
23
24 # The program we use to install a file. This may be the script install.sh.
25 if echo "$1" | grep 'install.sh$'; then
26     INSPROG=$SRCDIR/$1
27 else
28     INSPROG=$1
29 fi
30 DESTBIN=$2
31 DEBUG=$3
32 #DEBUG=1
33 FCRONTABS=$4
34 ANSWER=$5
35 SRCDIR=$6
36
37 if test $DEBUG -eq 1; then
38     STARTCMD="fcron -b -d"
39 else
40     STARTCMD="fcron -b"
41 fi    
42
43 if test `uname -s` = "FreeBSD"; then
44   IS_FREEBSD=1
45 else
46   IS_FREEBSD=0
47 fi
48
49 # Check now if there is an old ( < 1.1.x ) version of fcrontab on the system.
50 # We do that here because if user say "no" too early, the PREVIOUS_VERSION would
51 # not be removed.
52 if test -r "PREVIOUS_VERSION"; then
53   MAJOR=`cat PREVIOUS_VERSION | awk '{print $2}' | awk -F '.' '{print $1}'`
54   MINOR=`cat PREVIOUS_VERSION | awk '{print $2}' | awk -F '.' '{print $2}'`
55   #echo "MINOR $MINOR MAJOR $MAJOR"
56   if test "x$MAJOR" = "x" -a "x$MINOR" = "x"; then 
57     # we don't have the version: there was no previous fcron installed
58     NEED_UPDATE=0
59   elif test \( "$MAJOR" -lt 1 \) -o \( \( "$MINOR" -lt 1 \) -a "$MAJOR" -eq 1 \); then
60     NEED_UPDATE=1
61   else
62     NEED_UPDATE=0
63   fi
64   rm -f PREVIOUS_VERSION
65 else
66   NEED_UPDATE=1
67 fi
68 #echo "NEED_UPDATE : $NEED_UPDATE"
69
70 echo
71 echo "Fcron should be started by your init scripts."
72 echo "The installation process is going to try to install fcron in them."
73 echo
74 echo "Note that if you answer no to a proposition made at this point by"
75 echo "the installation script, it will try to propose another way to do it."
76 echo "(if there are several possibilities, a list will be printed before each"
77 echo "action)"
78 echo
79 echo "If you answer no to all the propositions of the script, or if the script"
80 echo "fails, a message will be printed telling you what you should do manually."
81 echo
82
83 echo
84 echo "The script proposes the following location to do it :"
85 if test $IS_FREEBSD -eq 1; then
86   echo "  /usr/local/etc/rc.d/fcron.sh"
87 fi
88 if test -d /etc/init.d/; then
89   echo "  /etc/init.d/fcron"
90 elif test -d /etc/rc.d/init.d/; then
91   echo "  /etc/rc.d/init.d/fcron"
92 fi
93 if test -f /etc/rc.d/rc.local; then
94   echo "  /etc/rc.d/rc.local"
95 fi
96 if test -f /etc/rc.local; then
97   echo "  /etc/rc.local"
98 fi
99 echo
100
101 INSTALL="nothing"
102 SYSV=0
103 STOPPED=0
104 INSTALLED=0
105
106 if test $IS_FREEBSD -eq 1; then 
107   if test -x /usr/local/etc/rc.d/fcron.sh; then
108     echo "Fcron is already in /usr/local/etc/rc.d/."
109     INSTALLED=1
110   else
111     if test $ANSWER -eq 2; then
112       while test \( ! -z "$INSTALL" \) -a \( "$INSTALL" != "y" \) -a \( "$INSTALL" != "n" \);
113       do
114         echo "Would you like to add fcron.sh script in the directory /usr/local/etc/rc.d/ ?"
115         echo -n "Please answer with 'y' or 'n' (default: 'y'): "
116         read INSTALL NOTHING
117       done
118     # automatic answer given by configure script (option --with-answer-all)
119     elif test $ANSWER -eq 1; then
120       INSTALL="y"
121     else
122       INSTALL="n"
123     fi
124     if test \( -z "$INSTALL" \) -o \( "$INSTALL" = "y" \); then
125       cp -f script/fcron.sh /usr/local/etc/rc.d/
126       if test $DEBUG -eq 1; then
127         cat /usr/local/etc/rc.d/fcron.sh | sed 's: -b: -b -d:' > /usr/local/etc/rc.d/fcron.sh2
128         mv -f /usr/local/etc/rc.d/fcron.sh2 /usr/local/etc/rc.d/fcron.sh
129       fi
130       chmod +x /usr/local/etc/rc.d/fcron.sh
131       INSTALLED=1
132     else
133       INSTALLED=0
134     fi
135   fi
136 fi
137
138
139 INSTALL="nothing"
140 ROOTDIR=""
141 if test -d /etc/init.d/; then
142     ROOTDIR="/etc"
143 elif test -d /etc/rc.d/init.d/; then
144     ROOTDIR="/etc/rc.d"
145 fi
146 if test \( ! "$INSTALLED" -eq 1 \) -a \( "$ROOTDIR" != "" \); then
147   if test $ANSWER -eq 2; then
148     while test \( ! -z "$INSTALL" \) -a \( "$INSTALL" != "y" \) -a \( "$INSTALL" != "n" \);
149     do
150       echo "Would you like to add fcron in the directory $ROOTDIR/init.d/ and in runlevel 2, 3, 4 and 5"
151       echo "(directories $ROOTDIR/rc{2,3,4,5}.d/) ?"
152       echo -n "Please answer with 'y' or 'n' (default: 'y'): "
153       read INSTALL NOTHING
154     done
155   # automatic answer given by configure script (option --with-answer-all)
156   elif test $ANSWER -eq 1; then
157     INSTALL="y"
158   else
159     INSTALL="n"
160   fi
161   if test \( -z "$INSTALL" \) -o \( "$INSTALL" = "y" \); then
162     $INSPROG -c -m 755 script/sysVinit-launcher $ROOTDIR/init.d/fcron
163     if test $DEBUG -eq 1; then
164       cat $ROOTDIR/init.d/fcron | sed 's: -b: -b -d:' >$ROOTDIR/init.d/fcron2
165       mv -f $ROOTDIR/init.d/fcron2 $ROOTDIR/init.d/fcron
166       chmod +x $ROOTDIR/init.d/fcron
167     fi
168     chmod +x $ROOTDIR/init.d/fcron
169
170     for j in 2 3 4 5
171     do
172     cd $ROOTDIR/rc$j.d/ ; ln -f -s ../init.d/fcron S40fcron
173     done
174
175     for j in 0 6
176     do
177     cd $ROOTDIR/rc$j.d/ ; ln -f -s ../init.d/fcron K60fcron
178     done
179     cd $startdir
180
181     INSTALLED=1
182     SYSV=1
183   else
184     INSTALLED=0      
185   fi
186
187 fi
188
189 INSTALL="nothing"
190 if test \( ! "$INSTALLED" -eq 1 \) -a \( -f /etc/rc.d/rc.local \); then
191   # Slackware
192   if ! cat /etc/rc.d/rc.local | grep "$STARTCMD"; then
193     if cat /etc/rc.d/rc.local | grep fcron; then        
194       echo "Fcron seems to be in /etc/rc.d/rc.local, but not with the appropriate options :"
195       echo "you should probably correct this file in order to run fcron with $STARTCMD."
196       INSTALLED=1
197     else
198       if test $ANSWER -eq 2; then
199         while test \( ! -z "$INSTALL" \) -a \( "$INSTALL" != "y" \) -a \( "$INSTALL" != "n" \);
200         do
201           echo "Would you like to add $STARTCMD in the file /etc/rc.d/rc.local ?"
202           echo -n "Please answer with 'y' or 'n' (default: 'y'): "
203           read INSTALL NOTHING
204         done
205       # automatic answer given by configure script (option --with-answer-all)
206       elif test $ANSWER -eq 1; then
207         INSTALL="y"
208       else
209         INSTALL="n"
210       fi
211       if test \( -z "$INSTALL" \) -o \( "$INSTALL" = "y" \); then
212         echo $STARTCMD >> /etc/rc.d/rc.local
213         INSTALLED=1
214       else
215         INSTALLED=0
216       fi
217     fi
218   else
219     echo "Fcron is already in /etc/rc.d/rc.local."
220     INSTALLED=1
221   fi
222 fi 
223
224
225 INSTALL="nothing"
226
227 if test \( ! "$INSTALLED" -eq 1 \) -a \( -f /etc/rc.local \) ; then
228   if ! cat /etc/rc.local | grep "$STARTCMD"; then
229     if cat /etc/rc.local | grep fcron; then     
230       echo "Fcron seems to be in /etc/rc.local, but not with the appropriate options :"
231       echo "you should probably correct this file in order to run fcron with $STARTCMD."
232       INSTALLED=1
233     else
234       if test $ANSWER -eq 2; then
235         while test \( ! -z "$INSTALL" \) -a \( "$INSTALL" != "y" \) -a \( "$INSTALL" != "n" \);
236         do
237           echo "Would you like to add $STARTCMD in the file /etc/rc.local ?"
238           echo -n "Please answer with 'y' or 'n' (default: 'y'): "
239           read INSTALL NOTHING
240         done
241       # automatic answer given by configure script (option --with-answer-all)
242       elif test $ANSWER -eq 1; then
243         INSTALL="y"
244       else
245         INSTALL="n"
246       fi
247       if test \( -z "$INSTALL" \) -o \( "$INSTALL" = "y" \); then
248         echo $STARTCMD >> /etc/rc.local
249         INSTALLED=1
250       else
251         INSTALLED=0
252       fi
253     fi
254   else
255     echo "Fcron is already in /etc/rc.local."
256     INSTALLED=1
257   fi
258 fi
259
260
261 if test "$INSTALLED" -eq 0; then
262 echo
263 echo "Installation process failed to install fcron in your init scripts :"
264 echo "please do it manually."
265 fi
266
267
268 if PID=`pidof fcron`; then
269   KILL="kill -TERM $PID"
270   KILLSTR="kill -TERM \`pidof fcron\`"
271 else
272   KILL="killall -TERM fcron"
273   KILLSTR=$KILL
274   COMMENT="WARNING : this command may not have the desired effect on non-Linux systems.\n"
275   PID="test -z on PID is not need in this case"
276 fi
277
278 # NEED_UPDATE is set at the beginning of this script
279 if test $NEED_UPDATE -eq 0; then
280   # we stop fcron like this (not using "fcron restart") because
281   # an old version of fcron may not stop correctly otherwise.
282   echo 
283   echo "You should now stop the old version of fcron and start the new one."
284   RESTART="nothing"
285   COMMENT=""
286   if test -z "$PID"; then
287     echo "Fcron is not running."
288     KILL=""
289     COMMENT=""
290   fi
291   if test "$SYSV" -eq 1; then
292     CMD="$ROOTDIR/init.d/fcron start"
293   else
294     CMD=$STARTCMD
295   fi
296   if test $ANSWER -eq 2; then
297     while test \( ! -z "$RESTART" \) -a \( "$RESTART" != "y" \) -a \( "$RESTART" != "n" \);
298     do
299       if test ! -z "$KILL"; then
300         echo "Would you like to do it with a '"$KILLSTR"' ?"
301         echo -n $COMMENT
302         echo "followed by a '"$CMD"' ?"
303       else
304         echo "Would you like to start it by '"$CMD"' ?"
305       fi
306         echo -n "Please answer with 'y' or 'n' (default: 'y'): "
307         read RESTART NOTHING
308     done
309   # automatic answer given by configure script (option --with-answer-all)
310   elif test $ANSWER -eq 1; then
311     RESTART="y"
312   else
313     RESTART="n"
314   fi
315   if test \( -z "$RESTART" \) -o \( "$RESTART" = "y" \); then
316     $KILL
317     sleep 2   # wait for fcron to stop
318     $CMD
319   fi
320
321 else # test $NEED_UPDATE -eq 0
322
323   echo 
324   echo "You should now stop the old version fcron."
325   STOP="nothing"
326   COMMENT=""
327   if test -z "$PID"; then
328     echo "Fcron is not running."
329     echo "You may start it after having updated the fcrontabs."
330     STOPPED=1
331   else
332     if test $ANSWER -eq 2; then
333       while test \( ! -z "$STOP" \) -a \( "$STOP" != "y" \) -a \( "$STOP" != "n" \);
334       do
335         echo "Would you like to do it with a '"$KILLSTR"'"
336         echo -n $COMMENT
337         echo -n "Please answer with 'y' or 'n' (default: 'y'): "
338         read STOP NOTHING
339       done
340       # automatic answer given by configure script (option --with-answer-all)
341     elif test $ANSWER -eq 1; then
342       STOP="y"
343     else
344       STOP="n"
345     fi
346     if test \( -z "$STOP" \) -o \( "$STOP" = "y" \); then
347       $KILL
348       STOPPED=1
349     fi
350   fi
351
352   echo
353   if test "$STOPPED" = "1"; then
354     echo "You should now update the fcrontabs format using convert-fcrontab program."
355   else
356     echo "After having restarted fcron, you should update the fcrontabs format"
357     echo "using the convert-fcrontab program ($SRCDIR/convert-fcrontab)"
358     echo "(run \"convert-fcrontab -h\" to get help) and then start the new version"
359     echo "of fcron."
360     exit 0
361   fi
362   echo "As a matter of fact, you must know that fcrontabs installed by an old"
363   echo "version (<1.1.x) of fcrontab won't work anymore with this version if you don't"
364   echo "update their format."
365
366   UPDATE="nothing"
367   # reinstall the fcrontabs
368   if test $ANSWER -eq 2; then
369     while test \( ! -z "$UPDATE" \) -a \( "$UPDATE" != "y" \) -a \( "$UPDATE" != "n" \);
370     do
371       echo "Would you like to do it now ?"
372       echo -n "Please answer with 'y' or 'n' (default: 'y'): "
373       read UPDATE NOTHING
374     done
375   elif test $ANSWER -eq 1; then
376     UPDATE="y"
377   else
378     UPDATE="n"
379   fi
380   if test \( -z "$UPDATE" \) -o \( "$UPDATE" = "y" \); then
381     for FILE in $FCRONTABS/* ; do \
382       if test "$FILE" != "$FCRONTABS/*"; then
383         BASENAME=`basename $FILE` ; \
384         FCRONTAB=`echo "$BASENAME" | \
385         sed "s|.*orig|| ; s|fcrontab.sig|| ; s|rm.*||"` ; \
386         ( test ! -z "$FCRONTAB" && $SRCDIR/convert-fcrontab $FCRONTAB ) \
387             || echo -n ""; \
388       fi
389     done
390   fi
391
392   # start the new version of fcron
393   echo 
394   echo "You should now start the new version of fcron."
395   START="nothing"
396   COMMENT=""
397   if test "$SYSV" -eq 1; then
398     CMD="$ROOTDIR/init.d/fcron start"
399   else
400     CMD=$STARTCMD
401   fi
402   if test $ANSWER -eq 2; then
403     while test \( ! -z "$START" \) -a \( "$START" != "y" \) -a \( "$START" != "n" \);
404     do
405       echo "Would you like to do it with a '"$CMD"'"
406       echo -n "Please answer with 'y' or 'n' (default: 'y'): "
407       read START NOTHING
408     done
409     # automatic answer given by configure script (option --with-answer-all)
410   elif test $ANSWER -eq 1; then
411     START="y"
412   else
413     START="n"
414   fi
415   if test \( -z "$START" \) -o \( "$START" = "y" \); then
416     $CMD
417   fi
418
419 fi