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.

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