]> git.saurik.com Git - apple/launchd.git/blame - launchd/src/rc
launchd-106.20.tar.gz
[apple/launchd.git] / launchd / src / rc
CommitLineData
e91b9f68
A
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
fc89531e
A
51if [ -f /etc/rc.server ]; then
52 sh /etc/rc.server
e91b9f68 53fi
fc89531e 54
e91b9f68
A
55if [ -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
60fi
61
62sysctl -w kern.sysv.shmmax=4194304 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=1024
63
64if [ -f /var/account/acct ]; then
65 accton /var/account/acct
66fi
67
e91b9f68
A
68echo "Resetting files and devices"
69
70RMRF_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##
76if [ -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
86elif [ -r /etc/ptmp ]; then
87 echo "Removing passwd lock file"
88 RMRF_ITEMS="$RMRF_ITEMS /etc/ptmp"
89fi
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##
96RMRF_ITEMS="$RMRF_ITEMS /etc/nologin"
97
98# Clean out /private/tmp.
99if [ -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_"
108fi
109mkdir -p -m 01777 /private/var/tmp /private/tmp
110
111# Move /var/run out of the way
112if [ -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_
119fi
120
121# Make new /var/run
122mkdir -m 775 /var/run
123mkdir -m 775 /var/run/StartupItems /var/run/davlocks
124mkdir -m 755 /var/run/proxy
125chown root:daemon /var/run /var/run/StartupItems
126chown 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
129if [ -d /var/_run_/sudo ]; then
130 mv /var/_run_/sudo /var/run/sudo
131 touch -t 198501010000 /var/run/sudo/*
132fi
133
134# Clear utmp (who is logged on).
135touch /var/run/utmp /var/run/utmpx
136
137# purge the _run_ directory if it exists
138if [ -d /var/_run_ ]; then
139 chflags -R -P 0 /var/_run_
140 RMRF_ITEMS="$RMRF_ITEMS /var/_run_"
141fi
142
143# Clear /var/spool/lock
144if [ -d /var/spool/lock ]; then
145 find /var/spool/lock -not -type d -print0 | xargs -0 rm -f
146fi
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
156needlink=0
157if [ -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
164fi
165
166if [ "${needlink}" -lt 3 ]; then
167 if [ -h "/Desktop (Mac OS 9)" ]; then
168 rm -f "/Desktop (Mac OS 9)"
169 fi
170else
171 if ! [ -e "/Desktop (Mac OS 9)" ]; then
172 ln -s "/Desktop Folder" "/Desktop (Mac OS 9)"
173 fi
174fi
175
176echo "Starting virtual memory"
177
178swapdir=/private/var/vm
179if [ "${NetBoot}" = "-N" ]; then
180 sh /etc/rc.netboot setup_vm ${swapdir}
181fi
182
183if [ ! -d ${swapdir} ]; then
184 echo "Creating default swap directory"
185 mkdir -p -m 755 ${swapdir}
186 chown root:wheel ${swapdir}
187else
188 RMRF_ITEMS="${RMRF_ITEMS} ${swapdir}/swap*"
189fi
190
191echo Removing $RMRF_ITEMS
192rm -rf $RMRF_ITEMS
193
194if [ ${ENCRYPTSWAP:=-NO-} = "-YES-" ]; then
195 encryptswap="-E"
196else
197 encryptswap=""
198fi
199/sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile
200
201appprofiledir=/private/var/vm/app_profile
202
203if [ ! -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}
209fi
210
211# Create mach symbol file
212sysctl -n kern.symfile
213if [ -f /mach.sym ]; then
214 ln -sf /mach.sym /mach
215else
216 ln -sf /mach_kernel /mach
217fi
218
219if [ "${SafeBoot}" = "-x" ]; then
220 echo "Configuring kernel extensions for safe boot"
221 touch /private/tmp/.SafeBoot
222 kextd -x
223else
224 echo "Configuring kernel extensions"
225 kextd
226fi
227
2a27bb34
A
228if [ -f /etc/rc.installer_cleanup ]; then
229 /etc/rc.installer_cleanup multiuser
230fi
231
e91b9f68
A
232if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
233 ${BootCacheControl} tag
234fi
235
236# Create local NetInfo database if it doesn't exist
237if [ ! -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
242fi
243
244if [ -f /etc/security/rc.audit ]; then
245 . /etc/security/rc.audit
246fi
247
248if [ -f /Library/Preferences/com.apple.sharing.firewall.plist ]; then
249 /usr/libexec/FirewallTool
250fi
251
252# Load [ideally on demand] daemons
e91b9f68 253if [ "${SafeBoot}" = "-x" ]; then
aa59983a 254 launchctl load /System/Library/LaunchDaemons /etc/mach_init.d
e91b9f68 255else
aa59983a 256 launchctl load /Library/LaunchDaemons /System/Library/LaunchDaemons /etc/mach_init.d
e91b9f68
A
257 SystemStarter ${VerboseFlag}
258fi
259
260/usr/sbin/update
261
262if [ "${NetBoot}" = "-N" ]; then
263 sh /etc/rc.netboot setup_computername
264fi
265
266# Set language from CDIS.custom - assumes this is parse-able by sh
267if [ -f /var/log/CDIS.custom ]; then
268 . /var/log/CDIS.custom
269fi
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.
273STARTPBS="/System/Library/CoreServices/pbs" # apps stall w/o
274BUDDYCOOKIE="/var/db/.AppleSetupDone"
275LCACOOKIE="/var/db/.RunLanguageChooserToo"
276STARTLCA="/System/Library/CoreServices/Language Chooser.app/Contents/MacOS/Language Chooser"
277
278if [ -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
283fi
284
285if [ ! -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"
288fi
289
290export LANGUAGE
291
292if [ -f /etc/rc.local ]; then
293 sh /etc/rc.local
294fi
295
296touch /var/run/.systemStarterRunning
297
298if [ "${VerboseFlag}" != "-v" ] ; then
299 /usr/libexec/WaitingForLoginWindow
300fi
301
302exit 0