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