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.

238 lines
6.4 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/target/livecd/fixedfiles/system
  11. # ROCK Linux is Copyright (C) 1998 - 2006 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. title() {
  29. local x w="$( stty size 2>/dev/null </dev/tty | cut -d" " -f2 )"
  30. [ -z "$w" ] && w="$( stty size </dev/console | cut -d" " -f2 )"
  31. for (( x=1; x<w; x++ )) do echo -n .; done
  32. echo -e "\e[222G\e[3D v \r\e[36m$* \e[0m"
  33. error=0
  34. }
  35. status() {
  36. if [ $error -eq 0 ]
  37. then
  38. echo -e "\e[1A\e[222G\e[4D\e[32m :-)\e[0m"
  39. else
  40. echo -e "\e[1A\e[222G\e[4D\a\e[1;31m :-(\e[0m"
  41. fi
  42. }
  43. case "$1" in
  44. start)
  45. title "Creating valid /etc/mtab ..."
  46. grep -v "^rootfs " /proc/mounts > /etc/mtab || error=$?
  47. status
  48. if [ -f /etc/conf/hardware ] ; then
  49. . /etc/conf/hardware
  50. fi
  51. if [ -f /etc/conf/devfs ] ; then
  52. title "Configuring the /dev filesystem ..."
  53. sh /etc/conf/devfs || error=$?
  54. status
  55. fi
  56. if [ -d /etc/hotplug ] ; then
  57. title "Configuring hardware by activating hotplug."
  58. [ -f /proc/sys/kernel/hotplug ] && \
  59. echo "/sbin/hotplug" > /proc/sys/kernel/hotplug
  60. for RC in /etc/hotplug/*.rc; do
  61. echo -n "[$( basename ${RC%.rc} )] "
  62. $RC start || error=$?;
  63. done ; echo
  64. mkdir -p /var/lock/subsys
  65. touch /var/lock/subsys/hotplug
  66. status
  67. fi
  68. title "Loading kernel modules and configuring the kernel."
  69. if [ -f /etc/conf/kernel ] ; then
  70. sh /etc/conf/kernel || error=$?
  71. fi
  72. [ -f /etc/conf/clock ] && . /etc/conf/clock
  73. if [ "$clock_tz" = localtime ] ; then
  74. status
  75. title "Setting kernel clock to local time."
  76. hwclock --hctosys --localtime || error=$?
  77. fi
  78. status
  79. if [ "$clock_rtc" ] ; then
  80. if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
  81. title "Setting enhanced real time clock precision to $clock_rtc."
  82. echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq || error=$?
  83. status
  84. fi
  85. fi
  86. title "Setting hostname to $(cat /etc/HOSTNAME)."
  87. hostname "$(cat /etc/HOSTNAME)" || error=$?
  88. status
  89. mkdir /tmp/.ICE-unix
  90. chmod 1777 /tmp/.ICE-unix
  91. title "Writing /var/log/boot.msg."
  92. dmesg > /var/log/boot.msg || error=$?
  93. status
  94. if [ -e /etc/default.keymap ] ; then
  95. title "Setting keyboard mappings."
  96. mapfile=$( readlink -f /etc/default.keymap )
  97. loadkeys $mapfile || error=$?
  98. status
  99. fi
  100. title "Setting keyboard repeat rate and delay time."
  101. kbd_rate=30; kbd_delay=250
  102. [ -f /etc/conf/kbd ] && . /etc/conf/kbd
  103. /usr/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console || error=$?
  104. status
  105. if [ -e /etc/default.vcfont ] ; then
  106. title "Setting console screen font."
  107. fontfile=$( readlink -f /etc/default.vcfont )
  108. setfont $fontfile || error=$?
  109. status
  110. fi
  111. title "Setting console terminal type and blank interval."
  112. con_term=linux; con_blank=0
  113. [ -f /etc/conf/console ] && . /etc/conf/console
  114. /usr/bin/setterm -term $con_term -blank $con_blank > /dev/console || error=$?
  115. status
  116. title "Setting up loopback networking."
  117. ip link set lo up || error=$?
  118. ip addr add 127.0.0.1/8 dev lo || error=$?
  119. ip route add 127/8 dev lo || error=$?
  120. status
  121. title "Setting overflow UID and GID kernel parameters."
  122. sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null || error=$?
  123. sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null || error=$?
  124. status
  125. if [ -e /etc/sysctl.conf ] ; then
  126. title "Reading /etc/sysctl.conf file."
  127. sysctl -p || error=$?
  128. status
  129. fi
  130. if [ -e /var/state/random-seed ] ; then
  131. title "Initializing kernel random number generator."
  132. cat /var/state/random-seed >/dev/urandom || error=$?
  133. status
  134. fi
  135. title "Setting mixer devices Master and PCM to 65%."
  136. /usr/bin/amixer sset PCM 20 >/dev/null 2>&1 || error=$?
  137. /usr/bin/amixer sset PCM unmute >/dev/null 2>&1 || error=$?
  138. /usr/bin/amixer sset Master 20 >/dev/null 2>&1 || error=$?
  139. /usr/bin/amixer sset Master unmute >/dev/null 2>&1 || error=$?
  140. status
  141. ;;
  142. stop)
  143. title "Unconfiguring hardware by de-activating hotplug."
  144. for RC in /etc/hotplug/*.rc; do
  145. echo -n "[$( basename ${RC%.rc} )] "
  146. $RC stop || error=$?;
  147. done ; echo
  148. rm -f /var/lock/subsys/hotplug
  149. status
  150. title "Sending all processes a SIGTERM (15)."
  151. killall5 -15 || error=$? ; sleep 5
  152. status
  153. title "Sending all processes a 2nd SIGTERM (15)."
  154. killall5 -15 || error=$? ; sleep 5
  155. status
  156. title "Sending all processes a SIGKILL (9)."
  157. killall5 -9 || error=$? ; sleep 5
  158. status
  159. title "Turning off swap devices."
  160. swapoff -a || error=$?
  161. sync ; sleep 1
  162. status
  163. title "Remounting sync/ro and umount filesystems."
  164. cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r | \
  165. while read dev dir fs ; do
  166. [ "$dir" = "/" ] && continue
  167. [ "$dir" = "/dev" ] && continue
  168. [ "$dir" = "/dev/shm" ] && continue
  169. [ "$dir" = "/proc" ] && continue
  170. [ "$dir" = "/sys" ] && continue
  171. [ "$dir" = "/tmp" ] && continue
  172. echo "Umounting $dev on $dir ($fs)."
  173. mount -o remount,sync $dir
  174. mount -o remount,ro $dir
  175. umount -d $dir
  176. bash
  177. done
  178. status
  179. title "Unmounting remaining file systems."
  180. grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
  181. sync ; sleep 1 ; sync
  182. umount -vdnra -t nodevfs,proc,sysfs,shm
  183. mount -vn -o remount,sync /
  184. mount -vn -o remount,ro /
  185. sleep 1 ; sync ; sleep 1
  186. status
  187. command=""
  188. [ "$RUNLEVEL" = 0 ] && command=halt
  189. [ "$RUNLEVEL" = 6 ] && command=reboot
  190. if [ -n "$command" ] ; then
  191. echo "Going to $command the system ..."
  192. $command -d -f -i -p
  193. while true ; do sleep 1 ; done
  194. fi
  195. ;;
  196. restart)
  197. $0 stop; $0 start
  198. ;;
  199. *)
  200. echo "Usage: $0 { start | stop | restart }"
  201. exit 1
  202. ;;
  203. esac
  204. exit 0