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.

249 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 "Runnind 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. status
  91. title "Writing /var/log/boot.msg."
  92. klogd -f /var/log/boot.msg -o ; dmesg -n 3
  93. status
  94. title "Setting keyboard keymappings."
  95. if [ -L /etc/default.keymap ] ; then
  96. mapfile=$(ls -l /etc/default.keymap | sed 's,.* -> ,,')
  97. loadkeys $mapfile || error=$?
  98. elif [ -f /etc/default.keymap ] ; then
  99. loadkeys /etc/default.keymap || error=$?
  100. else
  101. echo "No /etc/default.keymap found."
  102. fi
  103. status
  104. title "Setting keyboard repeat rate and delay time."
  105. kbd_rate=30; kbd_delay=250
  106. [ -f /etc/conf/kbd ] && . /etc/conf/kbd
  107. /usr/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console || error=$?
  108. status
  109. title "Setting console screen font."
  110. if [ -L /etc/default.vcfont ] ; then
  111. fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
  112. setfont $fontfile || error=$?
  113. elif [ -f /etc/default.vcfont ] ; then
  114. setfont /etc/default.vcfont || error=$?
  115. else
  116. echo "No /etc/default.vcfont found."
  117. fi
  118. status
  119. title "Setting console terminal type and blank interval."
  120. con_term=linux; con_blank=0
  121. [ -f /etc/conf/console ] && . /etc/conf/console
  122. /usr/bin/setterm -term $con_term -blank $con_blank > /dev/console || error=$?
  123. status
  124. title "Setting up loopback networking."
  125. ip link set lo up || error=$?
  126. ip addr add 127.0.0.1/8 dev lo || error=$?
  127. ip route add 127/8 dev lo || error=$?
  128. status
  129. title "Setting overflow UID and GID kernel parameters."
  130. sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null || error=$?
  131. sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null || error=$?
  132. status
  133. title "Reading /etc/sysctl.conf file."
  134. sysctl -p || error=$?
  135. status
  136. title "Initializing kernel random number generator."
  137. if [ -e /var/state/random-seed ] ; then
  138. cat /var/state/random-seed >/dev/urandom || error=$?
  139. fi
  140. status
  141. title "Setting mixer devices Master and PCM to 65%."
  142. /usr/bin/amixer sset PCM 20 >/dev/null 2>&1 || error=$?
  143. /usr/bin/amixer sset PCM unmute >/dev/null 2>&1 || error=$?
  144. /usr/bin/amixer sset Master 20 >/dev/null 2>&1 || error=$?
  145. /usr/bin/amixer sset Master unmute >/dev/null 2>&1 || error=$?
  146. status
  147. ;;
  148. stop)
  149. title "Saving /var/log/init.msg and /var/log/boot.msg."
  150. touch /var/log/init.msg /var/log/boot.msg || error=$?
  151. mv /var/log/init.msg /var/log/init.old || error=$?
  152. mv /var/log/boot.msg /var/log/boot.old || error=$?
  153. status
  154. title "Writing a wtmp record."
  155. if [ "$RUNLEVEL" = 0 ] ; then halt -w || error=$?
  156. else reboot -w || error=$? ; fi
  157. status
  158. title "Saving kernel random seed."
  159. dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
  160. status
  161. title "Sending all processes a SIGTERM (15)."
  162. killall5 -15 || error=$? ; sleep 5
  163. status
  164. title "Sending all processes a 2nd SIGTERM (15)."
  165. killall5 -15 || error=$? ; sleep 5
  166. status
  167. title "Sending all processes a SIGKILL (9)."
  168. killall5 -9 || error=$? ; sleep 5
  169. status
  170. title "Turning off swap devices."
  171. swapoff -a || error=$?
  172. sync ; sleep 1
  173. status
  174. title "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" = "/sys" ] && continue
  182. [ "$dir" = "/tmp" ] && continue
  183. echo "Umounting $dev on $dir ($fs)."
  184. mount -o remount,sync $dir
  185. mount -o remount,ro $dir
  186. umount -d $dir
  187. done
  188. status
  189. title "Unmounting remaining file systems."
  190. grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
  191. sync ; sleep 1 ; sync
  192. umount -vdnra -t nodevfs,proc,sysfs,shm
  193. mount -vn -o remount,sync /
  194. mount -vn -o remount,ro /
  195. sleep 1 ; sync ; sleep 1
  196. status
  197. command=""
  198. [ "$RUNLEVEL" = 0 ] && command=halt
  199. [ "$RUNLEVEL" = 6 ] && command=reboot
  200. if [ -n "$command" ] ; then
  201. echo "Going to $command the system ..."
  202. $command -d -f -i -p
  203. while true ; do sleep 1 ; done
  204. fi
  205. ;;
  206. restart)
  207. $0 stop; $0 start
  208. ;;
  209. *)
  210. echo "Usage: $0 { start | stop }"
  211. exit 1 ;;
  212. esac
  213. exit 0