From 40a7d4b61a8d0fa89f16337672b9f8aa1c31cc54 Mon Sep 17 00:00:00 2001 From: Roman Macko Date: Fri, 31 Jul 2009 16:31:25 -0700 Subject: [PATCH] Address depmod version differences for depmod.d/demod.conf http://www.intellinuxwireless.org/bugzilla/show_bug.cgi?id=2061#c6 This adds support for the different demod version out there. This explanation is taken from the thread which added the patch: Assume depmod is run without -C or --config option depmod version 3.6 reads firstly /etc/depmod.conf file and then it reads config files in directory /etc/depmod.d. Files in directory /etc/depmod.d are read and parsed in unpredictable order by readdir function (this function uses raw directory structures of filesystem) depmod version 3.10 reads /etc/depmod.conf firstly as well, but this config file is considered as deprecated in this version and prints out warning about that. Then it reads config files in directory /etc/depmod.d by readdir function as well, but before it starts to parse them, it sorts them accord to filename, so you know the order in which they are going to be parsed and this is very improtant!!! This behavior should be from version 3.7 The same for both versions: 1) List of directories to be searched is created from search commands from all config files in order how particular search commands are found in config files (so order of parsed config files is important). If no search command is found, updates directory is added before "built-in" directory. 2) As for override command, the last one found for particular module and kernel in all config files wins, so again the order of parsed config files is important. From this is evident, that both versions can work differently which depends on the order of parsed config files from /etc/depmod.d directory that is different in both versions. Signed-off-by: Roman Macko --- scripts/check_depmod | 73 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/scripts/check_depmod b/scripts/check_depmod index 212bb6e61b9f..f127a6a6676c 100755 --- a/scripts/check_depmod +++ b/scripts/check_depmod @@ -7,50 +7,77 @@ # Seems Mandriva has an $DEPMOD_DIR but it doesn't have any files, # so lets deal with those distributions. DEPMOD_CONF="/etc/depmod.conf" +DEPMOD_CONF_TMP="$DEPMOD_CONF.compat-wireless.old" DEPMOD_DIR="/etc/depmod.d/" COMPAT_DEPMOD_FILE=compat-wireless.conf +GREP_REGEX_UPDATES="^[[:space:]]*search.*[[:space:]]updates\([[:space:]]\|$\)" +GREP_REGEX_SEARCH="^[[:space:]]*search[[:space:]].\+$" +DEPMOD_CMD="depmod" function add_compat_depmod_conf { echo "NOTE: Your distribution lacks an $DEPMOD_DIR directory with " - echo "updates/ directory being prioritized for mouldes, we're adding " + echo "updates/ directory being prioritized for modules, we're adding " echo "one for you." mkdir -p $DEPMOD_DIR - echo "search updates extra built-in" > $DEPMOD_DIR/$COMPAT_DEPMOD_FILE + FIRST_FILE=$(ls $DEPMOD_DIR|head -1) + [ -n "$FIRST_FILE" ] && while [[ $FIRST_FILE < $COMPAT_DEPMOD_FILE ]]; do + COMPAT_DEPMOD_FILE="0$COMPAT_DEPMOD_FILE" + done + echo "search updates" > $DEPMOD_DIR/$COMPAT_DEPMOD_FILE } -function depmod_updates_ok { - echo "depmod will prefer updates/ over kernel/ -- OK!" +function add_global_depmod_conf { + echo "NOTE: Your distribution lacks updates/ directory being" + echo "prioritized for modules, we're adding it to $DEPMOD_CONF." + rm -f $DEPMOD_CONF_TMP + [ -f $DEPMOD_CONF ] && cp -f $DEPMOD_CONF $DEPMOD_CONF_TMP + echo "search updates" > $DEPMOD_CONF + [ -f $DEPMOD_CONF_TMP ] && cat $DEPMOD_CONF_TMP >> $DEPMOD_CONF } -function check_depmod_conf { - if [ -f $DEPMOD_CONF ]; then - grep -q updates $DEPMOD_CONF - return $? - fi - return 1 +function depmod_updates_ok { + echo "depmod will prefer updates/ over kernel/ -- OK!" } -function add_depmod_conf_if_missing { - check_depmod_conf - if [[ $? -ne 0 ]]; then - add_compat_depmod_conf +function add_depmod_conf { + if [ -f "$DEPMOD_CONF" ]; then + add_global_depmod_conf else - depmod_updates_ok + DEPMOD_VERSION=$($DEPMOD_CMD --version | cut -d" " -f2 | sed "s/\.//") + if [[ $DEPMOD_VERSION -gt 36 ]]; then + add_compat_depmod_conf + else + add_global_depmod_conf + fi fi } +# ============================================================================= +# === MAIN ==================================================================== +# ============================================================================= + +GREP_FILES="" +[ -f $DEPMOD_CONF ] && GREP_FILES="$DEPMOD_CONF" if [ -d $DEPMOD_DIR ]; then DEPMOD_FILE_COUNT=$(ls $DEPMOD_DIR | wc -l) - if [[ $DEPMOD_FILE_COUNT -eq 0 ]]; then - add_depmod_conf_if_missing - else - grep -q updates $DEPMOD_DIR/* - if [[ $? -ne 0 ]]; then - add_depmod_conf_if_missing - else + [[ $DEPMOD_FILE_COUNT -gt 0 ]] && GREP_FILES="$GREP_FILES $DEPMOD_DIR/*" +fi + +if [ -n "$GREP_FILES" ]; then + grep -q "$GREP_REGEX_SEARCH" $GREP_FILES + if [[ $? -eq 0 ]]; then + grep -q "$GREP_REGEX_UPDATES" $GREP_FILES + if [[ $? -eq 0 ]]; then depmod_updates_ok + else + add_depmod_conf fi + else + depmod_updates_ok fi else - add_depmod_conf_if_missing + depmod_updates_ok fi + +exit 0 + -- 2.30.2