source: trunk/minix/etc/rc@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.8 KB
Line 
1# /etc/rc - System startup script run by init before going multiuser.
2
3umask 022
4TERM="${TERM-minix}"
5PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin
6RC_TZ=/etc/rc.timezone
7export TERM PATH
8
9usage()
10{
11 echo >&2 "Usage: $0 [-saf] start|stop|down"
12 exec intr sh
13}
14
15up()
16{
17 service=$1
18 shift
19
20 # Function to dynamically start a system service
21 echo -n " $service"
22 service up /sbin/$service "$@"
23}
24
25while getopts 'saf' opt
26do
27 case $opt in
28 s) sflag=t ;; # Single user
29 a) aflag=t ;; # Ask for /usr
30 f) fflag=t ;; # Force a full file system check
31 *) usage
32 esac
33done
34shift `expr $OPTIND - 1`
35
36case "$#:$1" in
371:start|1:stop|1:down)
38 action=$1
39 ;;
40*) usage
41esac
42
43case $action in
44start)
45 echo ""
46 echo -n "Multiuser startup in progress ...:"
47
48 # National keyboard?
49 test -f /etc/keymap && loadkeys /etc/keymap
50
51 up is -period 5HZ
52 up cmos -dev /dev/cmos -period 5HZ
53 echo .
54
55 # Set timezone.
56 export TZ=GMT0
57 if [ -f "$RC_TZ" ]
58 then . "$RC_TZ"
59 fi
60
61 # Try to read the hardware real-time clock, otherwise do it manually.
62 readclock || intr date -q
63
64 # Initialize files.
65 printroot >/etc/mtab # /etc/mtab keeps track of mounts
66 >/etc/utmp # /etc/utmp keeps track of logins
67
68 # /etc/fstab lists the root, tmp and usr devices.
69 . /etc/fstab
70
71 # Any swapspace on a device?
72 test "$swap" : '/dev/' && mount -s $swap
73
74 # Are we booting from CD?
75 bootcd="`/bin/sysenv bootcd`"
76
77 # If booting from CD, /usr has to be mounted readonly.
78 # Also, $usr won't be specified correctly in the
79 # fstab (the CD could be anywhere), so we decide
80 # where it is based on sysenv (set by FS when probing for CD).
81 if [ "$bootcd" = 1 ]
82 then
83 #imagedev="`/bin/sysenv cdproberoot`"
84 #usrdev="`expr $imagedev + 1`"
85 usr_roflag="-r"
86 usr="$cddev"p2
87 echo "Setting /usr on cd is $usr"
88 fi
89
90 # Mount the /usr partition unless this is a single floppy Minix.
91 if [ ! -d /usr/bin ]
92 then
93 if [ "$aflag" -o "$usr" = unknown ]
94 then
95 # We need to ask what the /usr du jour is.
96 intr sh -c '
97 echo -n "Finish the name of device to mount as /usr: /dev/"
98 read usr
99 echo "usr=/dev/$usr" >/tmp/usr'
100 . /tmp/usr
101 fi
102 mount $usr_roflag $usr /usr || {
103 echo "\
104Please try to mount something else as /usr, then hit CTRL-D to continue startup.
105Mount $usr /usr failed -- Single user."
106 intr sh
107 }
108 rm -f /tmp/usr
109 fi
110
111 # Check if the system crashed.
112 if shutdown -C
113 then
114 echo
115 echo "The system was not properly shut down. Checking file systems."
116 fflag=t
117 fi
118
119 if [ "$fflag" ]
120 then
121 umount $usr
122 echo "fsck / - $root"
123 intr fsck -r $root
124 echo "fsck /usr - $usr"
125 intr fsck -r $usr
126 if [ ! -z "$home" ]
127 then echo "fsck /home - $home"
128 intr fsck -r $home
129 fi
130 mount $usr /usr
131 fi
132
133 if [ ! -z "$home" ]
134 then mount $home /home || echo "WARNING: couldn't mount $home on /home"
135 fi
136
137 # This file is necessary for above 'shutdown -C' check.
138 # (Silence stderr in case of running from cd.)
139 touch /usr/adm/wtmp 2>/dev/null
140
141 if [ "$sflag" ]
142 then
143 echo "Single user."
144 intr sh
145 fi
146
147 # Any swapspace on a file?
148 test -n "$swap" -a ! "$swap" : '/dev/' && mount -s $swap
149
150
151 case "`printroot -r`":$bootcd in
152 /dev/ram:)
153 # Remove boot-only things to make space,
154 # unless booting from CD, in which case we need them.
155 rm -rf /boot
156 # put the compiler on ram
157 cp /usr/lib/em* /usr/lib/cpp* /lib
158 esac
159
160 # Things should be alright now.
161 ;;
162down|stop)
163 sync
164 # Tell RS server we're going down.
165 service shutdown
166 ;;
167esac
168
169# Further initialization.
170test -f /usr/etc/rc && sh /usr/etc/rc $action
171test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
172test -f /etc/rc.rescue && sh /etc/rc.rescue $action
173
174# Any messages?
175test "$action" = start -a -f /etc/issue && cat /etc/issue
176
177exit 0
Note: See TracBrowser for help on using the repository browser.