wl1251: Add support for idle mode
[pandora-wifi.git] / scripts / check_depmod
1 #!/bin/bash
2 # Copyright 2009        Luis R. Rodriguez <mcgrof@gmail.com>
3
4 # Ensures your distribution likes to prefer updates/ over the kernel/
5 # search updates built-in
6
7 # Seems Mandriva has an $DEPMOD_DIR but it doesn't have any files,
8 # so lets deal with those distributions.
9 DEPMOD_CONF="/etc/depmod.conf"
10 DEPMOD_CONF_TMP="$DEPMOD_CONF.compat-wireless.old"
11 DEPMOD_DIR="/etc/depmod.d/"
12 COMPAT_DEPMOD_FILE=compat-wireless.conf
13 GREP_REGEX_UPDATES="^[[:space:]]*search.*[[:space:]]updates\([[:space:]]\|$\)"
14 GREP_REGEX_SEARCH="^[[:space:]]*search[[:space:]].\+$"
15 DEPMOD_CMD="depmod"
16
17 function add_compat_depmod_conf {
18         echo "NOTE: Your distribution lacks an $DEPMOD_DIR directory with "
19         echo "updates/ directory being prioritized for modules, we're adding "
20         echo "one for you."
21         mkdir -p $DEPMOD_DIR
22         FIRST_FILE=$(ls $DEPMOD_DIR|head -1)
23         [ -n "$FIRST_FILE" ] && while [[ $FIRST_FILE < $COMPAT_DEPMOD_FILE ]]; do
24                 COMPAT_DEPMOD_FILE="0$COMPAT_DEPMOD_FILE"
25         done
26         echo "search updates" > $DEPMOD_DIR/$COMPAT_DEPMOD_FILE
27 }
28
29 function add_global_depmod_conf {
30         echo "NOTE: Your distribution lacks updates/ directory being"
31         echo "prioritized for modules, we're adding it to $DEPMOD_CONF."
32         rm -f $DEPMOD_CONF_TMP
33         [ -f $DEPMOD_CONF ] && cp -f $DEPMOD_CONF $DEPMOD_CONF_TMP
34         echo "search updates" > $DEPMOD_CONF
35         [ -f $DEPMOD_CONF_TMP ] && cat $DEPMOD_CONF_TMP >> $DEPMOD_CONF
36 }
37
38 function depmod_updates_ok {
39         echo "depmod will prefer updates/ over kernel/ -- OK!"
40 }
41
42 function add_depmod_conf {
43         if [ -f "$DEPMOD_CONF" ]; then
44                 add_global_depmod_conf
45         else
46                 DEPMOD_VERSION=$($DEPMOD_CMD --version | cut -d" " -f2 | sed "s/\.//")
47                 if [[ $DEPMOD_VERSION -gt 36 ]]; then
48                         add_compat_depmod_conf
49                 else
50                         add_global_depmod_conf
51                 fi
52         fi
53 }
54
55 # =============================================================================
56 # === MAIN ====================================================================
57 # =============================================================================
58
59 GREP_FILES=""
60 [ -f $DEPMOD_CONF ] && GREP_FILES="$DEPMOD_CONF"
61 if [ -d $DEPMOD_DIR ]; then
62         DEPMOD_FILE_COUNT=$(ls $DEPMOD_DIR | wc -l)
63         [[ $DEPMOD_FILE_COUNT -gt 0 ]] && GREP_FILES="$GREP_FILES $DEPMOD_DIR/*"
64 fi
65
66 if [ -n "$GREP_FILES" ]; then
67         grep -q "$GREP_REGEX_SEARCH" $GREP_FILES
68         if [[ $? -eq 0 ]]; then
69                 grep -q "$GREP_REGEX_UPDATES" $GREP_FILES
70                 if [[ $? -eq 0 ]]; then
71                         depmod_updates_ok
72                 else
73                         add_depmod_conf
74                 fi
75         else
76                 depmod_updates_ok
77         fi
78 else
79         depmod_updates_ok
80 fi
81
82 exit 0
83