- Timestamp:
- 12/07/07 07:47:58 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init
r2544 r2632 1 #!/bin/sh 1 #!/bin/bash 2 2 3 ### BEGIN INIT INFO 3 # Provides: live-reboot4 # Provides: fll-reboot 4 5 # Required-Start: 5 # Required-Stop: 6 # Required-Stop: 6 7 # Default-Start: 7 # Default-Stop: 8 # Short-Description: halt/reboot service 9 # Description: Halt/Reboot Service for Parsix 8 # Default-Stop: 0 6 9 # Short-Description: shutdown and eject live media 10 # Description: This script provides the equivalent of umountfs, 11 # umountroot and halt on a stadard debian system. It umounts 12 # live mounts and ejects the live media at shutdown/reboot. 10 13 ### END INIT INFO 11 14 12 PATH=/sbin:/bin:/usr/bin:/usr/sbin 13 export PATH 14 15 # override tool behaviour through distro-defaults 15 ### 16 # F.U.L.L.S.T.O.R.Y init script 17 # 18 # Copyright: (C) 2007 F.U.L.L.S.T.O.R.Y Project 19 # Copyright: (C) 2007 Kel Modderman <kel@otaku42.de> 20 # Copyright: (C) 2007 Alan Baghumian <alan@technotux.org> 21 # License: GPLv2 22 # 23 # F.U.L.L.S.T.O.R.Y Project Homepage: 24 # http://developer.berlios.de/projects/fullstory 25 ### 26 27 PATH=/sbin:/usr/sbin:/bin:/usr/bin 28 NAME="fll-reboot" 29 30 ### 31 # source distro-defaults, no-op unless in live mode 32 ### 16 33 FLL_DISTRO_MODE="installed" 17 FLL_DISTRO_NAME="PARSIX" 18 19 #[ -r /etc/default/distro ] && . /etc/default/distro 20 #FLL_DISTRO_NAME="$(echo $FLL_DISTRO_NAME | tr [a-z] [A-Z])" 21 22 [ ! "$FLL_DISTRO_MODE" = "live" ] && exit 0 23 24 case "$1" in 34 35 if [ -s /etc/default/distro ]; then 36 . /etc/default/distro 37 fi 38 39 if [ "${FLL_DISTRO_MODE}" != "live" ]; then 40 exit 0 41 fi 42 43 ### 44 # VERBOSE setting and other rcS variables 45 ### 46 . /lib/init/vars.sh 47 48 ### 49 # source lsb functions 50 ### 51 . /lib/lsb/init-functions 52 53 ### 54 # ANSI escape sequences (N, R, G, Y, B, M, C, W) 55 ### 56 . /lib/fll/fll-init-cols 57 58 ### 59 # define this for copy_exec 60 ### 61 DESTDIR="/live-hack" 62 63 if [ -f /proc/cmdline ]; then 64 for param in $(cat /proc/cmdline); do 65 case "${param}" in 66 flldebug=*) 67 [ "${param#flldebug=}" = "${NAME#fll-}" ] && set -x 68 ;; 69 noeject) 70 NOEJECT="1" 71 ;; 72 noprompt) 73 NOPROMPT="1" 74 ;; 75 esac 76 done 77 fi 78 79 ############################################################################### 80 # Adapted from initscripts: /etc/init.d/umountfs (2.86.ds1-38) 81 ############################################################################### 82 # Print in order of decreasing length 83 # 84 # Algorithm: Find and print longest argument, then call self 85 # to print remaining arguments in order of decreasing length 86 # 87 # This function runs at one tenth the speed of the sort program 88 # but we use the function because we don't want to rely on any 89 # programs in /usr/. 90 # 91 # N.B.: Arguments must not be null and must not contain whitespace 92 # 93 pioodl() { 94 [ "$1" ] || return 0 95 96 ARGNUM=1 97 ARGNUM_LONGEST=0 98 ARGLENGTH_LONGEST=0 99 for ARG in "$@" 100 do 101 ARGLENGTH="${#ARG}" 102 if [ "$ARGLENGTH" -gt "$ARGLENGTH_LONGEST" ] 103 then 104 ARGLENGTH_LONGEST="$ARGLENGTH" 105 ARGNUM_LONGEST="$ARGNUM" 106 fi 107 ARGNUM=$(($ARGNUM + 1)) 108 done 109 110 # The method of passing prevargs assumes that args can be 111 # delimited with spaces 112 ARGNUM=1 113 PREVARGS="" 114 while [ "$ARGNUM" -lt "$ARGNUM_LONGEST" ] 115 do 116 PREVARGS="$PREVARGS $1" 117 shift 118 ARGNUM=$(($ARGNUM + 1)) 119 done 120 echo "$1" 121 shift 122 123 pioodl $PREVARGS "$@" 124 } 125 126 do_umount() { 127 exec 9<&0 < /proc/mounts 128 129 REG_MTPTS="" 130 TMPFS_MTPTS="" 131 while read DEV MTPT FSTYPE OPTS REST 132 do 133 case "$MTPT" in 134 # 135 # live hack 136 # 137 /fll/*) 138 case "$FSTYPE" in 139 iso9660) 140 if [ "$MTPT" = /fll/fromiso ]; then 141 LIVE_MTPTS="$LIVE_MTPTS $MTPT" 142 else 143 LIVE_CDROM="$DEV" 144 fi 145 ;; 146 *) 147 LIVE_MTPTS="$LIVE_MTPTS $MTPT" 148 ;; 149 esac 150 continue 151 ;; 152 # 153 # live hack 154 # 155 /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/lib/init/rw) 156 continue 157 ;; 158 /var/run) 159 if [ yes = "$RAMRUN" ] ; then 160 continue 161 fi 162 ;; 163 /var/lock) 164 if [ yes = "$RAMLOCK" ] ; then 165 continue 166 fi 167 ;; 168 esac 169 case "$FSTYPE" in 170 proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts) 171 continue 172 ;; 173 # 174 # live hack 175 # 176 aufs|unionfs) 177 UNION_MTPTS="$UNION_MTPTS $MTPT" 178 ;; 179 squashfs) 180 SQUSH_MTPTS="$SQUSH_MTPTS $MTPT" 181 ;; 182 # 183 # live hack 184 # 185 tmpfs) 186 TMPFS_MTPTS="$TMPFS_MTPTS $MTPT" 187 ;; 188 *) 189 REG_MTPTS="$REG_MTPTS $MTPT" 190 ;; 191 esac 192 done 193 194 exec 0<&9 9<&- 195 196 # 197 # Make sure tmpfs file systems are umounted before turning off 198 # swap, to avoid running out of memory if the tmpfs filesystems 199 # use a lot of space. 200 # 201 if [ "$TMPFS_MTPTS" ] 202 then 203 TMPFS_MTPTS="$(pioodl $TMPFS_MTPTS)" 204 if [ "$VERBOSE" = no ] 205 then 206 log_action_begin_msg "Unmounting temporary filesystems" 207 umount $TMPFS_MTPTS 208 log_action_end_msg $? 209 else 210 log_daemon_msg "Will now unmount temporary filesystems" 211 umount -v $TMPFS_MTPTS 212 log_end_msg $? 213 fi 214 fi 215 216 # 217 # Deactivate swap 218 # 219 if [ "$VERBOSE" = no ] 220 then 221 log_action_begin_msg "Deactivating swap" 222 swapoff -a >/dev/null 223 log_action_end_msg $? 224 else 225 log_daemon_msg "Will now deactivate swap" 226 swapoff -a -v 227 log_end_msg $? 228 fi 229 230 # 231 # Unmount local filesystems 232 # 233 if [ "$REG_MTPTS" ] 234 then 235 REG_MTPTS="$(pioodl $REG_MTPTS)" 236 if [ "$VERBOSE" = no ] 237 then 238 log_action_begin_msg "Unmounting local filesystems" 239 umount -n -f -r -d $REG_MTPTS 240 log_action_end_msg $? 241 else 242 log_daemon_msg "Will now unmount local filesystems" 243 umount -n -f -v -r -d $REG_MTPTS 244 log_end_msg $? 245 fi 246 fi 247 248 # 249 # live hack: any command after this point must be prefixed with ${BINDIR} 250 # 251 if [ "$UNION_MTPTS" ] 252 then 253 UNION_MTPTS="$(pioodl $UNION_MTPTS)" 254 if [ "$VERBOSE" = no ] 255 then 256 log_action_begin_msg "Unmounting union filesystems" 257 ${BINDIR}umount -l -n -f -d $UNION_MTPTS 258 log_action_end_msg $? 259 else 260 log_daemon_msg "Will now unmount union filesystems" 261 ${BINDIR}umount -l -n -f -v -d $UNION_MTPTS 262 log_end_msg $? 263 fi 264 fi 265 266 if [ "$SQSH_MTPTS" ] 267 then 268 SQSH_MTPTS="$(pioodl $SQSH_MTPTS)" 269 if [ "$VERBOSE" = no ] 270 then 271 log_action_begin_msg "Unmounting squashfs filesystems" 272 ${BINDIR}umount -l -n -f -d $SQSH_MTPTS 273 log_action_end_msg $? 274 else 275 log_daemon_msg "Will now unmount squashfs filesystems" 276 ${BINDIR}umount -l -n -f -v -d $SQSH_MTPTS 277 log_end_msg $? 278 fi 279 fi 280 281 if [ "$LIVE_MTPTS" ] 282 then 283 LIVE_MTPTS="$(pioodl $LIVE_MTPTS)" 284 if [ "$VERBOSE" = no ] 285 then 286 log_action_begin_msg "Unmounting live filesystems" 287 ${BINDIR}umount -l -n -f -d $LIVE_MTPTS 288 log_action_end_msg $? 289 else 290 log_daemon_msg "Will now unmount live filesystems" 291 ${BINDIR}umount -l -n -f -v -d $LIVE_MTPTS 292 log_end_msg $? 293 fi 294 fi 295 296 if [ "$LIVE_CDROM" ]; then 297 export LIVE_CDROM 298 fi 299 } 300 ############################################################################### 301 # Adapted from initramfs-tools hook-functions (0.87b) 302 ############################################################################### 303 # $1 is source 304 # $2 is relative destination 305 copy_exec() { 306 local verbose="${VERBOSE}" 307 local final_destination=${DESTDIR}/${2}/`basename ${1}` 308 309 if [ -L "$final_destination" ]; then 310 if ! [ `readlink ${final_destination}` = "${1}" ]; then 311 return 312 fi 313 else 314 cp ${1} ${DESTDIR}/${2} 315 if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then 316 echo "Adding binary ${1}" 317 fi 318 fi 319 320 # Copy the dependant libraries 321 for x in $(ldd ${1} 2>/dev/null | sed -e ' 322 /\//!d; 323 /linux-gate/d; 324 /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/}; 325 s/[[:blank:]]*\([^[:blank:]]*\) (.*)/\1/' 2>/dev/null); do 326 327 # Try to use non-optimised libraries where possible. 328 # We assume that all HWCAP libraries will be in tls. 329 nonoptlib=$(echo ${x} | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#') 330 331 if [ -e ${nonoptlib} ]; then 332 x=${nonoptlib} 333 fi 334 335 libname=$(basename ${x}) 336 dirname=$(dirname ${x}) 337 338 mkdir -p ${DESTDIR}/${dirname} 339 if [ ! -e ${DESTDIR}/${dirname}/${libname} ]; then 340 cp ${x} ${DESTDIR}/${dirname} 341 if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then 342 echo "Adding library ${x}" 343 fi 344 fi 345 done 346 } 347 ############################################################################### 348 # End adapted functions 349 ############################################################################### 350 351 live_hack() { 352 mkdir -p ${DESTDIR}/bin 353 copy_exec /bin/umount /bin 354 copy_exec /sbin/halt /bin 355 copy_exec /sbin/reboot /bin 356 copy_exec /usr/bin/eject /bin 357 358 LD_LIBRARY_PATH="${DESTDIR}/lib" 359 if [ -e "${DESTDIR}/lib64" ]; then 360 LD_LIBRARY_PATH="${DESTDIR}/lib64:${LD_LIBRARY_PATH}" 361 fi 362 export LD_LIBRARY_PATH 363 364 LD_LINUX="${DESTDIR}/lib/ld-linux.so.2" 365 if [ -e "${DESTDIR}/lib64/ld-linux-x86-64.so.2" ]; then 366 LD_LINUX="${DESTDIR}/lib64/ld-linux-x86-64.so.2" 367 fi 368 export LD_LINUX 369 370 PATH="${DESTDIR}/bin:${PATH}" 371 export PATH 372 373 BINDIR="${LD_LINUX} ${DESTDIR}/bin/" 374 export BINDIR 375 } 376 377 pop_live_cd() 378 { 379 if [ -z "${LIVE_CDROM}" ] || [ "${NOEJECT}" ]; then 380 return 0 381 fi 382 383 # 384 # disable kernel messages while ejecting cdrom (libata noise) 385 # 386 echo "0" > /proc/sys/kernel/printk 387 388 if [ -b "${LIVE_CDROM}" ]; then 389 ${BINDIR}eject -m -p ${LIVE_CDROM} 390 fi 391 392 echo "6" > /proc/sys/kernel/printk 393 394 if [ -z "${NOPROMPT}" ]; then 395 echo "${Y}Please remove CD, close cdrom drive and hit return.${N}" > /dev/console 396 read 397 fi 398 } 399 400 do_stop() { 401 local command message options 402 403 # prepare binaries for post-umount of live media 404 live_hack 405 # umount the live media and other mount points 406 do_umount 407 408 case "${0}" in 409 *halt) 410 message="${G}${FLL_DISTRO_SNAME} halted.${N}" 411 command="halt" 412 options="-h -n -p -i -f" 413 ;; 414 *reboot) 415 message="${G}Preparing for reboot...${N}" 416 command="reboot" 417 options="-n -i -f" 418 ;; 419 *) 420 echo "${0}: call this script as \"halt\" or \"reboot\" please!" 421 exit 1 422 ;; 423 esac 424 425 echo "${message}" > /dev/console 426 427 pop_live_cd 428 429 exec ${BINDIR}${command} ${options} > /dev/console 2>&1 < /dev/console 430 } 431 432 case "${1}" in 25 433 start) 434 # no-op 435 ;; 436 restart|reload|force-reload) 437 echo "Error: argument '${1}' not supported" >&2 438 exit 3 26 439 ;; 27 440 stop) 441 # live-hack, umount and eject 442 do_stop 28 443 ;; 29 restart|force-reload) 444 *) 445 echo "Usage: ${NAME} {start|stop}" >&2 446 exit 3 30 447 ;; 31 448 esac 32 33 # Clean input/output34 exec > /dev/console 2>&1 < /dev/console35 36 NORMAL="[0;39m"37 RED="[1;31m"38 GREEN="[1;32m"39 YELLOW="[1;33m"40 BLUE="[1;34m"41 MAGENTA="[1;35m"42 CYAN="[1;36m"43 WHITE="[1;37m"44 45 case "$0" in46 *halt)47 message="${YELLOW}${FLL_DISTRO_NAME} halted.${NORMAL}"48 command="halt"49 options="-p -d -i -f"50 ;;51 *reboot)52 message="${GREEN}Preparing for reboot...${NORMAL}"53 command="reboot"54 options="-d -i -f"55 ;;56 *)57 echo "$0: call this script as \"halt\" or \"reboot\" please!"58 exit 159 ;;60 esac61 62 # No sync and no wtmp entry if running from CD63 options="$options -n"64 65 mysleep()66 {67 for i in $(seq 1 40); do68 sleep "0.075s"69 echo -n "$1.${NORMAL}"70 done71 echo ""72 }73 74 # Disable kernel messages75 echo "0" > /proc/sys/kernel/printk76 77 # poweroff pcmcia devices78 if lsmod | grep -q pcmcia_core 2>&1 > /dev/null; then79 echo -n "${BLUE}Shutting down PCMCIA devices...${NORMAL}"80 pccardctl eject 2>&1 > /dev/null81 sleep 282 echo ""83 fi84 85 # Now kill them all86 killall5 -1587 sleep 188 echo -n "${BLUE}Sent all processes the TERM signal...${NORMAL}"89 mysleep "$BLUE"90 91 killall5 -992 sleep 193 echo -n "${RED}Sent all processes the KILL signal...${NORMAL}"94 mysleep "$RED"95 96 # Unmount network filesystems first before shutting down network97 NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2> /dev/null)"98 if [ -n "$NETMOUNTS" ]; then99 echo "${BLUE}Unmounting network filesystems.${NORMAL}"100 umount -t nfs -arvf 2> /dev/null101 fi102 103 # Shutdown network104 NETDEVICES="$(awk -F: '/ath.:|eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"105 if [ -n "$NETDEVICES" ]; then106 pidof pump 2>&1 > /dev/null && { pump -k ; sleep 2; }107 echo -n "${BLUE}Shutting down network device${NORMAL}"108 for n in $NETDEVICES; do109 echo -n " ${MAGENTA}$n${NORMAL}"110 ifconfig "$n" down111 done112 echo ""113 fi114 115 # read cmdline params116 NOEJECT=""117 NOPROMPT=""118 read CMDLINE <<EOT119 $(cat /proc/cmdline 2> /dev/null)120 EOT121 case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac122 case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac123 124 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"125 126 # This uses standard sysvinit127 FINALCMD="/etc/live-hack/$command"128 rm -rf /etc/live-hack 2>&1 > /dev/null129 mkdir -p /etc/live-hack130 [ -x "/etc/live-hack/$command" ] || cp -p "/sbin/$command" /etc/live-hack/131 [ -x /usr/bin/eject ] && cp -p /usr/bin/eject /etc/live-hack/eject132 LD_LINUX=ld-linux.so.2133 [ -x /lib/ld-linux-x86-64.so.2 ] && LD_LINUX=ld-linux-x86-64.so.2134 [ -x "/etc/live-hack/$LD_LINUX" ] || cp -p "/lib/$LD_LINUX" /etc/live-hack/135 136 # Turn off swap, then unmount file systems.137 swapoff -a 2>&1 > /dev/null138 139 echo "${BLUE}Unmounting file systems.${NORMAL}"140 141 cd /142 143 # Umount everything but root144 umount -arvf 2> /dev/null145 if [ "$?" != "0" ] ; then146 # Free loopback devices if necessary, so we can unmount the host media147 for i in /dev/loop*; do losetup -d "$i" 2> /dev/null; done148 # And retry149 umount -arf 2> /dev/null150 fi151 152 # Remove remaining unused modules153 rmmod -a 2>&1 > /dev/null154 155 echo "$message" > /dev/console156 157 # eject CD-ROM, noprompt implies noeject (backward compatibility)158 if [ -z "$NOPROMPT" ]; then159 [ -n "$CDROM" -a -z "$NOEJECT" ] && "/etc/live-hack/$LD_LINUX" /etc/live-hack/eject -m -p "$CDROM" 2>&1 >/dev/null160 echo "${CYAN}Please remove CD, close cdrom drive and hit return.${NORMAL}"161 read162 fi163 164 # Now halt or reboot.165 exec "/etc/live-hack/$LD_LINUX" "$FINALCMD" $options > /dev/console 2>&1 < /dev/console166
Note: See TracChangeset
for help on using the changeset viewer.


