From 65a523302462e738bd3c813bdae4d0a8a62990ac Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 30 Jan 2011 19:15:51 -0600 Subject: 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 --- functions | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'functions') 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 {} +)" -- cgit v1.2.3-24-g4f1b