]> git.saurik.com Git - apple/launchd.git/blob - launchd/src/rc
launchd-106.20.tar.gz
[apple/launchd.git] / launchd / src / rc
1 #!/bin/sh
2 # Copyright 1997-2004 Apple Computer, Inc.
3
4 . /etc/rc.common
5
6 export -n SafeBoot
7 export -n VerboseFlag
8 export -n FsckSlash
9 export -n NetBoot
10
11 if [ -d /System/Installation -a -f /etc/rc.cdrom ]; then
12 /etc/rc.cdrom multiuser
13 # We shouldn't get here; CDIS should reboot the machine when done
14 echo "CD-ROM boot procedure complete"
15 halt
16 fi
17
18 if [ "${NetBoot}" = "-N" ] ; then
19 echo "Initializing NetBoot"
20 if ! sh /etc/rc.netboot start ; then
21 echo NetBoot initialization failed, shut down in 10 seconds...
22 sleep 10
23 halt
24 fi
25 fi
26
27 if [ "${FsckSlash}" = "-F" ]; then
28 # Benignly clean up ("preen") any dirty filesystems.
29 # fsck -p will skip disks which were properly unmounted during
30 # a normal shutdown.
31 echo "Checking disk"
32 if [ "${SafeBoot}" = "-x" ]; then
33 fsck -fy || halt
34 else
35 fsck -p || fsck -fy || halt
36 fi
37 fi
38
39 echo "Mounting local filesystems"
40 mount -uw /
41 [ -f /etc/fstab ] && mount -vat nonfs
42
43 BootCacheControl=/System/Library/Extensions/BootCache.kext/Contents/Resources/BootCacheControl
44 if [ ! -f $BootCacheControl ]; then
45 BootCacheControl=/usr/sbin/BootCacheControl
46 fi
47 if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
48 ${BootCacheControl} start
49 fi
50
51 if [ -f /etc/rc.server ]; then
52 sh /etc/rc.server
53 fi
54
55 if [ -f /etc/sysctl.conf ]; then
56 awk '{ if (!index($1, "#") && index($1, "=")) print $1 }' < /etc/sysctl.conf | while read
57 do
58 sysctl -w ${REPLY}
59 done
60 fi
61
62 sysctl -w kern.sysv.shmmax=4194304 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=1024
63
64 if [ -f /var/account/acct ]; then
65 accton /var/account/acct
66 fi
67
68 echo "Resetting files and devices"
69
70 RMRF_ITEMS="/mach.sym /var/tmp/folders.*"
71 ##
72 # Attempt to recover the passwd file, if needed. This procedure is
73 # primarily historical and makes sense only when the passwd file is edited
74 # using the vipw command.
75 ##
76 if [ -s /etc/ptmp ]; then
77 if [ -s /etc/passwd ]; then
78 echo -n "Passwd file conflict with ptmp: "
79 ls -l /etc/passwd /etc/ptmp
80 echo "Moving ptmp to ptmp.save"
81 mv -f /etc/ptmp /etc/ptmp.save
82 else
83 echo "Passwd file recovered from ptmp"
84 mv /etc/ptmp /etc/passwd
85 fi
86 elif [ -r /etc/ptmp ]; then
87 echo "Removing passwd lock file"
88 RMRF_ITEMS="$RMRF_ITEMS /etc/ptmp"
89 fi
90
91 ##
92 # If the shutdown command was used to shut the system down, the file
93 # /etc/nologin may have been created to prevent users from logging in.
94 # Remove it so that logins are enabled when the system comes up.
95 ##
96 RMRF_ITEMS="$RMRF_ITEMS /etc/nologin"
97
98 # Clean out /private/tmp.
99 if [ -d /private/tmp ]; then
100 # blow away any _tmp_ in case it exists as well
101 if [ -e /private/_tmp_ ]; then
102 chflags -R -P 0 /private/_tmp_
103 rm -rf /private/_tmp_
104 fi
105 mv /private/tmp /private/_tmp_
106 chflags -R -P 0 /private/_tmp_
107 RMRF_ITEMS="$RMRF_ITEMS /private/_tmp_"
108 fi
109 mkdir -p -m 01777 /private/var/tmp /private/tmp
110
111 # Move /var/run out of the way
112 if [ -d /var/run ]; then
113 # blow away any _run_ in case it exists as well
114 if [ -e /var/_run_ ]; then
115 chflags -R -P 0 /var/_run_
116 rm -rf /var/_run_
117 fi
118 mv /var/run /var/_run_
119 fi
120
121 # Make new /var/run
122 mkdir -m 775 /var/run
123 mkdir -m 775 /var/run/StartupItems /var/run/davlocks
124 mkdir -m 755 /var/run/proxy
125 chown root:daemon /var/run /var/run/StartupItems
126 chown www:www /var/run/proxy /var/run/davlocks
127
128 # Move sudo back to /var/run, touch the contents of /var/run/sudo/* back to the epoch
129 if [ -d /var/_run_/sudo ]; then
130 mv /var/_run_/sudo /var/run/sudo
131 touch -t 198501010000 /var/run/sudo/*
132 fi
133
134 # Clear utmp (who is logged on).
135 touch /var/run/utmp /var/run/utmpx
136
137 # purge the _run_ directory if it exists
138 if [ -d /var/_run_ ]; then
139 chflags -R -P 0 /var/_run_
140 RMRF_ITEMS="$RMRF_ITEMS /var/_run_"
141 fi
142
143 # Clear /var/spool/lock
144 if [ -d /var/spool/lock ]; then
145 find /var/spool/lock -not -type d -print0 | xargs -0 rm -f
146 fi
147
148
149 # if "/Desktop Folder" exists and has contents, make sure there is a
150 # "/Desktop (Mac OS 9)" symlink to it
151 # if "/Desktop Folder" does not exist, exists but has no contents, or exists
152 # and has only a single file, ".DS_Store" then there should be no
153 # "/Desktop (Mac OS 9)" symlink
154 # if there is some other file or directory with the name "/Desktop (Mac OS 9)"
155 # then just exit
156 needlink=0
157 if [ -d "/Desktop Folder" ]; then
158 needlink=$(ls -a1 "/Desktop Folder" | wc -l)
159 if [ "${needlink}" -eq 3 ]; then
160 if [ -f "/Desktop Folder/.DS_Store" ]; then
161 needlink=0
162 fi
163 fi
164 fi
165
166 if [ "${needlink}" -lt 3 ]; then
167 if [ -h "/Desktop (Mac OS 9)" ]; then
168 rm -f "/Desktop (Mac OS 9)"
169 fi
170 else
171 if ! [ -e "/Desktop (Mac OS 9)" ]; then
172 ln -s "/Desktop Folder" "/Desktop (Mac OS 9)"
173 fi
174 fi
175
176 echo "Starting virtual memory"
177
178 swapdir=/private/var/vm
179 if [ "${NetBoot}" = "-N" ]; then
180 sh /etc/rc.netboot setup_vm ${swapdir}
181 fi
182
183 if [ ! -d ${swapdir} ]; then
184 echo "Creating default swap directory"
185 mkdir -p -m 755 ${swapdir}
186 chown root:wheel ${swapdir}
187 else
188 RMRF_ITEMS="${RMRF_ITEMS} ${swapdir}/swap*"
189 fi
190
191 echo Removing $RMRF_ITEMS
192 rm -rf $RMRF_ITEMS
193
194 if [ ${ENCRYPTSWAP:=-NO-} = "-YES-" ]; then
195 encryptswap="-E"
196 else
197 encryptswap=""
198 fi
199 /sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile
200
201 appprofiledir=/private/var/vm/app_profile
202
203 if [ ! -d ${appprofiledir} ]; then
204 if [ -f ${appprofiledir} ]; then
205 mv -f ${appprofiledir} "${appprofiledir}_"
206 fi
207 mkdir -p -m 711 ${appprofiledir}
208 chown root:wheel ${appprofiledir}
209 fi
210
211 # Create mach symbol file
212 sysctl -n kern.symfile
213 if [ -f /mach.sym ]; then
214 ln -sf /mach.sym /mach
215 else
216 ln -sf /mach_kernel /mach
217 fi
218
219 if [ "${SafeBoot}" = "-x" ]; then
220 echo "Configuring kernel extensions for safe boot"
221 touch /private/tmp/.SafeBoot
222 kextd -x
223 else
224 echo "Configuring kernel extensions"
225 kextd
226 fi
227
228 if [ -f /etc/rc.installer_cleanup ]; then
229 /etc/rc.installer_cleanup multiuser
230 fi
231
232 if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
233 ${BootCacheControl} tag
234 fi
235
236 # Create local NetInfo database if it doesn't exist
237 if [ ! -d /var/db/netinfo/local.nidb ]; then
238 echo "Creating local NetInfo database"
239 mkdir -p /var/db/netinfo
240 /usr/libexec/create_nidb
241 rm -f /var/db/.AppleSetupDone
242 fi
243
244 if [ -f /etc/security/rc.audit ]; then
245 . /etc/security/rc.audit
246 fi
247
248 if [ -f /Library/Preferences/com.apple.sharing.firewall.plist ]; then
249 /usr/libexec/FirewallTool
250 fi
251
252 # Load [ideally on demand] daemons
253 if [ "${SafeBoot}" = "-x" ]; then
254 launchctl load /System/Library/LaunchDaemons /etc/mach_init.d
255 else
256 launchctl load /Library/LaunchDaemons /System/Library/LaunchDaemons /etc/mach_init.d
257 SystemStarter ${VerboseFlag}
258 fi
259
260 /usr/sbin/update
261
262 if [ "${NetBoot}" = "-N" ]; then
263 sh /etc/rc.netboot setup_computername
264 fi
265
266 # Set language from CDIS.custom - assumes this is parse-able by sh
267 if [ -f /var/log/CDIS.custom ]; then
268 . /var/log/CDIS.custom
269 fi
270
271 # Start the Language Chooser. This code should be able to go away as far as I
272 # know once loginwindow becomes more dynamic.
273 STARTPBS="/System/Library/CoreServices/pbs" # apps stall w/o
274 BUDDYCOOKIE="/var/db/.AppleSetupDone"
275 LCACOOKIE="/var/db/.RunLanguageChooserToo"
276 STARTLCA="/System/Library/CoreServices/Language Chooser.app/Contents/MacOS/Language Chooser"
277
278 if [ -x "$STARTLCA" -a -x "$STARTPBS" -a ! -f "$BUDDYCOOKIE" -a -f "$LCACOOKIE" ]; then
279 "$STARTPBS" &
280 pbspid=$!
281 "$STARTLCA"
282 kill $pbspid # XSelect does this independently
283 fi
284
285 if [ ! -s "/var/log/CDIS.custom" ]; then
286 echo "Language Chooser seems to have failed; defaulting to English"
287 echo "LANGUAGE=English" > "/var/log/CDIS.custom"
288 fi
289
290 export LANGUAGE
291
292 if [ -f /etc/rc.local ]; then
293 sh /etc/rc.local
294 fi
295
296 touch /var/run/.systemStarterRunning
297
298 if [ "${VerboseFlag}" != "-v" ] ; then
299 /usr/libexec/WaitingForLoginWindow
300 fi
301
302 exit 0