[arch-projects] [initscripts][PATCH] Add is_true and is_false functions
Allan McRae
allan at archlinux.org
Tue Jun 12 11:20:10 EDT 2012
Signed-off-by: Allan McRae <allan at archlinux.org>
---
This work is based on independent research and any resemblance to other
patches, living or dead, is entirely coincidental.
functions | 9 ++++++---
rc.shutdown | 6 +++---
rc.sysinit | 6 +++---
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/functions b/functions
index 4a8ba7b..b87854f 100644
--- a/functions
+++ b/functions
@@ -19,6 +19,9 @@ if [[ $1 == "start" ]]; then
fi
fi
+is_true() { [[ ${1^^} = @(TRUE|YES|1) ]]; }
+is_false() { [[ ${1,,} = @(false|no|0) ]]; }
+
# width:
calc_columns () {
STAT_COL=80
@@ -384,7 +387,7 @@ udevd_modprobe() {
}
activate_vgs() {
- [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0
+ is_true "$USELVM" && [[ -x $(type -P lvm) && -d /sys/block ]] || return 0
stat_busy "Activating LVM2 groups"
vgchange --sysinit -a y >/dev/null
(( $? == 0 )) && stat_done || stat_fail
@@ -659,7 +662,7 @@ if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then
declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1
fi
-if [[ $DAEMON_LOCALE = [yY][eE][sS] ]]; then
+if is_true "$DAEMON_LOCALE"; then
export LANG=${LOCALE:-C}
if [[ -r /etc/locale.conf ]]; then
parse_envfile /etc/locale.conf "${localevars[@]}"
@@ -669,7 +672,7 @@ else
fi
# set colors
-if [[ $USECOLOR = [yY][eE][sS] ]]; then
+if is_true "$USECOLOR"; then
if tput setaf 0 &>/dev/null; then
C_CLEAR=$(tput sgr0) # clear text
C_MAIN=${C_CLEAR}$(tput bold) # main text
diff --git a/rc.shutdown b/rc.shutdown
index c708b92..f8d870d 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -27,7 +27,7 @@ status 'Saving Random Seed' /usr/lib/systemd/systemd-random-seed save
halt -w
# stop monitoring of lvm2 groups before unmounting filesystems
-[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
+is_true "$USELVM" && [[ -x $(type -P lvm) ]] &&
status "Deactivating monitoring of LVM2 groups" vgchange --monitor n
# any future uevents can and should be ignored
@@ -58,7 +58,7 @@ if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
stat_busy "Deactivating encrypted volumes:"
# Maybe someone has LVM on an encrypted block device
# executing an extra vgchange is errorless
- [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null
+ is_true "$USELVM" && vgchange --sysinit -a n &>/dev/null
do_lock() {
stat_append "${1}.."
if cryptsetup remove "$1" &>/dev/null; then
@@ -71,7 +71,7 @@ if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
stat_done
fi
-[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
+is_true "$USELVM" && [[ -x $(type -P lvm) ]] &&
status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null
run_hook shutdown_poweroff
diff --git a/rc.sysinit b/rc.sysinit
index 906135c..cb53561 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -77,11 +77,11 @@ status 'Configuring Virtual Consoles' /usr/lib/systemd/systemd-vconsole-setup
status "Bringing up loopback interface" ip link set up dev lo
# FakeRAID devices detection
-[[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]] &&
+is_true "$USEDMRAID" && [[ -x $(type -P dmraid) ]] &&
status "Activating FakeRAID arrays" dmraid -i -ay
# BTRFS devices detection
-[[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]] &&
+is_true "$USEBTRFS" && [[ -x $(type -P btrfs) ]] &&
status "Activating BTRFS volumes" btrfs device scan
# Activate LVM2 groups if any
@@ -121,7 +121,7 @@ status "Mounting Local Filesystems" \
run_hook sysinit_postmount
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw
-[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
+is_true "$USELVM" && [[ -x $(type -P lvm) && -d /sys/block ]] &&
status "Activating monitoring of LVM2 groups" \
vgchange --monitor y >/dev/null
--
1.7.10.4
More information about the arch-projects
mailing list