summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-31 02:15:51 +0100
committerThomas Bächler <thomas@archlinux.org>2011-01-31 21:44:27 +0100
commit65a523302462e738bd3c813bdae4d0a8a62990ac (patch)
treeea5ce01dec8ee033ddb4203cb6d924c98a12af8b
parentb55e66b8c135729d3aa12390848e64532c423b83 (diff)
downloadmkinitcpio-65a523302462e738bd3c813bdae4d0a8a62990ac.tar.gz
mkinitcpio-65a523302462e738bd3c813bdae4d0a8a62990ac.tar.xz
Add new helper functions
Replace common behavior we had in some other places with get_module_name, and add some basename/dirname replacements done in bash to avoid the forks for the number of times we call these functions. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--functions22
1 files changed, 22 insertions, 0 deletions
diff --git a/functions b/functions
index 584fe0d..f2515de 100644
--- a/functions
+++ b/functions
@@ -2,6 +2,28 @@ msg () { [ "${QUIET}" = "n" ] && echo $@; }
err () { echo "ERROR: $@" >&2; }
die () { echo "FATAL: $@" >&2; cleanup; exit 1; }
+get_dirname ()
+{
+ # strip any trailing slash first...
+ local dir="${1%/}"
+ # then get the directory portion
+ echo "${dir%/*}"
+}
+
+get_basename ()
+{
+ echo "${1##*/}"
+}
+
+get_module_name ()
+{
+ #cleanup - remove .ko, replace - with _
+ local modname="${1%.gz}"
+ modname=$(get_basename "${modname%.ko}")
+ modname="${modname//-/_}"
+ echo "$modname"
+}
+
auto_modules ()
{
aliases="$(find /sys/devices/ -name modalias -exec cat {} +)"