Git init
[external/insserv.git] / debian / run-testsuite
1 #!/bin/bash
2
3 basedir=$(dirname $0)
4 . $basedir/../tests/suite
5
6 if head -1 debian/changelog | grep -q UNRELEASED ; then
7     severity=check
8 else
9     severity=test
10 fi
11
12 update_conf() {
13 set +C
14 cat <<'EOF' > $insconf
15 $local_fs       +mountall +umountfs
16 $network        +networking +ifupdown
17 $named          +named +dnsmasq +lwresd +bind9 $network
18 $remote_fs      $local_fs +mountnfs +mountnfs-bootclean +umountnfs +sendsigs
19 $syslog         +syslog +sysklogd
20 $portmap        portmap
21 $time           hwclock
22 <interactive>   udev mountdevsubfs checkroot checkfs console-screen
23 EOF
24 set -C
25 }
26 ##########################################################################
27 test_normal_sequence() {
28 echo
29 echo "info: test normal boot sequence scripts, and their order"
30 echo
31
32 insertscript mountkernfs.sh <<'EOF'
33 ### BEGIN INIT INFO
34 # Provides:          mountkernfs
35 # Required-Start:
36 # Required-Stop:
37 # Should-Start:      glibc
38 # Default-Start:     S
39 # Default-Stop:
40 ### END INIT INFO
41 EOF
42
43 insertscript mountdevsubfs.sh <<'EOF'
44 ### BEGIN INIT INFO
45 # Provides:          mountdevsubfs mountvirtfs
46 # Required-Start:    mountkernfs
47 # Required-Stop:
48 # Should-Start:      udev
49 # Default-Start:     S
50 # Default-Stop:
51 ### END INIT INFO
52 EOF
53
54 insertscript checkroot.sh <<'EOF'
55 ### BEGIN INIT INFO
56 # Provides:          checkroot
57 # Required-Start:    mountdevsubfs
58 # Required-Stop:
59 # Should-Start:      keymap hwclockfirst
60 # Should-stop:
61 # Default-Start:     S
62 # Default-Stop:
63 ### END INIT INFO
64 EOF
65
66 insertscript ifupdown-clean <<'EOF'
67 ### BEGIN INIT INFO
68 # Provides:          ifupdown-clean
69 # Required-Start:    checkroot
70 # Required-Stop:
71 # Default-Start:     S
72 # Default-Stop:
73 ### END INIT INFO
74 EOF
75
76 insertscript ifupdown <<'EOF'
77 ### BEGIN INIT INFO
78 # Provides:          ifupdown
79 # Required-Start:    ifupdown-clean
80 # Required-Stop:     $local_fs
81 # Default-Start:     S
82 # Default-Stop:      0 6
83 ### END INIT INFO
84 EOF
85
86 insertscript checkfs.sh <<'EOF'
87 ### BEGIN INIT INFO
88 # Provides:          checkfs
89 # Required-Start:    checkroot
90 # Required-Stop:
91 # Should-Start:      lvm cryptdisks
92 # Should-Stop:
93 # Default-Start:     S
94 # Default-Stop:
95 ### END INIT INFO
96 EOF
97
98 insertscript mountall.sh <<'EOF'
99 ### BEGIN INIT INFO
100 # Provides:          mountall
101 # Required-Start:    checkfs
102 # Required-Stop:
103 # Should-Start:      lvm
104 # Should-Stop:
105 # Default-Start:     S
106 # Default-Stop:
107 ### END INIT INFO
108 EOF
109
110 insertscript mountnfs.sh <<'EOF'
111 ### BEGIN INIT INFO
112 # Provides:          mountnfs
113 # Required-Start:    $local_fs
114 # Required-Stop:
115 # Should-Start:      $network
116 # Default-Start:     S
117 # Default-Stop:
118 ### END INIT INFO
119 EOF
120
121 insertscript beforenfs <<'EOF'
122 ### BEGIN INIT INFO
123 # Provides:          beforenfs
124 # Required-Start:    $local_fs
125 # Required-Stop:
126 # X-Start-Before:    mountnfs
127 # Default-Start:     S
128 # Default-Stop:
129 ### END INIT INFO
130 EOF
131
132 insertscript hwclock.sh <<'EOF'
133 ### BEGIN INIT INFO
134 # Provides:          hwclock
135 # Required-Start:    mountdevsubfs
136 # Required-Stop:     $local_fs
137 # Default-Start:     S
138 # Default-Stop:      0 6
139 ### END INIT INFO
140 EOF
141
142 insertscript killprocs <<'EOF'
143 ### BEGIN INIT INFO
144 # Provides:          killprocs
145 # Required-Start:    $local_fs
146 # Required-Stop:
147 # Default-Start:     1
148 # Default-Stop:
149 ### END INIT INFO
150 EOF
151
152 insertscript single <<'EOF'
153 ### BEGIN INIT INFO
154 # Provides:          single
155 # Required-Start:    $local_fs killprocs $all
156 # Required-Stop:
157 # Default-Start:     1
158 # Default-Stop:
159 ### END INIT INFO
160 EOF
161
162 insertscript needlocalfs <<'EOF'
163 ### BEGIN INIT INFO
164 # Provides:          needlocalfs
165 # Required-Start:    $local_fs
166 # Required-Stop:     $local_fs
167 # Default-Start:     2 3 4 5
168 # Default-Stop:      0 1 6
169 ### END INIT INFO
170 EOF
171
172 insertscript needallfs <<'EOF'
173 ### BEGIN INIT INFO
174 # Provides:          needallfs
175 # Required-Start:    $remote_fs
176 # Required-Stop:     $remote_fs
177 # Default-Start:     2 3 4 5
178 # Default-Stop:      0 1 6
179 ### END INIT INFO
180 EOF
181
182 insertscript sysklogd <<'EOF'
183 ### BEGIN INIT INFO
184 # Provides:          syslog
185 # Required-Start:    $remote_fs
186 # Required-Stop:     $remote_fs
187 # Default-Start:     2 3 4 5
188 # Default-Stop:      0 1 6
189 ### END INIT INFO
190 EOF
191
192 insertscript reboot <<'EOF'
193 ### BEGIN INIT INFO
194 # Provides:          reboot
195 # Required-Start:
196 # Required-Stop:
197 # Default-Start:
198 # Default-Stop:      6
199 ### END INIT INFO
200 EOF
201
202 insertscript halt <<'EOF'
203 ### BEGIN INIT INFO
204 # Provides:          halt
205 # Required-Start:
206 # Required-Stop:
207 # Default-Start:
208 # Default-Stop:      0
209 ### END INIT INFO
210 EOF
211
212 insertscript umountroot <<'EOF'
213 ### BEGIN INIT INFO
214 # Provides:          umountroot
215 # Required-Start:
216 # Required-Stop:
217 # Should-Stop:       halt reboot
218 # Default-Start:
219 # Default-Stop:      0 6
220 ### END INIT INFO
221 EOF
222
223 insertscript umountfs <<'EOF'
224 ### BEGIN INIT INFO
225 # Provides:          umountfs
226 # Required-Start:
227 # Required-Stop:     umountroot
228 # Default-Start:
229 # Default-Stop:      0 6
230 ### END INIT INFO
231 EOF
232
233 insertscript umountnfs <<'EOF'
234 ### BEGIN INIT INFO
235 # Provides:          umountnfs
236 # Required-Start:
237 # Required-Stop:     umountfs
238 # Should-Stop:       $network $portmap nfs-common
239 # Default-Start:
240 # Default-Stop:      0 6
241 ### END INIT INFO
242 EOF
243
244 insertscript needallfs2 <<'EOF'
245 ### BEGIN INIT INFO
246 # Provides:          needallfs2
247 # Required-Start:    $remote_fs
248 # Required-Stop:     $remote_fs
249 # X-Start-Before:    needallfs
250 # Default-Start:     2 3 4 5
251 # Default-Stop:      0 1 6
252 ### END INIT INFO
253 EOF
254
255 insertscript kexec <<'EOF'
256 ### BEGIN INIT INFO
257 # Provides:             kexec
258 # Required-Start:
259 # Required-Stop:        reboot
260 # X-Stop-After:         umountroot
261 # Default-Start:
262 # Default-Stop:         6
263 ### END INIT INFO
264 EOF
265
266 insertscript networking <<'EOF'
267 ### BEGIN INIT INFO
268 # Provides:          networking
269 # Required-Start:    mountkernfs ifupdown $local_fs
270 # Required-Stop:     ifupdown $local_fs
271 # Default-Start:     S
272 # Default-Stop:      0 6
273 ### END INIT INFO
274 EOF
275
276 insertscript nolsbheader <<'EOF'
277 EOF
278
279 list_rclinks
280
281 check_order S mountkernfs.sh mountdevsubfs.sh
282 check_order S ifupdown-clean ifupdown
283 check_order S ifupdown-clean ifupdown
284 check_order S mountall.sh mountnfs.sh
285 check_order S mountall.sh beforenfs
286 check_order S beforenfs mountnfs.sh
287
288 check_order 0 needallfs umountnfs
289 check_order 0 umountroot halt
290
291 check_order 1 killprocs single
292 check_order 1 needallfs killprocs
293
294 check_order 2 needlocalfs needallfs
295 check_order 2 needlocalfs nolsbheader
296 check_order 2 sysklogd nolsbheader
297 check_order 2 needallfs2 needallfs
298
299 check_order 6 needallfs umountnfs
300 check_order 6 nolsbheader umountnfs
301 check_order 6 umountfs umountroot
302 check_order 6 umountnfs networking
303 check_order 6 networking ifupdown
304 check_order 6 umountnfs umountfs
305 check_order 6 umountroot reboot
306 check_order 6 umountroot kexec
307 check_order 6 kexec reboot
308 }
309 ##########################################################################
310 test_override_files() {
311 echo
312 echo "info: test if override files replace headers in the file"
313 echo
314
315 initdir_purge
316
317 # Two scripts with a loop between them
318 insertscript base <<'EOF' || true
319 ### BEGIN INIT INFO
320 # Provides:          base
321 # Required-Start:
322 # Required-Stop:
323 # Default-Start:     S
324 # Default-Stop:
325 ### END INIT INFO
326 EOF
327
328 insertscript mover <<'EOF' || true
329 ### BEGIN INIT INFO
330 # Provides:          mover
331 # Required-Start:    base
332 # Required-Stop:
333 # Default-Start:     S
334 # Default-Stop:
335 ### END INIT INFO
336 EOF
337
338 check_order S base mover
339
340 mkdir -p $overridedir
341 cat <<'EOF' > $overridedir/mover
342 ### BEGIN INIT INFO
343 # Provides:          mover
344 # Required-Start:
345 # Required-Stop:
346 # X-Start-Before:    base
347 # Default-Start:     S
348 # Default-Stop:
349 ### END INIT INFO
350 EOF
351
352 insserv_reg mover
353
354 list_rclinks
355
356 # Make sure the override file moved mover before base
357 check_order S mover base
358 rm -rf $overridedir
359 }
360 ##########################################################################
361 test_override_loop() {
362 echo
363 echo "info: testing to insert scripts with a loop, and the effect of an override file"
364 echo
365
366 initdir_purge
367
368 # Two scripts with a loop between them
369 if insertscript loop1 <<'EOF' ; then
370 ### BEGIN INIT INFO
371 # Provides:          loop1
372 # Required-Start:    loop2
373 # Required-Stop:
374 # Default-Start:     S
375 # Default-Stop:
376 ### END INIT INFO
377 EOF
378     error "inserting script with missing dependencies did not fail"
379 fi
380
381 insertscript loop2 <<'EOF' || true
382 ### BEGIN INIT INFO
383 # Provides:          loop2
384 # Required-Start:    loop1
385 # Required-Stop:
386 # Default-Start:     S
387 # Default-Stop:
388 ### END INIT INFO
389 EOF
390
391 # Test if override file can be used to break the loop
392 mkdir -p $overridedir
393 cat <<'EOF' > $overridedir/loop1
394 ### BEGIN INIT INFO
395 # Provides:          loop1
396 # Required-Start:
397 # Required-Stop:
398 # Default-Start:     S
399 # Default-Stop:
400 ### END INIT INFO
401 EOF
402
403 check_script_not_present S loop1
404 check_script_not_present S loop2
405
406 insserv_reg loop1 || true
407 insserv_reg loop2 || true
408
409 check_order S loop1 loop2
410 rm -rf $overridedir
411 }
412 ##########################################################################
413
414 test_override_remove() {
415 echo
416 echo "info: Try to reproduce BTS #540866"
417 echo
418
419 initdir_purge
420
421 addscript testscript <<'EOF'
422 ### BEGIN INIT INFO
423 # Provides:          testscript
424 # Required-Start:
425 # Required-Stop:
426 # Default-Start:     2 3 4 5
427 # Default-Stop:      0 1 6
428 ### END INIT INFO
429 EOF
430
431 mkdir -p ${overridedir}/.
432 cat >${overridedir}/testscript <<'EOF'
433 ### BEGIN INIT INFO
434 # Provides:          testscript
435 # Required-Start:
436 # Required-Stop:
437 # Default-Start:     2 4 5
438 # Default-Stop:      0 1 6
439 ### END INIT INFO
440 EOF
441
442 insserv_reg testscript
443
444 list_rclinks
445
446 check_script_not_present 3 testscript
447
448 echo info: Trying to remove the script
449
450 insserv_del testscript
451
452 list_rclinks
453
454 check_script_not_present 3 testscript
455 }
456
457 ##########################################################################
458 test_long_loop() {
459 echo
460 echo "info: testing to insert scripts with a longer loop, making sure it fail"
461 echo
462
463 initdir_purge
464
465 # Three scripts with a loop between them, make sure introducing the
466 # loop fail, as it will make insserv generate a unstable and broken
467 # boot and shutdown sequence.
468 insertscript loop1 <<'EOF'
469 ### BEGIN INIT INFO
470 # Provides:          loop1
471 # Required-Start:
472 # Required-Stop:
473 # Default-Start:     S
474 # Default-Stop:
475 ### END INIT INFO
476 EOF
477
478 insertscript loop2 <<'EOF' || true
479 ### BEGIN INIT INFO
480 # Provides:          loop2
481 # Required-Start:    loop1
482 # Required-Stop:
483 # Default-Start:     S
484 # Default-Stop:
485 ### END INIT INFO
486 EOF
487
488 if insertscript loop3 <<'EOF' ; then
489 ### BEGIN INIT INFO
490 # Provides:          loop3
491 # Required-Start:    loop2
492 # Required-Stop:
493 # X-Start-Before:    loop1
494 # Default-Start:     S
495 # Default-Stop:
496 ### END INIT INFO
497 EOF
498     error "inserting script causing a loop did not fail"
499 fi
500 }
501 ##########################################################################
502 test_combined_loop() {
503 # Test real loop in the combined start and stop sequence.  There is no
504 # loop in the start sequence, and no loop in the stop sequence, but in
505 # the combined graph insserv is creating internally, there is a loop.
506 # This make sense, as scripts need to be installed in dependency
507 # order, and there is no way to install these scripts that make sure
508 # both start and stop dependencies are fulfilled.
509 echo
510 echo "info: test handling of loops in the combination of start and stop sequences"
511 echo
512
513 initdir_purge
514
515 insertscript startfirst <<'EOF' || true
516 ### BEGIN INIT INFO
517 # Provides:          startfirst
518 # Required-Start:
519 # Required-Stop:     startsecond
520 # Default-Start:     S
521 # Default-Stop:      6
522 ### END INIT INFO
523 EOF
524
525 insertscript startsecond <<'EOF' || true
526 ### BEGIN INIT INFO
527 # Provides:          startsecond
528 # Required-Start:    startfirst
529 # Required-Stop:
530 # Default-Start:     S
531 # Default-Stop:      6
532 ### END INIT INFO
533 EOF
534
535 list_rclinks
536
537 test_order S startfirst startsecond
538 test_order 6 startsecond startfirst
539 }
540 ##########################################################################
541 test_fake_loop() {
542 # Test another fake loop.  This one should work, as it is possible to
543 # install the two scripts in sequence because one of the dependencies
544 # are optional.  It does not with insserv today.
545 echo
546 echo "info: test handling of 'fake' loops in the combination of start and stop sequences"
547 echo
548
549 initdir_purge
550
551 insertscript startfirst_stopfirst <<'EOF' || true
552 ### BEGIN INIT INFO
553 # Provides:          startfirst_stopfirst
554 # Required-Start:
555 # Required-Stop:
556 # Should-Stop:       startsecond_stoplast
557 # Default-Start:     S
558 # Default-Stop:      6
559 ### END INIT INFO
560 EOF
561
562 insertscript startsecond_stoplast <<'EOF' || true
563 ### BEGIN INIT INFO
564 # Provides:          startsecond_stoplast
565 # Required-Start:    startfirst_stopfirst
566 # Required-Stop:
567 # Default-Start:     S
568 # Default-Stop:      6
569 ### END INIT INFO
570 EOF
571
572 list_rclinks
573
574 check_order S startfirst_stopfirst startsecond_stoplast
575 check_order 6 startfirst_stopfirst startsecond_stoplast
576 }
577 ##########################################################################
578 test_fake_loop_reverse() {
579 # Test another fake loop using reverse dependencies to document that
580 # it can happen based on information provided in one package only.
581 # This should work, as it is possible to install the two scripts in
582 # sequence because one of the dependencies are optional.  It does not
583 # with insserv today.  Note thought that the generated order is
584 # different from the one above.
585
586 echo
587 echo "info: test handling of 'fake' loops using reverse depends"
588 echo
589
590 initdir_purge
591
592 insertscript startfirst_stopfirst <<'EOF' || true
593 ### BEGIN INIT INFO
594 # Provides:          startfirst_stopfirst
595 # Required-Start:
596 # Required-Stop:
597 # Default-Start:     S
598 # Default-Stop:      6
599 ### END INIT INFO
600 EOF
601
602 insertscript startsecond_stoplast <<'EOF' || true
603 ### BEGIN INIT INFO
604 # Provides:          startsecond_stoplast
605 # Required-Start:    startfirst_stopfirst
606 # Required-Stop:
607 # X-Stop-After:      startfirst_stopfirst
608 # Default-Start:     S
609 # Default-Stop:      6
610 ### END INIT INFO
611 EOF
612
613 list_rclinks
614
615 # #458582
616 check_order S startfirst_stopfirst startsecond_stoplast
617 check_order 6 startfirst_stopfirst startsecond_stoplast 
618 }
619 ##########################################################################
620 test_badscript() {
621 echo
622 echo "info: test if bad script in init.d/ with no symlinks in rc*.d/ make problems"
623 echo
624
625 initdir_purge
626
627 addscript sitelocal <<'EOF' || true
628 ### BEGIN INIT INFO
629 # Provides:          duplicate
630 # Required-Start:    $remote_fs
631 # Required-Stop:     $remote_fs
632 # Default-Start:     S
633 # Default-Stop:      6
634 ### END INIT INFO
635 EOF
636
637 insertscript distroglobal <<'EOF' || true
638 ### BEGIN INIT INFO
639 # Provides:          dublicate
640 # Required-Start:    $remote_fs
641 # Required-Stop:     $remote_fs
642 # Default-Start:     S
643 # Default-Stop:      6
644 ### END INIT INFO
645 EOF
646
647 list_rclinks
648
649 check_script_present S distroglobal
650 }
651 ##########################################################################
652 test_onlystart() {
653 echo
654 echo "info: check that it work to insert scripts with only start runlevels"
655 echo
656
657 initdir_purge
658
659 insertscript onlystart <<'EOF' || true
660 ### BEGIN INIT INFO
661 # Provides:          onlystart
662 # Required-Start:    $remote_fs
663 # Required-Stop:     $remote_fs
664 # Default-Start:     2 3 4 5
665 # Default-Stop:
666 ### END INIT INFO
667 EOF
668
669 list_rclinks
670
671 check_script_present 2 onlystart
672 check_script_present 3 onlystart
673 check_script_present 4 onlystart
674 check_script_present 5 onlystart
675
676 check_script_not_present 0 onlystart
677 check_script_not_present 1 onlystart
678 check_script_not_present 6 onlystart
679 }
680 ##########################################################################
681 test_onlystop() {
682 echo
683 echo "info: check that it work to insert scripts with only stop runlevels"
684 echo
685 # This test check that the common way to update the runlevels used by
686 # a given script is working.  It simulates these calls to update-rc.d:
687 #  update-rc.d oldscript default
688 #  update-rc.d -f oldscript remove
689 #  update-rc.d oldscript start 20 2 3 4 5 . stop 20 1 .
690
691 initdir_purge
692
693 insertscript onlystop <<'EOF' || true
694 ### BEGIN INIT INFO
695 # Provides:          onlystop
696 # Required-Start:    $remote_fs
697 # Required-Stop:     $remote_fs
698 # Default-Start:
699 # Default-Stop:      0 6
700 ### END INIT INFO
701 EOF
702
703 list_rclinks
704
705 check_script_present 0 onlystop
706 check_script_present 6 onlystop
707
708 check_script_not_present 1 onlystop
709 check_script_not_present 2 onlystop
710 check_script_not_present 3 onlystop
711 check_script_not_present 4 onlystop
712 check_script_not_present 5 onlystop
713 check_script_not_present S onlystop
714 }
715 ##########################################################################
716 test_removal() {
717 echo
718 echo "info: test if script removal removes all symlinks."
719 echo
720 # This test check that the common way to update the runlevels used by
721 # a given script is working.  It simulates these calls to update-rc.d:
722 #  update-rc.d oldscript default
723 #  update-rc.d -f oldscript remove
724 #  update-rc.d oldscript start 20 2 3 4 5 . stop 20 1 .
725
726 initdir_purge
727
728 insertscript oldscript <<'EOF' || true
729 ### BEGIN INIT INFO
730 # Provides:          oldscript
731 # Required-Start:    $remote_fs
732 # Required-Stop:     $remote_fs
733 # Default-Start:     2 3 4 5
734 # Default-Stop:      0 1 6
735 ### END INIT INFO
736 EOF
737
738 # Check that the problematic symlinks are presend, as well as one that
739 # is OK.
740 check_script_present 0 oldscript
741 check_script_present 1 oldscript
742 check_script_present 3 oldscript
743 check_script_present 6 oldscript
744
745 set +C
746 addscript oldscript <<'EOF' || true
747 ### BEGIN INIT INFO
748 # Provides:          oldscript
749 # Required-Start:    $remote_fs
750 # Required-Stop:     $remote_fs
751 # Default-Start:     2 4 5
752 # Default-Stop:      1
753 ### END INIT INFO
754 EOF
755 set -C
756
757 # Remove old symlinks
758 insserv_del oldscript
759 # Insert new ones, this time without runlevel 0 and 6
760 insserv_reg oldscript
761
762 list_rclinks
763
764 check_script_not_present 0 oldscript
765 check_script_present 1 oldscript
766 check_script_present 2 oldscript
767 check_script_not_present 3 oldscript
768 check_script_not_present 6 oldscript
769 }
770
771 ##########################################################################
772 test_segfault_virtfac() {
773 echo
774 echo "info: detect segfault caused by script providing virtual facility."
775 echo
776
777 initdir_purge
778
779 insertscript badheaderscript <<'EOF' || true
780 ### BEGIN INIT INFO
781 # Provides:          $syslog
782 # Required-Start:
783 # Required-Stop:
784 # Default-Start:     2 3 4 5
785 # Default-Stop:      0 1 6
786 ### END INIT INFO
787 EOF
788
789 # Problem is only triggered if there are start or stop symlinks for
790 # the script present.
791 mkdir -p $initddir/../rc2.d
792 ln -s ../init.d/badheaderscript $initddir/../rc2.d/S02badheaderscript
793
794 # This one segfaults
795 insertscript okscript <<'EOF' || true
796 ### BEGIN INIT INFO
797 # Provides:          okscript
798 # Required-Start:    $syslog
799 # Required-Stop:
800 # Default-Start:     2 3 4 5
801 # Default-Stop:      0 1 6
802 ### END INIT INFO
803 EOF
804
805 list_rclinks
806
807 check_script_present 2 okscript
808 }
809 ##########################################################################
810 test_incorrect_startscripts() {
811 echo
812 echo "info: Check if insserv add start symlinks for scripts that"
813 echo "info: currently do not have them. #492526"
814 echo
815
816 initdir_purge
817
818 insertscript disablestartscript <<'EOF' || true
819 ### BEGIN INIT INFO
820 # Provides:          disablestartscript
821 # Required-Start:
822 # Required-Stop:
823 # Default-Start:     2 3 4 5
824 # Default-Stop:      0 1 6
825 ### END INIT INFO
826 EOF
827 list_rclinks
828
829 check_script_present 2 disablestartscript
830 check_script_present 5 disablestartscript
831 check_script_not_present S disablestartscript
832 check_script_present 1 disablestartscript
833
834 rm $initddir/../rc{2,3,4,5}.d/S??disablestartscript
835
836 # Update symlinks, see if it add start symlinks
837 insserv_reg .
838
839 list_rclinks
840
841 check_script_not_present 2 disablestartscript
842 check_script_not_present 3 disablestartscript
843 check_script_not_present 4 disablestartscript
844 check_script_not_present 5 disablestartscript
845 check_script_not_present S disablestartscript
846 check_script_present 0 disablestartscript
847 check_script_present 1 disablestartscript
848 }
849 ##########################################################################
850 test_incorrect_stopscripts() {
851 echo
852 echo "info: Check if insserv add stop symlinks for scripts that"
853 echo "info: currently do not have them."
854 echo
855
856 initdir_purge
857
858 insertscript disablestopscript <<'EOF' || true
859 ### BEGIN INIT INFO
860 # Provides:          disablestopscript
861 # Required-Start:
862 # Required-Stop:
863 # Default-Start:     2 3 4 5
864 # Default-Stop:      0 1 6
865 ### END INIT INFO
866 EOF
867 list_rclinks
868
869 check_script_present 2 disablestopscript
870 check_script_present 5 disablestopscript
871 check_script_not_present S disablestopscript
872 check_script_present 1 disablestopscript
873
874 rm $initddir/../rc{0,1}.d/K??disablestopscript
875
876 # Update symlinks, see if it add stop symlinks
877 insserv_reg .
878
879 list_rclinks
880
881 check_script_present 2 disablestopscript
882 check_script_present 5 disablestopscript
883 check_script_not_present S disablestopscript
884 check_script_not_present 0 disablestopscript
885 check_script_not_present 1 disablestopscript
886 }
887 ##########################################################################
888 test_newbug_keepoldorder() {
889 echo
890 echo "info: Verify that introducing a loop in a working system do"
891 echo "info: not change the order of the scripts currently on disk."
892 echo
893
894 initdir_purge
895
896 insertscript mountall <<'EOF' || true
897 ### BEGIN INIT INFO
898 # Provides:          mountall
899 # Required-Start:
900 # Required-Stop:
901 # Default-Start:     S
902 # Default-Stop:
903 ### END INIT INFO
904 EOF
905
906 insertscript needlocal <<'EOF' || true
907 ### BEGIN INIT INFO
908 # Provides:          needlocal
909 # Required-Start:    $local_fs
910 # Required-Stop:     $local_fs
911 # Default-Start:     S
912 # Default-Stop:      6
913 ### END INIT INFO
914 EOF
915
916 insertscript needremote <<'EOF' || true
917 ### BEGIN INIT INFO
918 # Provides:          needremote
919 # Required-Start:    $remote_fs needlocal
920 # Required-Stop:     $remote_fs needlocal
921 # Default-Start:     S
922 # Default-Stop:      6
923 ### END INIT INFO
924 EOF
925
926 insertscript needboth <<'EOF' || true
927 ### BEGIN INIT INFO
928 # Provides:          needboth
929 # Required-Start:    needlocal needremote
930 # Required-Stop:     needlocal needremote
931 # Default-Start:     S
932 # Default-Stop:      6
933 ### END INIT INFO
934 EOF
935
936 list_rclinks
937
938 check_order S mountall needlocal
939 check_order S mountall needremote
940 check_order S mountall needboth
941 check_order S needlocal needremote
942 check_order S needlocal needboth
943 check_order S needremote needboth
944
945 # Then introduce buggy dependencies in an existing script
946 set +C
947 addscript needboth <<'EOF' || true
948 ### BEGIN INIT INFO
949 # Provides:          needboth
950 # Required-Start:    $remote_fs
951 # Required-Stop:     $remote_fs
952 # X-Start-Before:    $local_fs
953 # Default-Start:     S
954 # Default-Stop:      6
955 ### END INIT INFO
956 EOF
957 set -C
958
959 echo "info: calling insserv after introducing a bug in script needboth"
960 insserv_reg needboth || true
961
962 list_rclinks
963
964 # The severity of this test should be fatal, below is explanation about how
965 # new (1.11.10) and old (1.11.0) insserv version behaviour changed in this
966 # test.
967 #
968 # Hmm ... with this I've found out that the old insserv will
969 # run on a loop and therefore exit.  This loop was caused
970 # by the system facility $local_fs make the old insserv
971 # to do an exit ... now the problem is that the new insserv
972 # expands all system facility to their real requirements.
973 # This leads to the new behaviour as there is no node during
974 # the sorting algorithm which would cause such a loop.
975 #
976 # In other words: that the old insserv hasn't changed the
977 # order was simply a side effect of having a ghost node
978 # whereas the new insserv does not use such nodes anymore.
979 #
980 # If you would remove the `X-Start-Before: $local_fs' the
981 # old insserv will also change the boot order.
982
983 ${severity}_order S mountall needlocal
984 ${severity}_order S mountall needremote
985 ${severity}_order S mountall needboth
986 ${severity}_order S needlocal needremote
987 ${severity}_order S needlocal needboth
988 ${severity}_order S needremote needboth
989 }
990 ##########################################################################
991 test_start_before() {
992 echo
993 echo "info: Verify that X-start-before work as it should."
994 echo
995
996 initdir_purge
997
998 insertscript startlast <<'EOF' || true
999 ### BEGIN INIT INFO
1000 # Provides:          startlast
1001 # Required-Start:
1002 # Required-Stop:
1003 # Default-Start:     S
1004 # Default-Stop:
1005 ### END INIT INFO
1006 EOF
1007
1008 insertscript startfirst <<'EOF' || true
1009 ### BEGIN INIT INFO
1010 # Provides:          startfirst
1011 # Required-Start:
1012 # Required-Stop:
1013 # X-Start-Before:    startlast
1014 # Default-Start:     S
1015 # Default-Stop:
1016 ### END INIT INFO
1017 EOF
1018
1019 list_rclinks
1020
1021 check_order S startfirst startlast
1022 }
1023 ##########################################################################
1024 test_stop_after() {
1025 echo
1026 echo "info: Verify that X-stop-after work as it should."
1027 echo
1028
1029 initdir_purge
1030
1031 insertscript stopfirst <<'EOF' || true
1032 ### BEGIN INIT INFO
1033 # Provides:          stopfirst
1034 # Required-Start:
1035 # Required-Stop:
1036 # Default-Start:
1037 # Default-Stop:      0 6
1038 ### END INIT INFO
1039 EOF
1040
1041 insertscript stopafter <<'EOF' || true
1042 ### BEGIN INIT INFO
1043 # Provides:          stopafter
1044 # Required-Start:
1045 # Required-Stop:
1046 # X-Stop-After:      stopfirst
1047 # Default-Start:
1048 # Default-Stop:      0 6
1049 ### END INIT INFO
1050 EOF
1051
1052 list_rclinks
1053
1054 check_order 0 stopfirst stopafter
1055 }
1056 ##########################################################################
1057 test_adding_start() {
1058 echo
1059 echo "info: Make sure that adding start levels do not change an existing installation."
1060 echo
1061
1062 initdir_purge
1063
1064 insertscript addstartscript <<'EOF' || true
1065 ### BEGIN INIT INFO
1066 # Provides:          addstartscript
1067 # Required-Start:
1068 # Required-Stop:
1069 # Default-Start:
1070 # Default-Stop:      1
1071 ### END INIT INFO
1072 EOF
1073
1074 check_script_present 1 addstartscript
1075
1076 check_script_not_present S addstartscript
1077 check_script_not_present 0 addstartscript
1078 check_script_not_present 2 addstartscript
1079 check_script_not_present 3 addstartscript
1080 check_script_not_present 4 addstartscript
1081 check_script_not_present 5 addstartscript
1082 check_script_not_present 6 addstartscript
1083
1084 # Then change runlevel in existing script
1085 set +C
1086 addscript addstartscript <<'EOF' || true
1087 ### BEGIN INIT INFO
1088 # Provides:          addstartscript
1089 # Required-Start:
1090 # Required-Stop:
1091 # Default-Start:     2 3 4 5
1092 # Default-Stop:      1
1093 ### END INIT INFO
1094 EOF
1095 set -C
1096
1097 # Update script after changing the header
1098 insserv_reg addstartscript || true
1099
1100 list_rclinks
1101
1102 check_script_present 1 addstartscript
1103
1104 check_script_not_present S addstartscript
1105 check_script_not_present 0 addstartscript
1106 check_script_not_present 2 addstartscript
1107 check_script_not_present 3 addstartscript
1108 check_script_not_present 4 addstartscript
1109 check_script_not_present 5 addstartscript
1110 check_script_not_present 6 addstartscript
1111 }
1112 ##########################################################################
1113 test_removing_start() {
1114 echo
1115 echo "info: Make sure that removing start levels do not change an existing installation."
1116 echo
1117
1118 initdir_purge
1119
1120 insertscript remstartscript <<'EOF' || true
1121 ### BEGIN INIT INFO
1122 # Provides:          remstartscript
1123 # Required-Start:
1124 # Required-Stop:
1125 # Default-Start:     2 3 4 5
1126 # Default-Stop:      0 1 6
1127 ### END INIT INFO
1128 EOF
1129
1130 check_script_present 0 remstartscript
1131 check_script_present 1 remstartscript
1132 check_script_present 2 remstartscript
1133 check_script_present 3 remstartscript
1134 check_script_present 4 remstartscript
1135 check_script_present 5 remstartscript
1136 check_script_present 6 remstartscript
1137
1138 # Then change runlevel in existing script
1139 set +C
1140 addscript remstartscript <<'EOF' || true
1141 ### BEGIN INIT INFO
1142 # Provides:          remstartscript
1143 # Required-Start:
1144 # Required-Stop:
1145 # Default-Start:
1146 # Default-Stop:      0 1 6
1147 ### END INIT INFO
1148 EOF
1149 set -C
1150
1151 # Update script after changing the header
1152 insserv_reg remstartscript || true
1153
1154 list_rclinks
1155
1156 check_script_present 2 remstartscript
1157 check_script_present 3 remstartscript
1158 check_script_present 4 remstartscript
1159 check_script_present 5 remstartscript
1160 }
1161 ##########################################################################
1162 test_adding_stop() {
1163 echo
1164 echo "info: Make sure that adding stop levels do not change an existing installation."
1165 echo
1166
1167 initdir_purge
1168
1169 insertscript addstopscript <<'EOF' || true
1170 ### BEGIN INIT INFO
1171 # Provides:          addstopscript
1172 # Required-Start:
1173 # Required-Stop:
1174 # Default-Start:     S
1175 # Default-Stop:
1176 ### END INIT INFO
1177 EOF
1178
1179 check_script_present S addstopscript
1180 check_script_not_present 0 addstopscript
1181 check_script_not_present 1 addstopscript
1182 check_script_not_present 2 addstopscript
1183 check_script_not_present 3 addstopscript
1184 check_script_not_present 4 addstopscript
1185 check_script_not_present 5 addstopscript
1186 check_script_not_present 6 addstopscript
1187
1188 # Then change runlevel in existing script
1189 set +C
1190 addscript addstopscript <<'EOF' || true
1191 ### BEGIN INIT INFO
1192 # Provides:          addstopscript
1193 # Required-Start:
1194 # Required-Stop:
1195 # Default-Start:     S
1196 # Default-Stop:      0
1197 ### END INIT INFO
1198 EOF
1199 set -C
1200
1201 # Update script after changing the header
1202 insserv_reg addstopscript || true
1203
1204 list_rclinks
1205
1206 check_script_present S addstopscript
1207 check_script_not_present 0 addstopscript
1208 check_script_not_present 1 addstopscript
1209 check_script_not_present 2 addstopscript
1210 check_script_not_present 3 addstopscript
1211 check_script_not_present 4 addstopscript
1212 check_script_not_present 5 addstopscript
1213 check_script_not_present 6 addstopscript
1214 }
1215 ##########################################################################
1216 test_removing_stop() {
1217 echo
1218 echo "info: Make sure that removing stop levels do not change an existing installation."
1219 echo
1220
1221 initdir_purge
1222
1223 insertscript remstopscript <<'EOF' || true
1224 ### BEGIN INIT INFO
1225 # Provides:          remstopscript
1226 # Required-Start:
1227 # Required-Stop:
1228 # Default-Start:     S
1229 # Default-Stop:      0 6
1230 ### END INIT INFO
1231 EOF
1232
1233 check_script_present S remstopscript
1234 check_script_present 0 remstopscript
1235 check_script_present 6 remstopscript
1236
1237 check_script_not_present 1 remstopscript
1238 check_script_not_present 2 remstopscript
1239 check_script_not_present 3 remstopscript
1240 check_script_not_present 4 remstopscript
1241 check_script_not_present 5 remstopscript
1242
1243 # Then change runlevel in existing script
1244 set +C
1245 addscript remstopscript <<'EOF' || true
1246 ### BEGIN INIT INFO
1247 # Provides:          remstopscript
1248 # Required-Start:
1249 # Required-Stop:
1250 # Default-Start:     S
1251 # Default-Stop:
1252 ### END INIT INFO
1253 EOF
1254 set -C
1255
1256 # Update script after changing the header
1257 insserv_reg remstopscript || true
1258
1259 list_rclinks
1260
1261 check_script_present 0 remstopscript
1262 check_script_present 6 remstopscript
1263 }
1264 ##########################################################################
1265 test_duplicate_provides() {
1266 echo
1267 echo "info: test two initscripts providing same facility."
1268 echo "info: Not sure if this should fail or not."
1269 echo
1270
1271 initdir_purge
1272
1273 addscript one <<'EOF' || true
1274 ### BEGIN INIT INFO
1275 # Provides:          samefac
1276 # Required-Start:
1277 # Required-Stop:
1278 # Default-Start:     S
1279 # Default-Stop:
1280 ### END INIT INFO
1281 EOF
1282
1283 addscript two <<'EOF' || true
1284 ### BEGIN INIT INFO
1285 # Provides:          samefac
1286 # Required-Start:
1287 # Required-Stop:
1288 # Default-Start:     S
1289 # Default-Stop:
1290 ### END INIT INFO
1291 EOF
1292
1293 insserv_reg one || true
1294 insserv_reg two || true
1295
1296 list_rclinks
1297
1298 check_script_present S one
1299 ${severity}_script_not_present S two
1300 }
1301 ##########################################################################
1302 test_bogus_facility() {
1303 echo
1304 echo "info: test insertion of script requiring a virtual facility that doesn't exist"
1305 echo
1306
1307 initdir_purge
1308
1309 addscript needbogusvirtual <<'EOF'
1310 ### BEGIN INIT INFO
1311 # Provides:          needbogusvirtual
1312 # Required-Start:    $bogusvirtualfacility
1313 # Required-Stop:
1314 # Default-Start:     S
1315 # Default-Stop:
1316 ### END INIT INFO
1317 EOF
1318
1319 insserv_reg needbogusvirtual || true
1320
1321 list_rclinks
1322
1323 test_script_not_present S needbogusvirtual
1324 }
1325 ##########################################################################
1326 test_insserv_conf_d() {
1327 echo
1328 echo "info: test that /etc/insserv.conf.d/ is used"
1329 echo
1330
1331 initdir_purge
1332 rm -rf ${insconf}.d
1333 mkdir -p ${insconf}.d
1334
1335 # add a base service, to ensure check_order() is accurate
1336 insertscript dummy <<'EOF'
1337 ### BEGIN INIT INFO
1338 # Provides:          dummy
1339 # Required-Start:
1340 # Required-Stop:
1341 # Default-Start:     S
1342 # Default-Stop:
1343 ### END INIT INFO
1344 EOF
1345
1346 cat <<'EOF' > ${insconf}.d/facone
1347 $commvirtfac       +facone
1348 EOF
1349
1350 insertscript facone <<'EOF' || true
1351 ### BEGIN INIT INFO
1352 # Provides:          facone
1353 # Required-Start:    dummy
1354 # Required-Stop:
1355 # Default-Start:     S
1356 # Default-Stop:
1357 ### END INIT INFO
1358 EOF
1359
1360 cat <<'EOF' > ${insconf}.d/factwo
1361 $commvirtfac       +factwo
1362 EOF
1363
1364 insertscript factwo <<'EOF' || true
1365 ### BEGIN INIT INFO
1366 # Provides:          factwo
1367 # Required-Start:    dummy
1368 # Required-Stop:
1369 # Default-Start:     S
1370 # Default-Stop:
1371 ### END INIT INFO
1372 EOF
1373
1374 addscript service <<'EOF' || true
1375 ### BEGIN INIT INFO
1376 # Provides:          service
1377 # Required-Start:    $commvirtfac
1378 # Required-Stop:
1379 # Default-Start:     S
1380 # Default-Stop:
1381 ### END INIT INFO
1382 EOF
1383
1384 insserv_reg service || true
1385
1386 list_rclinks
1387
1388 check_script_present S service
1389 check_order S facone service
1390 check_order S factwo service
1391
1392 rm -rf ${insconf}.d
1393 }
1394 ##########################################################################
1395 test_broken_header() {
1396 echo
1397 echo "info: test insertion of script missing Required-{Start,Stop} fields"
1398 echo
1399
1400 initdir_purge
1401
1402 addscript badheader <<'EOF'
1403 ### BEGIN INIT INFO
1404 # Provides:          badheader
1405 # Default-Start:     2 3 4 5
1406 # Default-Stop:      0 1 6
1407 ### END INIT INFO
1408 EOF
1409
1410 insserv_reg badheader || true
1411
1412 list_rclinks
1413
1414 test_script_present 0 badheader
1415 test_script_present 1 badheader
1416 test_script_present 2 badheader
1417 test_script_present 3 badheader
1418 test_script_present 4 badheader
1419 test_script_present 5 badheader
1420 test_script_present 6 badheader
1421 }
1422 ##########################################################################
1423 test_noprovides_header() {
1424 echo
1425 echo "info: test insertion of script missing Provides fields"
1426 echo
1427
1428 initdir_purge
1429
1430 addscript badheader <<'EOF'
1431 ### BEGIN INIT INFO
1432 # Required-Start:
1433 # Required-Stop:
1434 # Default-Start:     2 3 4 5
1435 # Default-Stop:      0 1 6
1436 ### END INIT INFO
1437 EOF
1438
1439 insserv_reg badheader || true
1440
1441 list_rclinks
1442
1443 test_script_present 0 badheader
1444 test_script_present 1 badheader
1445 test_script_present 2 badheader
1446 test_script_present 3 badheader
1447 test_script_present 4 badheader
1448 test_script_present 5 badheader
1449 test_script_present 6 badheader
1450 }
1451 ##########################################################################
1452 test_no_default_start() {
1453 echo
1454 echo "info: test insertion of script missing Default-Start field"
1455 echo
1456
1457 initdir_purge
1458
1459 addscript nodefstart <<'EOF'
1460 ### BEGIN INIT INFO
1461 # Provides:          nodefstart
1462 # Required-Start:
1463 # Required-Stop:
1464 # Default-Stop:      0 6
1465 ### END INIT INFO
1466 EOF
1467
1468 insserv_reg nodefstart || true
1469
1470 list_rclinks
1471
1472 check_script_present 0 nodefstart
1473 check_script_present 6 nodefstart
1474
1475 check_script_not_present 2 nodefstart
1476 check_script_not_present 3 nodefstart
1477 check_script_not_present 4 nodefstart
1478 check_script_not_present 5 nodefstart
1479 }
1480 ##########################################################################
1481 test_no_default_stop() {
1482 echo
1483 echo "info: test insertion of script missing Default-Stop field"
1484 echo
1485
1486 initdir_purge
1487
1488 addscript nodefstop <<'EOF'
1489 ### BEGIN INIT INFO
1490 # Provides:          nodefstop
1491 # Required-Start:
1492 # Required-Stop:
1493 # Default-Start:     2 3 4 5
1494 ### END INIT INFO
1495 EOF
1496
1497 insserv_reg nodefstop || true
1498
1499 list_rclinks
1500
1501 check_script_present 2 nodefstop
1502 check_script_present 3 nodefstop
1503 check_script_present 4 nodefstop
1504 check_script_present 5 nodefstop
1505
1506 check_script_not_present 0 nodefstop
1507 check_script_not_present 1 nodefstop
1508 check_script_not_present 6 nodefstop
1509 }
1510 ##########################################################################
1511 test_initd_symlink() {
1512 echo
1513 echo "info: test that a symlink in /etc/init.d/ to another script does not cause problems"
1514 echo
1515
1516 initdir_purge
1517
1518 addscript symlinked <<'EOF'
1519 ### BEGIN INIT INFO
1520 # Provides:          symlinked
1521 # Required-Start:
1522 # Required-Stop:
1523 # Default-Start:     2 3 4 5
1524 # Default-Stop:      1
1525 ### END INIT INFO
1526 EOF
1527
1528 addscript outsider <<'EOF'
1529 ### BEGIN INIT INFO
1530 # Provides:          outsider
1531 # Required-Start:
1532 # Required-Stop:
1533 # Default-Start:     2 3 4 5
1534 # Default-Stop:      1
1535 ### END INIT INFO
1536 EOF
1537
1538 #addscript halt <<'EOF'
1539 ### BEGIN INIT INFO
1540 # Provides:          halt
1541 # Required-Start:
1542 # Required-Stop:
1543 # Default-Start:
1544 # Default-Stop:      0 6
1545 ### END INIT INFO
1546 #EOF
1547
1548 # Now make an illegal symlink to see if it causes problems, #485045
1549 ln -s symlinked ${initddir}/symlink
1550
1551 insserv_reg symlinked || true
1552 insserv_reg symlink || true
1553
1554 check_script_present 1 symlinked
1555 check_script_present 2 symlinked
1556 check_script_present 3 symlinked
1557 check_script_present 4 symlinked
1558 check_script_present 5 symlinked
1559 check_script_not_present 1 symlink
1560 check_script_not_present 2 symlink
1561 check_script_not_present 3 symlink
1562 check_script_not_present 4 symlink
1563 check_script_not_present 5 symlink
1564
1565 # Add a /etc/init.d/reboot -> halt symlink, to make sure the SUSE case
1566 # is not broken with stricter symlink sanity checking
1567 #ln -s halt ${initddir}/reboot
1568
1569 #insserv_reg reboot || true
1570
1571 #check_script_present 0 reboot
1572 #check_script_present 6 reboot
1573
1574 # Move outsider to a location other than /etc/init.d/ and create a symlink
1575 # to it. insserv should register it without problems.
1576 mv ${initddir}/outsider ${initddir}/../
1577 ln -s ../outsider ${initddir}/outsidelink
1578
1579 insserv_reg outsidelink || true
1580
1581 list_rclinks
1582
1583 check_script_present 1 outsidelink
1584 check_script_present 2 outsidelink
1585 check_script_present 3 outsidelink
1586 check_script_present 4 outsidelink
1587 check_script_present 5 outsidelink
1588
1589 rm -f ${initddir}/../outsider
1590 }
1591 ##########################################################################
1592 test_deterministic_order() {
1593 echo
1594 echo "info: test two or more initscripts providing same facility, making sure"
1595 echo "info: that the first script can be registered with insserv, but others fail." 
1596 echo
1597
1598 initdir_purge
1599
1600 addscript abc <<'EOF' || true
1601 ### BEGIN INIT INFO
1602 # Provides:          service
1603 # Required-Start:
1604 # Required-Stop:
1605 # Default-Start:     S
1606 # Default-Stop:
1607 ### END INIT INFO
1608 EOF
1609
1610 addscript xyz <<'EOF' || true
1611 ### BEGIN INIT INFO
1612 # Provides:          service
1613 # Required-Start:
1614 # Required-Stop:
1615 # Default-Start:     S
1616 # Default-Stop:
1617 ### END INIT INFO
1618 EOF
1619
1620 addscript hjk <<'EOF' || true
1621 ### BEGIN INIT INFO
1622 # Provides:          service
1623 # Required-Start:
1624 # Required-Stop:
1625 # Default-Start:     S
1626 # Default-Stop:
1627 ### END INIT INFO
1628 EOF
1629
1630 insserv_reg xyz || true
1631 insserv_reg hjk || true
1632 insserv_reg abc || true
1633
1634 list_rclinks
1635
1636 # #494514
1637 check_script_present S xyz
1638 check_script_not_present S abc
1639 check_script_not_present S hjk
1640 }
1641 ##########################################################################
1642 test_all_keyword() {
1643 echo
1644 echo "info: test behaviour of a script depending on another with the \$all keyword"
1645 echo "info: #491391"
1646 echo
1647
1648 initdir_purge
1649
1650 # Insert a few scripts to flesh out $initdir
1651 for script in one two three
1652 do
1653 insertscript $script <<EOF || true
1654 ### BEGIN INIT INFO
1655 # Provides:          $script
1656 # Required-Start:    \$remote_fs
1657 # Required-Stop:
1658 # Default-Start:     2 3 4 5
1659 # Default-Stop:
1660 ### END INIT INFO
1661 EOF
1662 done
1663
1664 insertscript four <<'EOF' || true
1665 ### BEGIN INIT INFO
1666 # Provides:          four
1667 # Required-Start:    $remote_fs
1668 # Required-Stop:
1669 # Should-Start:      one two three
1670 # Should-Stop:
1671 # Default-Start:     2 3 4 5
1672 # Default-Stop:
1673 ### END INIT INFO
1674 EOF
1675
1676 insertscript rmnologin <<'EOF' || true
1677 ### BEGIN INIT INFO
1678 # Provides:          rmnologin
1679 # Required-Start:    $remote_fs $all
1680 # Required-Stop:
1681 # Default-Start:     2 3 4 5
1682 # Default-Stop:
1683 ### END INIT INFO
1684 EOF
1685
1686 # This version of bootchart LSB info is not the best, but it does reveal
1687 # an interesting and unexpected behaviour.
1688 insertscript bootchart <<'EOF' || true
1689 ### BEGIN INIT INFO
1690 # Provides:          bootchart
1691 # Required-Start:    $remote_fs rmnologin
1692 # Required-Stop:
1693 # Default-Start:     2 3 4 5
1694 # Default-Stop:
1695 ### END INIT INFO
1696 EOF
1697
1698 list_rclinks
1699
1700 check_script_present 5 rmnologin
1701 check_script_present 5 bootchart
1702 test_order 5 rmnologin bootchart
1703
1704 echo
1705 echo "info: now add \$all keyword to bootchart script and reinsert"
1706 echo
1707
1708 remscript bootchart
1709 # This information looks correct, but due to the way all_links() works two or
1710 # more scripts with keyword $all in Required-Start start at same sequence, but
1711 # do start after all other scripts
1712 addscript bootchart <<'EOF' || true
1713 ### BEGIN INIT INFO
1714 # Provides:          bootchart
1715 # Required-Start:    $all rmnologin
1716 # Required-Stop:
1717 # Default-Start:     2 3 4 5
1718 # Default-Stop:
1719 ### END INIT INFO
1720 EOF
1721
1722 insserv_reg bootchart || true
1723
1724 list_rclinks
1725 check_script_present 5 bootchart
1726 test_order 5 rmnologin bootchart
1727
1728 echo
1729 echo "info: add yet another script depending on \$all"
1730 echo
1731 insertscript all <<'EOF' || true
1732 ### BEGIN INIT INFO
1733 # Provides:          all
1734 # Required-Start:    $all
1735 # Required-Stop:
1736 # Default-Start:     2 3 4 5
1737 # Default-Stop:
1738 ### END INIT INFO
1739 EOF
1740
1741 list_rclinks
1742 check_script_present 5 all
1743 }
1744 ##########################################################################
1745 test_early_all() {
1746 echo
1747 echo "info: Check that start dependency on \$all only affect the start"
1748 echo "sequence. BTS #485307"
1749
1750 echo
1751
1752 initdir_purge
1753
1754 # Insert a few scripts to flesh out $initdir
1755 insertscript early <<EOF || true
1756 ### BEGIN INIT INFO
1757 # Provides:          early
1758 # Required-Start:
1759 # Required-Stop:
1760 # Default-Start:     2
1761 # Default-Stop:      0
1762 ### END INIT INFO
1763 EOF
1764
1765 insertscript center <<'EOF' || true
1766 ### BEGIN INIT INFO
1767 # Provides:          center
1768 # Required-Start:    early
1769 # Required-Stop:     early
1770 # Default-Start:     2
1771 # Default-Stop:      0
1772 ### END INIT INFO
1773 EOF
1774
1775 insertscript late <<'EOF' || true
1776 ### BEGIN INIT INFO
1777 # Provides:          late
1778 # Required-Start:    center
1779 # Required-Stop:     center
1780 # Default-Start:     2
1781 # Default-Stop:      0
1782 ### END INIT INFO
1783 EOF
1784
1785 # This script should start early and stop before all other scripts
1786 insertscript zcomplex <<'EOF' || true
1787 ### BEGIN INIT INFO
1788 # Provides:          zcompex
1789 # Required-Start:    early
1790 # X-Start-Before:    center
1791 # Required-Stop:     $all
1792 # Default-Start:     2
1793 # Default-Stop:      0
1794 ### END INIT INFO
1795 EOF
1796
1797 list_rclinks
1798
1799 check_script_present 2 early
1800 check_script_present 2 zcomplex
1801 check_order 2 early zcomplex
1802 check_order 2 zcomplex center
1803 check_order 0 zcomplex late
1804 check_order 0 zcomplex early
1805 }
1806 ##########################################################################
1807 test_script_in_runlevel() {
1808 echo
1809 echo "info: add a regular file where only symlinks are expected (#493202)"
1810 echo
1811
1812 initdir_purge
1813
1814 # Create a regular file in runlevel directory where only symlinks are expected
1815 mkdir $initddir/../rcS.d
1816 touch $initddir/../rcS.d/S06badboy
1817
1818 insertscript goodboy <<'EOF'
1819 ### BEGIN INIT INFO
1820 # Provides:          goodboy
1821 # Required-Start:    $remote_fs
1822 # Required-Stop:
1823 # Default-Start:     S
1824 # Default-Stop:
1825 ### END INIT INFO
1826 EOF
1827
1828 list_rclinks
1829
1830 check_script_present S goodboy
1831
1832 rm $initddir/../rcS.d/S06badboy
1833 }
1834 ##########################################################################
1835 test_x_interactive() {
1836 echo
1837 echo "info: Check if X-Interactive header work"
1838 echo "BTS #458224"
1839 echo
1840   
1841 initdir_purge
1842
1843 # Insert a few scripts to flesh out $initdir
1844 insertscript first <<EOF || true
1845 ### BEGIN INIT INFO
1846 # Provides:          first
1847 # Required-Start:
1848 # Required-Stop:
1849 # Default-Start:     2
1850 # Default-Stop:      0
1851 ### END INIT INFO
1852 EOF
1853
1854 # This test if X-Interactive work with existing scripts when a new
1855 # script is inserted.
1856 insertscript alone1 <<'EOF' || true
1857 ### BEGIN INIT INFO
1858 # Provides:          alone1
1859 # Required-Start:    first
1860 # Required-Stop:     first
1861 # Default-Start:     2
1862 # Default-Stop:      0
1863 # X-Interactive:     true
1864 ### END INIT INFO
1865 EOF
1866
1867 insertscript after <<'EOF' || true
1868 ### BEGIN INIT INFO
1869 # Provides:          after
1870 # Required-Start:    first
1871 # Required-Stop:     first
1872 # Default-Start:     2
1873 # Default-Stop:      0
1874 ### END INIT INFO
1875 EOF
1876
1877 # This test if X-Interactive work with new scripts too.  The code
1878 # paths in insserv are different for the two cases.
1879 insertscript alone2 <<'EOF' || true
1880 ### BEGIN INIT INFO
1881 # Provides:          alone2
1882 # Required-Start:    first
1883 # Required-Stop:     first
1884 # Default-Start:     2
1885 # Default-Stop:      0
1886 # X-Interactive:     true
1887 ### END INIT INFO
1888 EOF
1889
1890 list_rclinks
1891
1892 check_script_present 2 first
1893 check_script_present 2 after
1894 check_script_present 2 alone1
1895 check_script_present 2 alone2
1896 check_order 2 first after
1897 check_order 2 first alone1
1898 check_order 2 first alone2
1899 ${severity}_order 2 alone1 after # This ordering is not guaranteed
1900 ${severity}_order 2 alone2 after # This ordering is not guaranteed
1901 }
1902 ##########################################################################
1903
1904 test_insserv_conf_makefile() {
1905 echo
1906 echo "info: test how recursive /etc/insserv.conf settings show up"
1907 echo "info: in .depend.boot.  BTS #534526."
1908 echo
1909
1910 initdir_purge
1911
1912 list_rclinks
1913
1914 # If $local_fs only depend on the mountall script, the test work.
1915 # Only the last script in $local_fs make it to the dependency file.
1916 set +C
1917 cat <<'EOF' > $insconf
1918 $local_fs       +mountall +nonexisting
1919 $remote_fs      $local_fs
1920 EOF
1921 set -C
1922
1923 insertscript mountall <<'EOF'
1924 ### BEGIN INIT INFO
1925 # Provides:          mountall
1926 # Required-Start:
1927 # Required-Stop:
1928 # Default-Start:     1
1929 # Default-Stop:
1930 ### END INIT INFO
1931 EOF
1932
1933 insertscript dbus <<'EOF'
1934 ### BEGIN INIT INFO
1935 # Provides:          dbus
1936 # Required-Start:
1937 # Required-Stop:
1938 # Default-Start:     1
1939 # Default-Stop:
1940 ### END INIT INFO
1941 EOF
1942
1943 insertscript hal <<'EOF'
1944 ### BEGIN INIT INFO
1945 # Provides:          hal
1946 # Required-Start:    $remote_fs dbus
1947 # Required-Stop:
1948 # Default-Start:     1
1949 # Default-Stop:
1950 ### END INIT INFO
1951 EOF
1952
1953 list_rclinks
1954
1955 if ! grep -q "^hal: mountall dbus" ${initddir}/.depend.start ; then
1956     msg="hal should depend on dbus and mountall in .depend.start:"
1957     if [ test = "$severity" ] ; then
1958         warning "$msg"
1959     else
1960         error "$msg"
1961     fi
1962     grep  "^hal: " ${initddir}/.depend.start | sed 's/^/  /'
1963 fi
1964
1965 update_conf
1966 }
1967
1968 #########################
1969
1970 test_insserv_virt_loop() {
1971 echo
1972 echo "info: test insserv handle virtual facilities depending on itself."
1973 echo
1974
1975 initdir_purge
1976
1977 list_rclinks
1978
1979 # If $local_fs depend on itself, the error is triggered.
1980 set +C
1981 cat <<'EOF' > $insconf
1982 $local_fs       +mountall $local_fs
1983 EOF
1984 set -C
1985
1986 # This used to hang and use unlimited amount of memory.  Now return
1987 # error instead.
1988 insertscript testscript <<'EOF' || true
1989 ### BEGIN INIT INFO
1990 # Provides:          testscript
1991 # Required-Start:    $local_fs
1992 # Required-Stop:
1993 # Default-Start:     1
1994 # Default-Stop:
1995 ### END INIT INFO
1996 EOF
1997
1998 list_rclinks
1999
2000 update_conf
2001 }
2002
2003 ##########################################################################
2004 test_local_virtual() {
2005 echo
2006 echo "info: Test if home made virtual facilities work as they should."
2007 echo
2008
2009 initdir_purge
2010
2011 mkdir $insconf.d
2012
2013 insertscript test1 <<'EOF' || true
2014 ### BEGIN INIT INFO
2015 # Provides:          test1
2016 # Required-Start:    $mail-transport-agent
2017 # Required-Stop:
2018 # Default-Start:     1
2019 # Default-Stop:
2020 ### END INIT INFO
2021 EOF
2022
2023 insertscript test2 <<'EOF' || true
2024 ### BEGIN INIT INFO
2025 # Provides:          test2
2026 # Required-Start:    $mail-transport-agent
2027 # Required-Stop:
2028 # Default-Start:     1
2029 # Default-Stop:
2030 ### END INIT INFO
2031 EOF
2032
2033 list_rclinks
2034
2035 set +C
2036 cat <<'EOF' > $insconf.d/test3
2037 $mail-transport-agent       test3
2038 EOF
2039 insertscript test3 <<'EOF' || true
2040 ### BEGIN INIT INFO
2041 # Provides:          test3
2042 # Required-Start:
2043 # Required-Stop:
2044 # Default-Start:     1
2045 # Default-Stop:
2046 ### END INIT INFO
2047 EOF
2048
2049 cat <<'EOF' > $insconf.d/test4
2050 $mail-transport-agent       +test4
2051 EOF
2052 set -C
2053 insertscript test4 <<'EOF' || true
2054 ### BEGIN INIT INFO
2055 # Provides:          test4
2056 # Required-Start:    test3
2057 # Required-Stop:
2058 # Default-Start:     1
2059 # Default-Stop:
2060 ### END INIT INFO
2061 EOF
2062
2063 list_rclinks
2064
2065 check_order 1 test3 test1
2066 check_order 1 test3 test2
2067 check_order 1 test4 test1
2068 check_order 1 test4 test2
2069
2070 }
2071 ##########################################################################
2072 test_insserv_upstart() {
2073 echo
2074 echo "info: test if insserv handle upstart jobs properly."
2075 echo
2076
2077 initdir_purge
2078
2079 list_rclinks
2080
2081 # This used to hang and use unlimited amount of memory.  Now return
2082 # error instead.
2083 upstartdir=${tmpdir}/etc/init
2084
2085 upstartjob="${tmpdir}/lib/init/upstart-job"
2086
2087 # Add upstart config
2088 oldconf="$insconf"
2089 insconf="$insconf -u $upstartjob"
2090
2091 # Dummy entry
2092 mkdir -p $(dirname $upstartjob)
2093 cat > $upstartjob <<EOF
2094 #!/bin/sh
2095 cat <<END
2096 ### BEGIN INIT INFO
2097 # Provides:          upstart-test
2098 # Required-Start:    
2099 # Required-Stop:
2100 # Default-Start:     1
2101 # Default-Stop:
2102 ### END INIT INFO
2103 END
2104 EOF
2105 chmod a+x $upstartjob
2106
2107 insert_upstart_job() {
2108     name=$1
2109     mkdir -p $upstartdir
2110     cat > $upstartdir/$name
2111     ln -s $upstartjob $initddir/$name
2112     insserv_reg $name
2113 }
2114
2115 # XXX Someone that understand upstart need to fill in sensible stuff
2116 # here
2117 insert_upstart_job upstart-test <<EOF || true
2118 exec /bin/foo --opt -xyz foo bar
2119 EOF
2120
2121 insertscript test <<'EOF' || true
2122 ### BEGIN INIT INFO
2123 # Provides:          test
2124 # Required-Start:    upstart-test
2125 # Required-Stop:
2126 # Default-Start:     1
2127 # Default-Stop:
2128 ### END INIT INFO
2129 EOF
2130
2131
2132 list_rclinks
2133
2134 # Undo upstart config
2135 insconf="$oldconf"
2136 }
2137
2138 ##########################################################################
2139
2140 test_normal_sequence
2141 test_override_files
2142 test_override_loop
2143 test_override_remove
2144 test_long_loop
2145 test_combined_loop              # 1 non-fatal test failing
2146 test_fake_loop
2147 test_fake_loop_reverse
2148 test_badscript
2149 test_onlystart
2150 test_onlystop
2151 test_removal
2152 test_segfault_virtfac
2153 test_incorrect_startscripts
2154 test_incorrect_stopscripts
2155 test_newbug_keepoldorder        # 3 non-fatal tests failing
2156 test_start_before
2157 test_stop_after
2158 test_adding_start
2159 test_removing_start
2160 test_adding_stop
2161 test_removing_stop
2162 test_duplicate_provides
2163 test_bogus_facility             # 1 non-fatal test failing
2164 test_insserv_conf_d
2165 test_broken_header
2166 test_noprovides_header
2167 test_no_default_start
2168 test_no_default_stop
2169 test_initd_symlink
2170 test_deterministic_order
2171 test_all_keyword
2172 test_early_all
2173 test_script_in_runlevel
2174 test_x_interactive
2175 test_insserv_conf_makefile
2176 test_insserv_virt_loop
2177 test_local_virtual
2178 test_insserv_upstart