Advertisement
shiftdot515

gorf.etc_rc

Dec 7th, 2016
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.70 KB | None | 0 0
  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/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
  56. fi
  57. if [ -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
  62. fi
  63.  
  64. sysctl -w kern.sysv.shmmax=4194304 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=1024
  65.  
  66. if [ -f /var/account/acct ]; then
  67.     accton /var/account/acct
  68. fi
  69.  
  70. echo "Resetting files and devices"
  71.  
  72. RMRF_ITEMS="/mach.sym /var/tmp/folders.*"
  73. ##
  74. # Attempt to recover the passwd file, if needed.  This procedure is
  75. # primarily historical and makes sense only when the passwd file is edited
  76. # using the vipw command.  
  77. ##
  78. if [ -s /etc/ptmp ]; then
  79.     if [ -s /etc/passwd ]; then
  80.         echo -n "Passwd file conflict with ptmp: "
  81.         ls -l /etc/passwd /etc/ptmp
  82.         echo "Moving ptmp to ptmp.save"
  83.         mv -f /etc/ptmp /etc/ptmp.save
  84.     else
  85.         echo "Passwd file recovered from ptmp"
  86.         mv /etc/ptmp /etc/passwd
  87.     fi
  88. elif [ -r /etc/ptmp ]; then
  89.     echo "Removing passwd lock file"
  90.     RMRF_ITEMS="$RMRF_ITEMS /etc/ptmp"
  91. fi
  92.  
  93. ##
  94. # If the shutdown command was used to shut the system down, the file
  95. # /etc/nologin may have been created to prevent users from logging in.  
  96. # Remove it so that logins are enabled when the system comes up.
  97. ##
  98. RMRF_ITEMS="$RMRF_ITEMS /etc/nologin"
  99.  
  100. # Clean out /private/tmp.
  101. if [ -d /private/tmp ]; then
  102.     # blow away any _tmp_ in case it exists as well
  103.     if [ -e /private/_tmp_ ]; then
  104.         chflags -R -P 0 /private/_tmp_
  105.         rm -rf /private/_tmp_
  106.     fi
  107.     mv /private/tmp /private/_tmp_
  108.     chflags -R -P 0 /private/_tmp_
  109.     RMRF_ITEMS="$RMRF_ITEMS /private/_tmp_"
  110. fi
  111. mkdir -p -m 01777 /private/var/tmp /private/tmp
  112.  
  113. # Move /var/run out of the way
  114. if [ -d /var/run ]; then
  115.     # blow away any _run_ in case it exists as well
  116.     if [ -e /var/_run_ ]; then
  117.         chflags -R -P 0 /var/_run_
  118.         rm -rf /var/_run_
  119.     fi
  120.     mv /var/run /var/_run_
  121. fi
  122.  
  123. # Make new /var/run
  124. mkdir -m 775 /var/run
  125. mkdir -m 775 /var/run/StartupItems /var/run/davlocks
  126. mkdir -m 755 /var/run/proxy
  127. chown root:daemon /var/run /var/run/StartupItems
  128. chown www:www /var/run/proxy /var/run/davlocks
  129.  
  130. # Move sudo back to /var/run, touch the contents of /var/run/sudo/* back to the epoch
  131. if [ -d /var/_run_/sudo ]; then
  132.     mv /var/_run_/sudo /var/run/sudo
  133.     touch -t 198501010000 /var/run/sudo/*
  134. fi
  135.  
  136. # Clear utmp (who is logged on).
  137. touch /var/run/utmp /var/run/utmpx
  138.  
  139. # purge the _run_ directory if it exists
  140. if [ -d /var/_run_ ]; then
  141.     chflags -R -P 0 /var/_run_
  142.     RMRF_ITEMS="$RMRF_ITEMS /var/_run_"
  143. fi
  144.  
  145. # Clear /var/spool/lock
  146. if [ -d /var/spool/lock ]; then
  147.     find /var/spool/lock -not -type d -print0 | xargs -0 rm -f
  148. fi
  149.  
  150.  
  151. # if "/Desktop Folder" exists and has contents, make sure there is a
  152. #   "/Desktop (Mac OS 9)" symlink to it
  153. # if "/Desktop Folder" does not exist, exists but has no contents, or exists
  154. #   and has only a single file, ".DS_Store" then there should be no
  155. #   "/Desktop (Mac OS 9)" symlink
  156. # if there is some other file or directory with the name "/Desktop (Mac OS 9)"
  157. #   then just exit
  158. needlink=0
  159. if [ -d "/Desktop Folder" ]; then
  160.     needlink=$(ls -a1 "/Desktop Folder" | wc -l)
  161.     if [ "${needlink}" -eq 3 ]; then
  162.         if [ -f "/Desktop Folder/.DS_Store" ]; then
  163.             needlink=0
  164.         fi
  165.     fi
  166. fi
  167.  
  168. if [ "${needlink}" -lt 3 ]; then
  169.     if [ -h "/Desktop (Mac OS 9)" ]; then
  170.         rm -f "/Desktop (Mac OS 9)"
  171.     fi
  172. else
  173.     if ! [ -e "/Desktop (Mac OS 9)" ]; then
  174.         ln -s "/Desktop Folder" "/Desktop (Mac OS 9)"
  175.     fi
  176. fi
  177.  
  178. echo "Starting virtual memory"
  179.  
  180. swapdir=/private/var/vm
  181. if [ "${NetBoot}" = "-N" ]; then
  182.     sh /etc/rc.netboot setup_vm ${swapdir}
  183. fi
  184.  
  185. if [ ! -d ${swapdir} ]; then
  186.     echo "Creating default swap directory"
  187.     mkdir -p -m 755 ${swapdir}
  188.     chown root:wheel ${swapdir}
  189. else
  190.     RMRF_ITEMS="${RMRF_ITEMS} ${swapdir}/swap*"
  191. fi
  192.            
  193. echo Removing $RMRF_ITEMS
  194. rm -rf $RMRF_ITEMS
  195.  
  196. if [ ${ENCRYPTSWAP:=-NO-} = "-YES-" ]; then
  197.     encryptswap="-E"
  198. else
  199.     encryptswap=""
  200. fi
  201. #/sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile
  202. #/sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile
  203. #/usr/bin/nice -n -10 /sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile -S 100663296
  204. #/sbin/dynamic_pager -S 402653184 -H 8388608 -L 469762048
  205. #/sbin/dynamic_pager -S 100663296 -H 4198400 -L 115347456
  206. #-S  The fixed filesize in bytes to use for the paging files.
  207. #-H  If there are less than high-water-trigger bytes free in paging files,
  208. #    the kernel will signal dynamic_pager to add a new external paging file.
  209. #-L  If there are more than low-water-trigger bytes free the kernel
  210. #    will coalese in-use pages and signal dynamic_pager to discard paging file.
  211. #    -L must be greater than -H + -S
  212. # S=128m H=2m L=S+H+(2*H)
  213. #/sbin/dynamic_pager -S 134217728 -H 2097152 -L 140509184
  214. # S=512m H=4m L=S+H+(2*H)
  215. /sbin/dynamic_pager -S 536870912 -H 4194304 -L 549453824
  216.  
  217.  
  218. appprofiledir=/private/var/vm/app_profile
  219.  
  220. if [ ! -d ${appprofiledir} ]; then
  221.     if [ -f  ${appprofiledir} ]; then
  222.         mv -f ${appprofiledir} "${appprofiledir}_"
  223.     fi
  224.     mkdir -p -m 711 ${appprofiledir}
  225.     chown root:wheel ${appprofiledir}
  226. fi
  227.  
  228. # Create mach symbol file
  229. sysctl -n kern.symfile
  230. if [ -f /mach.sym ]; then
  231.     ln -sf /mach.sym /mach
  232. else
  233.     ln -sf /mach_kernel /mach
  234. fi
  235.  
  236. if [ "${SafeBoot}" = "-x" ]; then
  237.     echo "Configuring kernel extensions for safe boot"
  238.     touch /private/tmp/.SafeBoot
  239.     kextd -x
  240. else
  241.     echo "Configuring kernel extensions"
  242.     kextd
  243. fi
  244.  
  245. if [ -f /etc/rc.installer_cleanup ]; then
  246.     /etc/rc.installer_cleanup multiuser
  247. fi
  248.  
  249. if [  "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
  250.     ${BootCacheControl} tag
  251. fi
  252.  
  253. # Create local NetInfo database if it doesn't exist
  254. if [ ! -d /var/db/netinfo/local.nidb ]; then
  255.     echo "Creating local NetInfo database"
  256.     mkdir -p /var/db/netinfo
  257.     /usr/libexec/create_nidb
  258.     rm -f /var/db/.AppleSetupDone
  259. fi
  260.  
  261. if [ -f /etc/security/rc.audit ]; then
  262.     . /etc/security/rc.audit
  263. fi
  264.  
  265. if [ -f /Library/Preferences/com.apple.sharing.firewall.plist ]; then
  266.     /usr/libexec/FirewallTool
  267. fi
  268.  
  269. # Load [ideally on demand] daemons
  270. if [ "${SafeBoot}" = "-x" ]; then
  271.     launchctl load /System/Library/LaunchDaemons /etc/mach_init.d
  272. else
  273.     launchctl load /Library/LaunchDaemons /System/Library/LaunchDaemons /etc/mach_init.d
  274.     SystemStarter ${VerboseFlag}
  275. fi
  276.  
  277. /usr/sbin/update
  278.  
  279. if [ "${NetBoot}" = "-N" ]; then
  280.     sh /etc/rc.netboot setup_computername
  281. fi
  282.  
  283. # Set language from CDIS.custom - assumes this is parse-able by sh
  284. if [ -f /var/log/CDIS.custom ]; then
  285.     . /var/log/CDIS.custom
  286. fi
  287.  
  288. # Start the Language Chooser. This code should be able to go away as far as I
  289. # know once loginwindow becomes more dynamic.
  290. STARTPBS="/System/Library/CoreServices/pbs"            # apps stall w/o
  291. BUDDYCOOKIE="/var/db/.AppleSetupDone"
  292. LCACOOKIE="/var/db/.RunLanguageChooserToo"
  293. STARTLCA="/System/Library/CoreServices/Language Chooser.app/Contents/MacOS/Language Chooser"
  294.  
  295. if [ -x "$STARTLCA" -a -x "$STARTPBS" -a ! -f "$BUDDYCOOKIE" -a -f "$LCACOOKIE" ]; then
  296.     "$STARTPBS" &
  297.     pbspid=$!
  298.     "$STARTLCA"
  299.     kill $pbspid    # XSelect does this independently
  300. fi
  301.  
  302. if [ ! -s "/var/log/CDIS.custom" ]; then
  303.     echo "Language Chooser seems to have failed; defaulting to English"
  304.     echo "LANGUAGE=English" > "/var/log/CDIS.custom"
  305. fi
  306.  
  307. export LANGUAGE
  308.  
  309. if [ -f /etc/rc.local ]; then
  310.     sh /etc/rc.local
  311. fi
  312.  
  313. touch /var/run/.systemStarterRunning
  314.  
  315. if [ "${VerboseFlag}" != "-v" ] ; then
  316.     /usr/libexec/WaitingForLoginWindow
  317. fi
  318.  
  319. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement