From 367ac227f42ca9c8a7c050da0bcc04248fae29b1 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 28 Sep 2012 13:54:10 -0400 Subject: commit to some level of style in variable naming This is an ugly patch, and probably does more than I'd like it to. The idea is that mkinitcpio adopts some sort of consistent style which I'm actually happy with. I define 3 kinds of variables: 1) local variables: all lower case, and scoped within functions. Use freely, as they're well contained. 2) global variables: these are known to mkinitcpio internally, but are global in scope. They mainly carry runtime configuration and collected data during the image generation process. These are always lower case, but carry a leading underscore to denote that they're global. 3) "API" variables: also global in scope, but exist "outside" of mkinitcpio -- either drawn in from the configuration file, or "exported" to the install hooks. These are always all upper case. When introducing new variables, extreme care must be taken to pick names that will not conflict with the environment inherited by mkinitcpio. A HACKING file is introduced with a similar description of the above, and more. Signed-off-by: Dave Reisner --- install/autodetect | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'install') diff --git a/install/autodetect b/install/autodetect index c0c7563..4f1e4bb 100644 --- a/install/autodetect +++ b/install/autodetect @@ -3,17 +3,17 @@ build() { local -a md_devs - MODULE_FILE=$workdir/autodetect_modules + _f_autodetect_cache=$_d_workdir/autodetect_modules add_if_avail() { local resolved # treat this as an alias, since ext3 might be aliased to ext4. IFS=$'\n' read -rd '' -a resolved < \ - <(modprobe -d "$MODULEROOT" -S "$KERNELVERSION" -R "$1" 2>/dev/null) + <(modprobe -d "$_optmoduleroot" -S "$KERNELVERSION" -R "$1" 2>/dev/null) if (( ${#resolved[*]} )); then - printf '%s\n' "${resolved[@]}" >>"$MODULE_FILE" + printf '%s\n' "${resolved[@]}" >>"$_f_autodetect_cache" fi } @@ -22,7 +22,7 @@ build() { return 1 fi - auto_modules >"$MODULE_FILE" + auto_modules >"$_f_autodetect_cache" # detect filesystem for root if rootfstype=$(findmnt -uno fstype '/'); then @@ -40,12 +40,13 @@ build() { # scan for md raid devices md_devs=(/sys/class/block/md*/md/level) if [[ -e $md_devs ]]; then - (( !QUIET )) && plain "found %d mdadm arrays to scan" "${#md_devs[*]}" - awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}" | sort -u >>"$MODULE_FILE" + quiet "found %d mdadm arrays to scan" "${#md_devs[*]}" + awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}" | + sort -u >>"$_f_autodetect_cache" fi - if (( !QUIET )) && [[ -s $MODULE_FILE ]]; then - plain "caching %d modules" $(wc -l < "$MODULE_FILE") + if [[ -s $_f_autodetect_cache ]]; then + quiet "caching %d modules" $(wc -l < "$_f_autodetect_cache") fi } -- cgit v1.2.3-24-g4f1b