aboutsummaryrefslogtreecommitdiff
path: root/rc.shutdown
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2010-06-07 11:14:09 -0500
committerVictor Lowther <victor.lowther@gmail.com>2010-07-11 20:23:46 -0500
commit24c494db1ef64a818ebb072b59d19bb3217991a9 (patch)
treee24d381de169e61239db8e5e6ae2752add5eb0df /rc.shutdown
parent9390083d675e1fd5059ab35d9977bf84b7d87ba2 (diff)
downloadinitscripts-24c494db1ef64a818ebb072b59d19bb3217991a9.tar.xz
Bashify rc.shutdown
Shorten domainname conditional execution. Use parameter expansion instead of dirname. Clean up entropy pool saving and system clock saving. Flatten LVM deactivation if block
Diffstat (limited to 'rc.shutdown')
-rwxr-xr-xrc.shutdown87
1 files changed, 37 insertions, 50 deletions
diff --git a/rc.shutdown b/rc.shutdown
index d540364..07061e8 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -16,21 +16,19 @@ printhl "Initiating Shutdown..."
echo " "
# avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
-if [ -x /bin/domainname ]; then
- /bin/domainname ""
-fi
+[[ -x /bin/domainname ]] && /bin/domainname ""
[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
kill_everything shutdown
stat_busy "Saving Random Seed"
RANDOM_SEED=/var/lib/misc/random-seed
-[ -d $(dirname $RANDOM_SEED) ] || mkdir -p $(dirname $RANDOM_SEED)
+[[ -d ${RANDOM_SEED%/*} ]] || mkdir -p ${RANDOM_SEED%/*}
: > $RANDOM_SEED
/bin/chmod 0600 $RANDOM_SEED
POOL_FILE=/proc/sys/kernel/random/poolsize
-if [ -r $POOL_FILE ]; then
- POOL_SIZE=$(/bin/cat $POOL_FILE)
+if [[ -r $POOL_FILE ]]; then
+ read POOL_SIZE <$POOL_FILE
else
POOL_SIZE=512
fi
@@ -38,22 +36,18 @@ fi
stat_done
stat_busy "Saving System Clock"
-if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
+if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then
/bin/rm -f /etc/localtime
/bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
HWCLOCK_PARAMS="--systohc"
-if [ "$HARDWARECLOCK" = "UTC" ]; then
- HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
-elif [ "$HARDWARECLOCK" = "localtime" ]; then
- HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
-else
- HWCLOCK_PARAMS=""
-fi
-if [ -n "$HWCLOCK_PARAMS" ]; then
- /sbin/hwclock $HWCLOCK_PARAMS
-fi
+case $HARDWARECLOCK in
+ UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";;
+ localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";;
+ *) HWCLOCK_PARAMS="";;
+esac
+[[ $HWCLOCK_PARAMS ]] && /sbin/hwclock $HWCLOCK_PARAMS
stat_done
# removing psmouse module to fix some reboot issues on newer laptops
@@ -71,7 +65,7 @@ stat_busy "Unmounting Filesystems"
stat_done
# Kill non-root encrypted partition mappings
-if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then
+if [[ -f /etc/crypttab ]]; then
stat_busy "Deactivating encrypted volumes:"
# Arch cryptsetup packages traditionally contained the binaries
# /usr/sbin/cryptsetup
@@ -79,38 +73,32 @@ if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)"
# By default, initscripts used the /sbin/cryptsetup.static.
# Newer packages will only have /sbin/cryptsetup and no static binary
# This ensures maximal compatibility with the old and new layout
- if [ -x /sbin/cryptsetup ]; then
- CS=/sbin/cryptsetup
- elif [ -x /usr/sbin/cryptsetup ]; then
- CS=/usr/sbin/cryptsetup
+ for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
+ /sbin/cryptsetup.static ''; do
+ [[ -x $CS ]] && break
+ done
+ if [[ ! $CS ]]; then
+ stat_append " Failed, unable to find cryptsetup."
+ stat_fail
else
- CS=/sbin/cryptsetup.static
- fi
- do_uncrypt() {
- if [ $# -ge 3 ]; then
- if [ -b /dev/mapper/$1 ] ;then
- stat_append "${1}.."
- $CS remove $1 >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- stat_append "failed "
- else
- stat_append "ok "
- fi
- fi
+ while read name src passwd opts; do
+ [[ ! $name || ${name:0:1} = '#']] && continue
+ [[ -b /dev/mapper/$name ]] || continue
+ stat_append "${1}.."
+ if "$CS" remove "$name" >/dev/null 2>&1; then
+ stat_append "ok "
+ else
+ stat_append "failed "
fi
- }
- while read line; do
- eval do_uncrypt "$line"
- done </etc/crypttab
- stat_done
+ done </etc/crypttab
+ fi
+ stat_done
fi
-if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
- if [ -x /sbin/lvm -a -d /sys/block ]; then
- stat_busy "Deactivating LVM2 groups"
- /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1
- stat_done
- fi
+if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then
+ stat_busy "Deactivating LVM2 groups"
+ /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1
+ stat_done
fi
stat_busy "Remounting Root Filesystem Read-only"
@@ -120,15 +108,14 @@ stat_done
run_hook shutdown_poweroff
# Power off or reboot
-if [ "$RUNLEVEL" = "0" ]; then
- printsep
+printsep
+if [[ $RUNLEVEL = 0 ]]; then
printhl "${C_H2}POWER OFF"
/sbin/poweroff -d -f -h -i
else
- printsep
printhl "${C_H2}REBOOTING"
# if kexec is installed and a kernel is loaded, use it
- [ -x /sbin/kexec ] && /sbin/kexec -e > /dev/null 2>&1
+ [[ -x /sbin/kexec ]] && /sbin/kexec -e > /dev/null 2>&1
/sbin/reboot -d -f -i
fi