mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.0 KiB

  1. #!/bin/sh
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/package/base/sysfiles/system.init
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. #
  25. # Desc: System bootup and shutdown
  26. # Runlevel: 01 rcX rc1 rc2 rc3 rc4 rc5
  27. #
  28. main_begin
  29. block_begin(start, `Mounting /dev, /proc, /dev/shm and /tmp.')
  30. check(`[ -e /dev/.devfsd ] || mount -n /dev')
  31. check(`mount -n /proc')
  32. check(`mount -n /dev/shm')
  33. mount -n /dev/pts 2> /dev/null
  34. mount -n /tmp 2> /dev/null
  35. dnl
  36. if [ -f /etc/conf/hardware ]; then
  37. . /etc/conf/hardware
  38. fi
  39. block_split(`Configuring the /dev filesystem ...')
  40. check(`sh /etc/conf/devfs')
  41. block_split(`Activating swap devices.')
  42. check(`swapon -a')
  43. dnl
  44. block_split(`Checking file systems.')
  45. fsck -A -C -a ; fsckrc=$?
  46. if [ $(( $fsckrc & ~3 )) != 0 ] ; then
  47. echo " **"
  48. echo " ** Filesystem check failed (returncode=$fsckrc)."
  49. echo " ** Please repair the broken disk(s) manually."
  50. echo " **"
  51. sulogin -t 600 /dev/console
  52. umount -arv ; /sbin/reboot -d -f
  53. while true ; do sleep 1 ; done
  54. elif [ $(( $fsckrc & 2 )) != 0 ] ; then
  55. for x in 10 9 8 7 6 5 4 3 2 ; do
  56. echo -en "\rSystem reboot in $x seconds ... "
  57. sleep 1
  58. done ; echo -e "\rSystem reboot now! "
  59. umount -arv ; /sbin/reboot -d -f
  60. while true ; do sleep 1 ; done
  61. fi
  62. dnl
  63. block_split(`Mounting file systems.')
  64. check(`mount -n -o remount,rw /')
  65. rootdev="/dev/$(ls -l /dev/root | sed 's,.* -> ,,')"
  66. check(`grep -v "^rootfs " /proc/mounts | \
  67. sed "s,^/dev/root ,$rootdev ," > /etc/mtab')
  68. check(`mount -a -t nocoda,nfs')
  69. dnl
  70. if [ "$HARDWARE_SETUP" = rockplug ]; then
  71. block_split(`Configuring hardware by activating rockplug.')
  72. echo "/sbin/rockplug" > /proc/sys/kernel/hotplug
  73. for file in /etc/rockplug/*.init ; do
  74. [ -f $file ] && $file start
  75. done
  76. else
  77. block_split(`Loading kernel modules and configuring the kernel.')
  78. check(`sh /etc/conf/kernel')
  79. fi
  80. dnl
  81. [ -f /etc/conf/clock ] && . /etc/conf/clock
  82. if [ "$clock_tz" = localtime ] ; then
  83. block_split(`Setting kernel clock to local time.')
  84. check(`hwclock --hctosys --localtime')
  85. fi
  86. if [ "$clock_rtc" ] ; then
  87. block_split(`Setting enhanced real time clock precision to $clock_rtc.')
  88. if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
  89. check(`echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq')
  90. else
  91. echo "No /proc/sys/dev/rtc/max-user-freq found."
  92. fi
  93. fi
  94. dnl
  95. block_split(`Setting hostname to $(cat /etc/HOSTNAME).')
  96. check(`hostname "$(cat /etc/HOSTNAME)"')
  97. dnl
  98. block_split(`Refresh utmp, delete lock files and other stuff.')
  99. rm -f /var/lock/* /var/lock/*/* /var/run/* 2> /dev/null
  100. rm -f /etc/nologin /nologin /fastboot ; touch /var/run/utmp
  101. chmod 664 /var/run/utmp ; chown root.tty /var/run/utmp
  102. dnl
  103. block_split(`Writing /var/log/boot.msg.')
  104. klogd -f /var/log/boot.msg -o ; dmesg -n 3
  105. dnl
  106. block_split(`Setting keyboard keymappings.')
  107. if [ -L /etc/default.keymap ] ; then
  108. mapfile=$(ls -l /etc/default.keymap | sed 's,.* -> ,,')
  109. check(`loadkeys $mapfile')
  110. elif [ -f /etc/default.keymap ] ; then
  111. check(`loadkeys /etc/default.keymap')
  112. else
  113. echo "No /etc/default.keymap found."
  114. fi
  115. dnl
  116. block_split(`Setting keyboard repeat rate and delay time.')
  117. kbd_rate=30; kbd_delay=250
  118. [ -f /etc/conf/kbd ] && . /etc/conf/kbd
  119. check(`D_prefix/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console')
  120. dnl
  121. block_split(`Setting console screen font.')
  122. if [ -L /etc/default.vcfont ] ; then
  123. fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
  124. check(`setfont $fontfile')
  125. elif [ -f /etc/default.vcfont ] ; then
  126. check(`setfont /etc/default.vcfont')
  127. else
  128. echo "No /etc/default.vcfont found."
  129. fi
  130. dnl
  131. block_split(`Setting console terminal type and blank interval.')
  132. con_term=linux; con_blank=0
  133. [ -f /etc/conf/console ] && . /etc/conf/console
  134. check(`D_prefix/bin/setterm -term $con_term -blank $con_blank > /dev/console')
  135. dnl
  136. block_split(`Setting up loopback networking.')
  137. check(`ip link set lo up')
  138. check(`ip addr add 127.0.0.1/8 dev lo')
  139. check(`ip route add 127/8 dev lo')
  140. dnl
  141. block_split(`Setting overflow UID and GID kernel parameters.')
  142. check(`sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null')
  143. check(`sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null')
  144. dnl
  145. block_split(`Reading /etc/sysctl.conf file.')
  146. check(`sysctl -p')
  147. dnl
  148. block_split(`Initializing kernel random number generator.')
  149. if [ -e /var/state/random-seed ] ; then
  150. check(`cat /var/state/random-seed >/dev/urandom')
  151. fi
  152. block_end
  153. block_begin(stop, `Saving /var/log/init.msg and /var/log/boot.msg.')
  154. check(`touch /var/log/init.msg /var/log/boot.msg')
  155. check(`mv /var/log/init.msg /var/log/init.old')
  156. check(`mv /var/log/boot.msg /var/log/boot.old')
  157. block_split(`Writing a wtmp record.')
  158. if [ "$RUNLEVEL" = 0 ] ; then check(`halt -w')
  159. else check(`reboot -w') ; fi
  160. block_split(`Saving kernel random seed.')
  161. dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
  162. dnl
  163. block_split(`Sending all processes a SIGTERM (15).')
  164. check(`killall5 -15') ; sleep 5
  165. block_split(`Sending all processes a 2nd SIGTERM (15).')
  166. check(`killall5 -15') ; sleep 5
  167. block_split(`Sending all processes a SIGKILL (9).')
  168. check(`killall5 -9') ; sleep 5
  169. dnl
  170. block_split(`Turning off swap devices.')
  171. check(`swapoff -a')
  172. sync ; sleep 1
  173. dnl
  174. block_split(`Remounting sync/ro and umount filesystems.')
  175. cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r | \
  176. while read dev dir fs ; do
  177. [ "$dir" = "/" ] && continue
  178. [ "$dir" = "/dev" ] && continue
  179. [ "$dir" = "/dev/shm" ] && continue
  180. [ "$dir" = "/proc" ] && continue
  181. [ "$dir" = "/tmp" ] && continue
  182. echo "Umounting $dev on $dir ($fs)."
  183. mount -o remount,sync $dir
  184. mount -o remount,ro $dir
  185. umount $dir
  186. done
  187. dnl
  188. block_split(`Unmounting remaining file systems.')
  189. grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
  190. sync ; sleep 1 ; sync
  191. umount -vnra -t noproc,devfs,shm
  192. mount -vn -o remount,sync /
  193. mount -vn -o remount,ro /
  194. sleep 1 ; sync ; sleep 1
  195. dnl
  196. block_split()
  197. [ "$RUNLEVEL" = 0 ] && command=halt || command=reboot
  198. echo "Going to $command the system ..."
  199. $command -d -f -i -p
  200. while true ; do sleep 1 ; done
  201. block_end
  202. main_end