| 1 | 
           beyerle@PS | 
           1 | 
           #!/bin/bash
  | 
        
        
            | 
            | 
           2 | 
           #
  | 
        
        
            | 
            | 
           3 | 
           # halt          This file is executed by init when it goes into runlevel
  | 
        
        
            | 
            | 
           4 | 
           #               0 (halt) or runlevel 6 (reboot). It kills all processes,
  | 
        
        
            | 
            | 
           5 | 
           #               unmounts file systems and then either halts or reboots.
  | 
        
        
            | 
            | 
           6 | 
           #
  | 
        
        
            | 
            | 
           7 | 
           # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
  | 
        
        
            | 
            | 
           8 | 
           #               Modified for RHS Linux by Damien Neil
  | 
        
        
            | 
            | 
           9 | 
           #
  | 
        
        
           | 206 | 
           beyerleu | 
           10 | 
           # modified for LiveCD, Urs Beyerle
  | 
        
        
           | 1 | 
           beyerle@PS | 
           11 | 
              | 
        
        
            | 
            | 
           12 | 
           NOLOCALE=1
  | 
        
        
            | 
            | 
           13 | 
           . /etc/init.d/functions
  | 
        
        
            | 
            | 
           14 | 
              | 
        
        
           | 206 | 
           beyerleu | 
           15 | 
           UMOUNT="umount"
  | 
        
        
            | 
            | 
           16 | 
           [ ! -w /etc ] && UMOUNT="umount -n"
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
           | 1 | 
           beyerle@PS | 
           18 | 
           action() {
  | 
        
        
            | 
            | 
           19 | 
              echo -n "$1 "
  | 
        
        
            | 
            | 
           20 | 
              shift
  | 
        
        
            | 
            | 
           21 | 
              if [ "$BOOTUP" = "color" ]; then
  | 
        
        
            | 
            | 
           22 | 
                 "$@" && echo_success || echo_failure
  | 
        
        
            | 
            | 
           23 | 
              else
  | 
        
        
            | 
            | 
           24 | 
                 "$@"
  | 
        
        
            | 
            | 
           25 | 
              fi
  | 
        
        
            | 
            | 
           26 | 
              echo
  | 
        
        
            | 
            | 
           27 | 
           }
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           halt_crypto() {
  | 
        
        
            | 
            | 
           30 | 
               fnval=0
  | 
        
        
            | 
            | 
           31 | 
               while read dst src key; do
  | 
        
        
            | 
            | 
           32 | 
           	[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
  | 
        
        
            | 
            | 
           33 | 
                   if [ -b "/dev/mapper/$dst" ]; then
  | 
        
        
            | 
            | 
           34 | 
                       if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
  | 
        
        
            | 
            | 
           35 | 
                           /sbin/cryptsetup remove "$dst"
  | 
        
        
            | 
            | 
           36 | 
                       else
  | 
        
        
            | 
            | 
           37 | 
                           fnval=1
  | 
        
        
            | 
            | 
           38 | 
                       fi
  | 
        
        
            | 
            | 
           39 | 
                   fi
  | 
        
        
            | 
            | 
           40 | 
               done < /etc/crypttab
  | 
        
        
            | 
            | 
           41 | 
               return $fnval
  | 
        
        
            | 
            | 
           42 | 
           }
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           # See how we were called.
  | 
        
        
            | 
            | 
           45 | 
           case "$0" in
  | 
        
        
            | 
            | 
           46 | 
              *halt)
  | 
        
        
            | 
            | 
           47 | 
           	message=$"Halting system..."
  | 
        
        
            | 
            | 
           48 | 
           	command="/sbin/halt"
  | 
        
        
            | 
            | 
           49 | 
           	;;
  | 
        
        
            | 
            | 
           50 | 
              *reboot)
  | 
        
        
            | 
            | 
           51 | 
           	message=$"Please stand by while rebooting the system..."
  | 
        
        
            | 
            | 
           52 | 
           	command="/sbin/reboot"
  | 
        
        
            | 
            | 
           53 | 
           	kexec_command="/sbin/kexec"
  | 
        
        
            | 
            | 
           54 | 
           	;;
  | 
        
        
            | 
            | 
           55 | 
              *)
  | 
        
        
            | 
            | 
           56 | 
           	echo $"$0: call me as 'halt' or 'reboot' please!"
  | 
        
        
            | 
            | 
           57 | 
           	exit 1
  | 
        
        
            | 
            | 
           58 | 
           	;;
  | 
        
        
            | 
            | 
           59 | 
           esac
  | 
        
        
            | 
            | 
           60 | 
           case "$1" in
  | 
        
        
            | 
            | 
           61 | 
              *start)
  | 
        
        
            | 
            | 
           62 | 
              	;;
  | 
        
        
            | 
            | 
           63 | 
              *)
  | 
        
        
            | 
            | 
           64 | 
           	echo $"Usage: $0 {start}"
  | 
        
        
            | 
            | 
           65 | 
           	exit 1
  | 
        
        
            | 
            | 
           66 | 
           	;;
  | 
        
        
            | 
            | 
           67 | 
           esac
  | 
        
        
            | 
            | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
           # Kill all processes.
  | 
        
        
            | 
            | 
           70 | 
           [ "${BASH+bash}" = bash ] && enable kill
  | 
        
        
            | 
            | 
           71 | 
              | 
        
        
            | 
            | 
           72 | 
           action $"Sending all processes the TERM signal..." /sbin/killall5 -15
  | 
        
        
            | 
            | 
           73 | 
           sleep 5
  | 
        
        
            | 
            | 
           74 | 
           action $"Sending all processes the KILL signal..."  /sbin/killall5 -9
  | 
        
        
            | 
            | 
           75 | 
              | 
        
        
            | 
            | 
           76 | 
           # Write to wtmp file before unmounting /var
  | 
        
        
            | 
            | 
           77 | 
           /sbin/halt -w
  | 
        
        
            | 
            | 
           78 | 
              | 
        
        
            | 
            | 
           79 | 
           # Save mixer settings, here for lack of a better place.
  | 
        
        
            | 
            | 
           80 | 
           grep -q "\(alsa\)" /proc/devices
  | 
        
        
            | 
            | 
           81 | 
           if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
  | 
        
        
            | 
            | 
           82 | 
              action $"Saving mixer settings" alsactl store
  | 
        
        
            | 
            | 
           83 | 
           fi
  | 
        
        
            | 
            | 
           84 | 
              | 
        
        
            | 
            | 
           85 | 
           # Save random seed
  | 
        
        
            | 
            | 
           86 | 
           touch /var/lib/random-seed
  | 
        
        
            | 
            | 
           87 | 
           chmod 600 /var/lib/random-seed
  | 
        
        
            | 
            | 
           88 | 
           action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
  | 
        
        
            | 
            | 
           89 | 
              | 
        
        
            | 
            | 
           90 | 
           # Sync the system clock.
  | 
        
        
            | 
            | 
           91 | 
           ARC=0
  | 
        
        
            | 
            | 
           92 | 
           SRM=0
  | 
        
        
            | 
            | 
           93 | 
           UTC=0
  | 
        
        
            | 
            | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
           if [ -f /etc/sysconfig/clock ]; then
  | 
        
        
            | 
            | 
           96 | 
              . /etc/sysconfig/clock
  | 
        
        
            | 
            | 
           97 | 
              | 
        
        
            | 
            | 
           98 | 
              # convert old style clock config to new values
  | 
        
        
            | 
            | 
           99 | 
              if [ "${CLOCKMODE}" = "GMT" ]; then
  | 
        
        
            | 
            | 
           100 | 
                 UTC=true
  | 
        
        
            | 
            | 
           101 | 
              elif [ "${CLOCKMODE}" = "ARC" ]; then
  | 
        
        
            | 
            | 
           102 | 
                 ARC=true
  | 
        
        
            | 
            | 
           103 | 
              fi
  | 
        
        
            | 
            | 
           104 | 
           fi
  | 
        
        
            | 
            | 
           105 | 
              | 
        
        
            | 
            | 
           106 | 
           CLOCKDEF=""
  | 
        
        
            | 
            | 
           107 | 
           CLOCKFLAGS="$CLOCKFLAGS --systohc"
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
           case "$UTC" in
  | 
        
        
            | 
            | 
           110 | 
              yes|true)
  | 
        
        
            | 
            | 
           111 | 
           	CLOCKFLAGS="$CLOCKFLAGS -u";
  | 
        
        
            | 
            | 
           112 | 
           	CLOCKDEF="$CLOCKDEF (utc)";
  | 
        
        
            | 
            | 
           113 | 
           	;;
  | 
        
        
            | 
            | 
           114 | 
              no|false)
  | 
        
        
            | 
            | 
           115 | 
           	CLOCKFLAGS="$CLOCKFLAGS --localtime";
  | 
        
        
            | 
            | 
           116 | 
           	CLOCKDEF="$CLOCKDEF (localtime)";
  | 
        
        
            | 
            | 
           117 | 
           	;;
  | 
        
        
            | 
            | 
           118 | 
           esac
  | 
        
        
            | 
            | 
           119 | 
              | 
        
        
            | 
            | 
           120 | 
           case "$ARC" in
  | 
        
        
            | 
            | 
           121 | 
              yes|true)
  | 
        
        
            | 
            | 
           122 | 
           	CLOCKFLAGS="$CLOCKFLAGS -A";
  | 
        
        
            | 
            | 
           123 | 
           	CLOCKDEF="$CLOCKDEF (arc)";
  | 
        
        
            | 
            | 
           124 | 
           	;;
  | 
        
        
            | 
            | 
           125 | 
           esac
  | 
        
        
            | 
            | 
           126 | 
           case "$SRM" in
  | 
        
        
            | 
            | 
           127 | 
              yes|true)
  | 
        
        
            | 
            | 
           128 | 
           	CLOCKFLAGS="$CLOCKFLAGS -S";
  | 
        
        
            | 
            | 
           129 | 
           	CLOCKDEF="$CLOCKDEF (srm)";
  | 
        
        
            | 
            | 
           130 | 
           	;;
  | 
        
        
            | 
            | 
           131 | 
           esac
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
           | 207 | 
           beyerleu | 
           133 | 
           # [ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
  | 
        
        
           | 1 | 
           beyerle@PS | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
           # Try to unmount tmpfs filesystems to avoid swapping them in.  Ignore failures.
  | 
        
        
            | 
            | 
           136 | 
           tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
  | 
        
        
            | 
            | 
           137 | 
           	     $3 == "tmpfs" { print $2; }' /proc/mounts | sort -r)
  | 
        
        
           | 206 | 
           beyerleu | 
           138 | 
           [ -n "$tmpfs" ] && fstab-decode $UMOUNT $tmpfs 2>/dev/null
  | 
        
        
           | 1 | 
           beyerle@PS | 
           139 | 
              | 
        
        
            | 
            | 
           140 | 
           # Turn off swap, then unmount file systems.
  | 
        
        
            | 
            | 
           141 | 
           [ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
  | 
        
        
            | 
            | 
           142 | 
           if [ -n "$SWAPS" ]; then
  | 
        
        
            | 
            | 
           143 | 
               action $"Turning off swap: " swapoff $SWAPS
  | 
        
        
            | 
            | 
           144 | 
               for dst in $SWAPS; do
  | 
        
        
            | 
            | 
           145 | 
           	if [[ "$dst" =~ "^/dev/mapper" ]] \
  | 
        
        
            | 
            | 
           146 | 
           	    && [ "$(dmsetup status "$dst" | cut -d ' ' -f 3)" = crypt ]; then
  | 
        
        
            | 
            | 
           147 | 
           	    backdev=$(/sbin/cryptsetup status "$dst" \
  | 
        
        
            | 
            | 
           148 | 
           		| awk '$1 == "device:" { print $2 }')
  | 
        
        
            | 
            | 
           149 | 
           	    /sbin/cryptsetup remove "$dst"
  | 
        
        
            | 
            | 
           150 | 
           	fi
  | 
        
        
            | 
            | 
           151 | 
               done
  | 
        
        
            | 
            | 
           152 | 
           fi
  | 
        
        
            | 
            | 
           153 | 
              | 
        
        
            | 
            | 
           154 | 
           [ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
  | 
        
        
            | 
            | 
           155 | 
              | 
        
        
            | 
            | 
           156 | 
           # Unmount file systems, killing processes if we have to.
  | 
        
        
            | 
            | 
           157 | 
           # Unmount loopback stuff first
  | 
        
        
           | 206 | 
           beyerleu | 
           158 | 
           #__umount_loopback_loop
  | 
        
        
           | 1 | 
           beyerle@PS | 
           159 | 
              | 
        
        
            | 
            | 
           160 | 
           # Unmount RPC pipe file systems
  | 
        
        
           | 206 | 
           beyerleu | 
           161 | 
           #__umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
  | 
        
        
           | 1 | 
           beyerle@PS | 
           162 | 
           #    /proc/mounts \
  | 
        
        
            | 
            | 
           163 | 
           #    $"Unmounting pipe file systems: " \
  | 
        
        
            | 
            | 
           164 | 
           #    $"Unmounting pipe file systems (retry): " \
  | 
        
        
            | 
            | 
           165 | 
           #    -f
  | 
        
        
            | 
            | 
           166 | 
              | 
        
        
           | 206 | 
           beyerleu | 
           167 | 
           #LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
  | 
        
        
           | 1 | 
           beyerle@PS | 
           168 | 
           #	$3 == "tmpfs" || $3 == "proc" {print $2 ; next}
  | 
        
        
           | 112 | 
           beyerle@PS | 
           169 | 
           #	/(loopfs|autofs|nfs|cifs|smbfs|ncpfs|sysfs|^none|^\/dev\/ram|^\/dev\/root$)/ {next}
  | 
        
        
           | 1 | 
           beyerle@PS | 
           170 | 
           #	{print $2}' /proc/mounts \
  | 
        
        
            | 
            | 
           171 | 
           #	$"Unmounting file systems: " \
  | 
        
        
            | 
            | 
           172 | 
           #	$"Unmounting file systems (retry): " \
  | 
        
        
            | 
            | 
           173 | 
           #	-f
  | 
        
        
            | 
            | 
           174 | 
              | 
        
        
           | 206 | 
           beyerleu | 
           175 | 
           [ -f /proc/bus/usb/devices ] && $UMOUNT /proc/bus/usb
  | 
        
        
           | 1 | 
           beyerle@PS | 
           176 | 
              | 
        
        
            | 
            | 
           177 | 
           [ -f /etc/crypttab ] && \
  | 
        
        
            | 
            | 
           178 | 
               LANG=C action $"Stopping disk encryption: " halt_crypto
  | 
        
        
            | 
            | 
           179 | 
              | 
        
        
            | 
            | 
           180 | 
           # remove the crash indicator flag
  | 
        
        
            | 
            | 
           181 | 
           rm -f /.autofsck
  | 
        
        
            | 
            | 
           182 | 
              | 
        
        
            | 
            | 
           183 | 
           # Try all file systems other than root, essential filesystems and RAM disks,
  | 
        
        
            | 
            | 
           184 | 
           # one last time.
  | 
        
        
            | 
            | 
           185 | 
           awk '$2 !~ /\/(|dev|proc|selinux)$/ && $1 !~ /^\/dev\/ram/ { print $2 }' \
  | 
        
        
            | 
            | 
           186 | 
               /proc/mounts | grep -v "/livecd/" | sort -r | \
  | 
        
        
            | 
            | 
           187 | 
             while read line; do
  | 
        
        
           | 206 | 
           beyerleu | 
           188 | 
               fstab-decode $UMOUNT -f $line
  | 
        
        
           | 1 | 
           beyerle@PS | 
           189 | 
           done
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
           if [ -x /sbin/halt.local ]; then
  | 
        
        
            | 
            | 
           192 | 
              /sbin/halt.local
  | 
        
        
            | 
            | 
           193 | 
           fi
  | 
        
        
            | 
            | 
           194 | 
              | 
        
        
            | 
            | 
           195 | 
           # Remount read only anything that's left mounted.
  | 
        
        
            | 
            | 
           196 | 
           # echo $"Remounting remaining filesystems readonly"
  | 
        
        
            | 
            | 
           197 | 
           mount | awk '{ print $3 }' | while read line; do
  | 
        
        
            | 
            | 
           198 | 
               fstab-decode mount -n -o ro,remount $line
  | 
        
        
            | 
            | 
           199 | 
           done
  | 
        
        
            | 
            | 
           200 | 
              | 
        
        
            | 
            | 
           201 | 
           # Now halt or reboot.
  | 
        
        
            | 
            | 
           202 | 
           echo $"$message"
  | 
        
        
            | 
            | 
           203 | 
           if [ -f /fastboot ]; then
  | 
        
        
            | 
            | 
           204 | 
            echo $"On the next boot fsck will be skipped."
  | 
        
        
            | 
            | 
           205 | 
           elif [ -f /forcefsck ]; then
  | 
        
        
            | 
            | 
           206 | 
            echo $"On the next boot fsck will be forced."
  | 
        
        
            | 
            | 
           207 | 
           fi
  | 
        
        
            | 
            | 
           208 | 
              | 
        
        
            | 
            | 
           209 | 
           if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
  | 
        
        
            | 
            | 
           210 | 
           	. /etc/sysconfig/ups
  | 
        
        
            | 
            | 
           211 | 
           	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
  | 
        
        
            | 
            | 
           212 | 
           		/sbin/upsdrvctl shutdown
  | 
        
        
            | 
            | 
           213 | 
           	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
  | 
        
        
            | 
            | 
           214 | 
           		$MODEL $OPTIONS_HALT -k $DEVICE
  | 
        
        
            | 
            | 
           215 | 
           	fi
  | 
        
        
            | 
            | 
           216 | 
           fi
  | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
           # ------------------ LiveCD -------------------------
  | 
        
        
            | 
            | 
           219 | 
              | 
        
        
           | 164 | 
           beyerle@PS | 
           220 | 
           # dir of mounted live system: /$MOUNTDIR/live
  | 
        
        
            | 
            | 
           221 | 
           MOUNTDIR=livecd
  | 
        
        
            | 
            | 
           222 | 
              | 
        
        
            | 
            | 
           223 | 
           # source functions of liblinuxlive
  | 
        
        
            | 
            | 
           224 | 
           . /$MOUNTDIR/live/liblinuxlive
  | 
        
        
            | 
            | 
           225 | 
              | 
        
        
            | 
            | 
           226 | 
           # root on NFS?
  | 
        
        
            | 
            | 
           227 | 
           NFSROOT=$( cmdline_value nfsroot )
  | 
        
        
            | 
            | 
           228 | 
              | 
        
        
            | 
            | 
           229 | 
           # noeject set?
  | 
        
        
            | 
            | 
           230 | 
           NOEJECT=$( cmdline_parameter noeject )
  | 
        
        
            | 
            | 
           231 | 
              | 
        
        
            | 
            | 
           232 | 
           # eject CDROM 
  | 
        
        
            | 
            | 
           233 | 
           # if CDROM is not on NFS and if noeject is not set
  | 
        
        
            | 
            | 
           234 | 
           if [ ! $NFSROOT ] && [ ! $NOEJECT ]; then
  | 
        
        
           | 168 | 
           beyerle@PS | 
           235 | 
               CDROM_DEV=$( grep /$MOUNTDIR/live/livecd /proc/mounts | awk '{print $1}' )
  | 
        
        
            | 
            | 
           236 | 
               echo -n "Ejecting CD-ROM $CDROM_DEV ... "
  | 
        
        
            | 
            | 
           237 | 
               eject $CDROM_DEV
  | 
        
        
           | 1 | 
           beyerle@PS | 
           238 | 
               echo
  | 
        
        
            | 
            | 
           239 | 
           fi
  | 
        
        
            | 
            | 
           240 | 
              | 
        
        
            | 
            | 
           241 | 
           if [ "${command##*/}" = "reboot" ]; then
  | 
        
        
            | 
            | 
           242 | 
             echo "Rebooting."; sleep 1
  | 
        
        
            | 
            | 
           243 | 
             /livecd/live/bin/busybox reboot 2>/dev/null
  | 
        
        
            | 
            | 
           244 | 
             reboot
  | 
        
        
            | 
            | 
           245 | 
           else
  | 
        
        
            | 
            | 
           246 | 
             echo "Poweroff."; sleep 1  
  | 
        
        
            | 
            | 
           247 | 
             /livecd/live/bin/busybox poweroff 2>/dev/null
  | 
        
        
            | 
            | 
           248 | 
             poweroff
  | 
        
        
            | 
            | 
           249 | 
           fi
  | 
        
        
            | 
            | 
           250 | 
              | 
        
        
            | 
            | 
           251 | 
           # ------------------ LiveCD -------------------------
  | 
        
        
            | 
            | 
           252 | 
              | 
        
        
            | 
            | 
           253 | 
           # First, try kexec. If that fails, fall back to rebooting the old way.
  | 
        
        
           | 112 | 
           beyerle@PS | 
           254 | 
           [ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
  | 
        
        
           | 1 | 
           beyerle@PS | 
           255 | 
              | 
        
        
            | 
            | 
           256 | 
           HALTARGS="-d"
  | 
        
        
            | 
            | 
           257 | 
           [ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
  | 
        
        
            | 
            | 
           258 | 
              | 
        
        
            | 
            | 
           259 | 
           exec $command $HALTARGS
  |