Split out reading /etc/crypttab and procssing the individual lines into
their own helper functions, and bashify the resulting shorter code.
Processing this file is still ugly, though. :(
---
functions | 43 +--
rc.shutdown | 36 +
rc.sysinit | 131 ++
3 files changed, 90 insertions(+), 120 deletions(-)
diff --git a/functions b/functions
index bf6ed45..9ec8b5e 100644
--- a/functions
+++ b/functions
@@ -232,6 +232,40 @@ kill_everything() {
run_hook single_postkillall
}
+activate_vgs() {
+[[ $USELVM =~ yes|YES -x /sbin/lvm -d /sys/block ]] || return
+# Kernel 2.6.x, LVM2 groups
+/sbin/modprobe -q dm-mod 2/dev/null
+stat_busy Activating LVM2 groups
+if /sbin/lvm vgchange --ignorelockingfailure -a y /dev/null; then
+ stat_done
+else
+ stat_fail
+ fi
+}
+
+# Arch cryptsetup packages traditionally contained the binaries
+# /usr/sbin/cryptsetup
+# /sbin/cryptsetup.static
+# 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
+for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
+/sbin/cryptsetup.static ''; do
+[[ -x $CS ]] break
+done
+
+read_crypttab() {
+# $1 = function to call with the split out line from the crypttab
+local line nspo failed=0
+while read line; do
+[[ $line ${line:0:1} != '#' ]] || continue
+eval nspo=(${line%#*})
+$1 ${ns...@]} || failed=1
+done /etc/crypttab
+return $failed
+}
+
###
# Custom hooks in initscripts #
###
@@ -278,7 +312,7 @@ run_hook() {
[[ $1 ]] || return 1
local func
for func in ${hook_funcs[$1]}; do
- ${func}
+ q${func}
done
}
@@ -293,13 +327,14 @@ set_consolefont() {
for i in /dev/tty[0-9]*; do
/usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \
$CONSOLEFONT -C ${i} /dev/null 21
-done
+ done
if (($? != 0)); then
stat_fail
elif [[ $CONSOLEMAP ]]; then
cat EOF /etc/profile.d/locale.sh
-if [ $CONSOLE = -a $TERM = linux -a -t 1 ]; then printf \033(K; fi
-
+if [ $CONSOLE = -a $TERM = linux -a -t 1 ]
+then printf \033(K
+fi
EOF
stat_done
fi
diff --git a/rc.shutdown b/rc.shutdown
index e823ed2..1081970 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -65,33 +65,17 @@ stat_busy Unmounting Filesystems
stat_done
# Kill non-root encrypted partition mappings
-if [[ -f /etc/crypttab ]]; then
+if [[ -f /etc/crypttab $CS ]]; then
stat_busy Deactivating encrypted volumes:
- # Arch cryptsetup packages traditionally contained the binaries
- # /usr/sbin/cryptsetup
- # /sbin/cryptsetup.static
- # 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
- 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
- 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 21; then
- stat_append ok
- else
- stat_append failed
- fi
- done /etc/crypttab
- fi
+ do_lock() {
+stat_append ${1}..
+if $CS remove $1 /dev/null 21; then
+stat_append ok
+ else
+stat_append failed
+ fi
+}
+read_crypttab do_lock
stat_done
fi
diff --git a/rc.sysinit b/rc.sysinit
index 404e11a..d54b9bb 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -127,104 +127,55 @@ if [[ -f /etc/mdadm.conf ]] /bin/grep -q ^ARRAY
/etc/mdadm.conf; then
status Activating RAID arrays /sbin/mdadm --assemble --scan
fi
-if [ $USELVM = yes -o $USELVM = YES ]; then
- if [ -x /sbin/lvm -a -d /sys/block ]; then
- # Kernel 2.6.x, LVM2 groups
- /sbin/modprobe -q dm-mod 2/dev/null
- stat_busy Activating LVM2 groups
- /sbin/lvm vgchange --ignorelockingfailure -a y /dev/null
- if [ $? -ne 0 ]; then
- stat_fail
- else
- stat_done
- fi
- fi
-fi
+activate_vgs
# Set up non-root encrypted partition mappings
-if [ -f /etc/crypttab -a -n $(/bin/grep -v ^# /etc/crypttab | /bin/grep -v
^$) ]; then
- /sbin/modprobe -q dm-mod