Bring RCNG in from 5.x and adjust config files and scripts accordingly.
[dragonfly.git] / etc / rc.d / fsck
1 #!/bin/sh
2 #
3 # $NetBSD: fsck,v 1.2 2001/06/18 06:42:35 lukem Exp $
4 # $FreeBSD: src/etc/rc.d/fsck,v 1.4 2002/10/12 10:31:31 schweikh Exp $
5 # $DragonFly: src/etc/rc.d/fsck,v 1.1 2003/07/24 06:35:37 dillon Exp $
6 #
7
8 # PROVIDE: fsck
9 # REQUIRE: localswap
10 # KEYWORD: DragonFly FreeBSD NetBSD
11
12 . /etc/rc.subr
13
14 name="fsck"
15 start_cmd="fsck_start"
16 stop_cmd=":"
17
18 stop_boot()
19 {
20         #       Terminate the process (which may include the parent /etc/rc)
21         #       if booting directly to multiuser mode.
22         #
23         if [ "$autoboot" = yes ]; then
24                 kill -TERM $$
25         fi
26         exit 1
27 }
28
29 fsck_start()
30 {
31         if [ "$autoboot" = no ]; then
32                 echo "Fast boot: skipping disk checks."
33         elif [ "$autoboot" = yes ]; then
34                                         # During fsck ignore SIGQUIT
35                 trap : 3
36
37                 echo "Starting file system checks:"
38                 case ${OSTYPE} in
39                 DragonFly)
40                         fsck -p
41                         ;;
42                 FreeBSD)
43                         fsck -p
44                         ;;
45                 NetBSD)
46                         fsck -p
47                         ;;
48                 esac
49
50                 case $? in
51                 0)
52                         ;;
53                 2)
54                         stop_boot
55                         ;;
56                 4)
57                         echo "Rebooting..."
58                         reboot
59                         echo "Reboot failed; help!"
60                         stop_boot
61                         ;;
62                 8)
63                 case ${OSTYPE} in
64                 DragonFly)
65                                  if checkyesno fsck_y_enable; then
66                                 echo "File system preen failed, trying fsck -y."
67                                 fsck -y
68                                 case $? in
69                                 0)
70                                         ;;
71                                 *)
72                                 echo "Automatic file system check failed; help!"
73                                         stop_boot
74                                         ;;
75                                 esac
76                         else
77                                 echo "Automatic file system check failed; help!"
78                                 stop_boot
79                         fi
80                         ;;
81
82                 FreeBSD)
83                         if checkyesno fsck_y_enable; then
84                                 echo "File system preen failed, trying fsck -y."
85                                 fsck -y
86                                 case $? in
87                                 0)
88                                         ;;
89                                 *)
90                                 echo "Automatic file system check failed; help!"
91                                         stop_boot
92                                         ;;
93                                 esac
94                         else
95                                 echo "Automatic file system check failed; help!"
96                                 stop_boot
97                         fi
98                         ;;
99                 NetBSD)
100                         echo "Automatic file system check failed; help!"
101                         stop_boot
102                         ;;
103                 esac
104                 ;;
105                 12)
106                         echo "Boot interrupted."
107                         stop_boot
108                         ;;
109                 130)
110                         stop_boot
111                         ;;
112                 *)
113                         echo "Unknown error; help!"
114                         stop_boot
115                         ;;
116                 esac
117         fi
118 }
119
120 load_rc_config $name
121 run_rc_command "$1"