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.

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