~ubuntu-branches/debian/stretch/dkms/stretch

« back to all changes in this revision

Viewing changes to dkms_autoinstaller

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano, 8510207
  • Date: 2009-12-15 08:57:24 UTC
  • mfrom: (1.1.12 upstream) (7.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091215085724-i177u1akx59x30ou
Tags: 2.1.1.0-2
[8510207] Do not install upstart job file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
 
1
#!/bin/sh
2
2
#
3
 
# dkms_autoinstaller            A service to automatically install DKMS modules
4
 
#                               for new kernels.
 
3
# dkms_autoinstaller        A service to automatically install DKMS modules
 
4
#                           for new kernels.
5
5
# chkconfig: 345 04 04
6
6
# description: An autoinstaller bootup service for DKMS
7
7
#
8
8
### BEGIN INIT INFO
9
 
# Provides: dkms
 
9
# Provides: dkms_autoinstaller dkms
10
10
# Default-Start: 2 3 4 5
11
11
# Default-Stop:
12
12
# Required-Start: $local_fs
15
15
# Description: A service to automatically install DKMS modules for new kernels.
16
16
### END INIT INFO
17
17
 
18
 
#use LSB functions for logging on Debian/Ubuntu
 
18
test -f /usr/sbin/dkms || exit 0
 
19
 
 
20
#We only have these functions on debian/ubuntu
 
21
# so on other distros just stub them out
19
22
if [ -f /lib/lsb/init-functions ]; then
20
23
    . /lib/lsb/init-functions
21
 
    if [ -f /etc/debian_version ]; then
22
 
        DEBIAN_STYLE_LOGGING="yes"
 
24
    if [ ! -f /etc/debian_version ]; then
 
25
        alias log_daemon_msg=echo
 
26
        log_end_msg() { if [ "$1" = "0" ]; then echo " Done. "; else echo " Failed. "; fi }
 
27
        alias log_action_begin_msg=log_daemon_msg
 
28
        alias log_action_end_msg=log_end_msg
23
29
    fi
24
30
fi
25
31
 
26
 
test -f /usr/sbin/dkms || exit 0
27
 
 
28
 
function invoke_command ()
 
32
invoke_command ()
29
33
{
30
34
    local exitval=0
31
35
    local exitval_file=`mktemp /tmp/dkms.XXXXXX`
32
 
    [ -z "$verbose" ] && echo -en "$2..." >>$output_loc || echo -e "$1" >>$output_loc
33
 
    if [ "$3" == background ] && [ -z "$verbose" ]; then
34
 
        (eval $1 >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
35
 
        while [ -e "$exitval_file" ] && ! [ -s "$exitval_file" ]; do
36
 
            sleep 3
37
 
            echo -en "." >>$output_loc
38
 
        done
39
 
        . "$exitval_file"
 
36
    if [ "$3" = background ] && [ -z "$verbose" ]; then
 
37
    (eval $1 >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
 
38
    while [ -e "$exitval_file" ] && ! [ -s "$exitval_file" ]; do
 
39
        sleep 3
 
40
    done
 
41
    . "$exitval_file"
40
42
    else
41
 
        eval $1; exitval=$?
 
43
    eval $1; exitval=$?
42
44
    fi
43
 
    [ $exitval -gt 0 ] && echo -en "(bad exit status: $exitval)" >>$output_loc
 
45
    [ $exitval -gt 0 ] && logger -t dkms_autoinstaller "(bad exit status: $exitval)"
44
46
    rm -f "$exitval_file"
45
 
    echo -en "\n" >>$output_loc
46
47
    return $exitval
47
48
}
48
49
 
 
50
emit_module_status ()
 
51
{
 
52
    #$1 is the signal to emit (successful|failed)
 
53
    #$2 is the module name in question
 
54
    if [ -x /sbin/initctl ]; then
 
55
        initctl emit build-$1 MODULE=$2 2>/dev/null
 
56
    fi
 
57
}
49
58
 
50
59
# Set Variables
51
 
output_loc="/var/log/dkms_autoinstaller"
52
 
[ -n "$2" ] && kernel=$2 && output_loc="/dev/stdout" || kernel=`uname -r`
53
 
kernelver_rpm=`rpm -qf "/lib/modules/$kernel" 2>/dev/null | grep -v "not owned by any package" | grep kernel | head -1`
54
 
if ! arch=`rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null`; then
55
 
    [ `uname -m` == "x86_64" ] && [ `cat /proc/cpuinfo | grep -c "Intel"` -gt 0 ] && [ `ls $install_tree/$kernel/build/configs 2>/dev/null | grep -c "ia32e"` -gt 0 ] && arch="ia32e" || arch=`uname -m`
56
 
fi
 
60
uname=`uname -mr`
 
61
[ -n "$2" ] && kernel=$2 || kernel=${uname% *}
 
62
arch=${uname#* }
57
63
kernel_preparation_done=""
58
64
dkms_tree="/var/lib/dkms"
59
65
. /etc/dkms/framework.conf 2>/dev/null
61
67
# See how we were called.
62
68
case "$1" in
63
69
  start)
64
 
        if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
65
 
            log_daemon_msg "Running DKMS auto installation service for kernel $kernel"
 
70
    log_daemon_msg "Running DKMS auto installation service for kernel $kernel"
 
71
 
 
72
    # Iterate over the modules
 
73
    for modulepath in $(find "$dkms_tree" -maxdepth 1 -mindepth 1 -type d); do
 
74
 
 
75
        module_in_tree=${modulepath##*/}
 
76
        # Determine which versions to show status for
 
77
        do_autoinstall=""
 
78
        version_count=0
 
79
        already_installed=""
 
80
        already_installed_version=""
 
81
        for versioned_path in $(find "$modulepath" -maxdepth 1 -mindepth 1 -type d -a -not -name original_module); do
 
82
            version_count=$(($version_count + 1))
 
83
            version_in_tree="${versioned_path##*/}"
 
84
 
 
85
            if [ -f $versioned_path/source/dkms.conf ]; then
 
86
                do_autoinstall=$(sed -n -e 's/^\(str  *\)\?AUTOINSTALL=\(.*\)$/\2/gp;'  $versioned_path/source/dkms.conf)
 
87
            else
 
88
                current_state="broken"
 
89
                continue
 
90
            fi
 
91
 
 
92
            # Get the current state
 
93
            # a mod can be both built and installed-weak (stupid, but could be)
 
94
            # but installed-weak comes last, so use tail
 
95
            current_state=`dkms status -m $module_in_tree -v $version_in_tree -k $kernel -a $arch 2>/dev/null | awk {'print $5'} | tail -n 1`
 
96
            [ "$current_state" = "installed" -o "$current_state" = "installed-weak" ] && already_installed="true" && already_installed_version=$version_in_tree
 
97
        done
 
98
 
 
99
        log_action_begin_msg " $module_in_tree ($version_in_tree)"
 
100
 
 
101
        # Based on what we know, either do it or not
 
102
        if [ "$current_state" = "broken" ]; then
 
103
            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): Unable to locate $versioned_path/source/dkms.conf"
 
104
            logger -t dkms_autoinstaller " DKMS tree must be manually fixed"
 
105
            log_action_end_msg 1
 
106
            continue
 
107
        elif [ -n "$already_installed" ]; then
 
108
            emit_module_status successful $module_in_tree
 
109
            log_action_end_msg 0
 
110
        elif [ -z "$do_autoinstall" ]; then
 
111
            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): AUTOINSTALL not set in its dkms.conf."
 
112
            log_action_end_msg 0
 
113
        elif [ -n "$do_autoinstall" ] && [ "$version_count" -gt 1 ]; then
 
114
            logger -t dkms_autoinstaller "$module_in_tree: Multiple versions in DKMS. Unsure what to do. Resolve manually."
 
115
            emit_module_status failed $module_in_tree
 
116
            log_action_end_msg 1
66
117
        else
67
 
            echo "Running DKMS auto installation service for kernel $kernel"
68
 
        fi
69
 
        echo "" >>$output_loc
70
 
 
71
 
        for filename in `ls "$dkms_tree"`; do
72
 
            if [ -d "$dkms_tree/$filename" ] && ! [ -h "$dkms_tree/$filename" ]; then
73
 
                modules_needing_status="$modules_needing_status $filename"
74
 
            fi
75
 
        done
76
 
 
77
 
        # Iterate over the modules
78
 
        for module_in_tree in $modules_needing_status; do
79
 
 
80
 
            # Make sure its in the tree
81
 
            if [ -d "$dkms_tree/$module_in_tree" ]; then
82
 
 
83
 
                # Determine which versions to show status for
84
 
                do_autoinstall=""
85
 
                version_count=0
86
 
                already_installed=""
87
 
                already_installed_version=""
88
 
                for filename in `ls "$dkms_tree/$module_in_tree"`; do
89
 
                    if [ -d "$dkms_tree/$module_in_tree/$filename" ] && ! [ -h "$dkms_tree/$module_in_tree/$filename" ] && [ "$filename" != "original_module" ]; then
90
 
                        version_count=$(($version_count + 1))
91
 
                        version_in_tree="$filename"
92
 
 
93
 
                        # Source in its dkms.conf to see if we should autoinstall
94
 
                        AUTOINSTALL=""
95
 
                        if [ -f $dkms_tree/$module_in_tree/$version_in_tree/source/dkms.conf ]; then
96
 
                                . $dkms_tree/$module_in_tree/$version_in_tree/source/dkms.conf
97
 
                        else
98
 
                                current_state="broken"
99
 
                                continue
100
 
                        fi
101
 
                        [ `echo "$AUTOINSTALL" | grep -ic "^y"` -gt 0 ] && do_autoinstall="yes"
102
 
 
103
 
                        # Get the current state
104
 
                        # a mod can be both built and installed-weak (stupid, but could be)
105
 
                        # but installed-weak comes last, so use tail
106
 
                        current_state=`dkms status -m $module_in_tree -v $version_in_tree -k $kernel -a $arch 2>/dev/null | awk {'print $5'} | tail -n 1`
107
 
                        [ "$current_state" == "installed" -o "$current_state" == "installed-weak" ] && already_installed="true" && already_installed_version=$version_in_tree
108
 
                    fi
109
 
                done
110
 
 
111
 
                if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
112
 
                    log_action_begin_msg " $module_in_tree ($version_in_tree)"
113
 
                fi                    
114
 
 
115
 
                # Based on what we know, either do it or not
116
 
                if [ "$current_state" = "broken" ]; then
117
 
                    echo "$module_in_tree ($version_in_tree): Unable to locate $dkms_tree/$module_in_tree/$version_in_tree/source/dkms.conf" >>$output_loc
118
 
                    echo -e "\tDKMS tree must be manually fixed." >>$output_loc
119
 
                    if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
120
 
                        log_action_end_msg 1
121
 
                    fi
122
 
                    continue
123
 
                elif [ -n "$already_installed" ]; then
124
 
                    echo "$module_in_tree ($already_installed_version): Already installed on this kernel." >>$output_loc
125
 
                    if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
126
 
                        log_action_end_msg 0
127
 
                    fi
128
 
                elif [ -z "$do_autoinstall" ]; then
129
 
                    echo "$module_in_tree ($version_in_tree): AUTOINSTALL not set in its dkms.conf." >>$output_loc
130
 
                    if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
131
 
                        log_action_end_msg 0
132
 
                    fi
133
 
                elif [ -n "$do_autoinstall" ] && [ "$version_count" -gt 1 ]; then
134
 
                    echo "$module_in_tree: Multiple versions in DKMS. Unsure what to do. Resolve manually." >>$output_loc
135
 
                    if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
136
 
                        log_action_end_msg 1
137
 
                    fi
138
 
                else
139
 
                    echo "$module_in_tree ($version_in_tree): Installing module." >>$output_loc
140
 
                    if [ "$current_state" != "built" ] && ! [ -e /lib/modules/$kernel/build/include ]; then
141
 
                        echo "  Kernel headers for $kernel are not installed.  Cannot install this module." >>$output_loc
142
 
                        echo "  Try installing linux-headers-$kernel or equivalent." >>$output_loc
143
 
                        log_action_end_msg 1
144
 
                    elif [ "$current_state" != "built" ] && [ -e /lib/modules/$kernel/build/include ]; then
145
 
                        return_status=""
146
 
                        if [ -z "$kernel_preparation_done" ]; then
147
 
                            invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q --no-clean-kernel >>$output_loc" "." background
148
 
                            return_status="$?"
149
 
                            kernel_preparation_done="true"
150
 
                        else
151
 
                            invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch --no-prepare-kernel --no-clean-kernel -q >>$output_loc" "." background
152
 
                            return_status="$?"
153
 
                        fi
154
 
                        if [ "$return_status" -eq 0 ]; then
155
 
                            invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q >>$output_loc" "." background
156
 
                            if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
157
 
                                log_action_end_msg 0
158
 
                            else
159
 
                                echo "Done"
160
 
                            fi
161
 
                        else
162
 
                            echo "  Build failed.  Installation skipped." >>$output_loc
163
 
                            if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
164
 
                                log_action_end_msg 1
165
 
                            else
166
 
                                echo " Failed."
167
 
                            fi
168
 
                        fi
169
 
                    else
170
 
                        invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q >>$output_loc" "." background
171
 
                        return_status=$?
172
 
                        if [ "$return_status" -eq 101 ]; then
173
 
                            echo "  A newer module version than this already exists in this kernel." >>$output_loc
174
 
                            echo "  Skipping install... (you can manually install later with --force)" >>$output_loc
175
 
                        elif [ "$return_status" -ne 0 ]; then
176
 
                            echo "  Installation failed!" >>$output_loc
177
 
                        fi
178
 
                    fi
179
 
                fi
180
 
            fi
181
 
        done
182
 
        if [ -z "$modules_needing_status" ]; then
183
 
            if [ ! -z "$DEBIAN_STYLE_LOGGING" ]; then
184
 
                log_end_msg 0
 
118
            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): Installing module on kernel $kernel."
 
119
            if [ "$current_state" != "built" ] && ! [ -e /lib/modules/$kernel/build/include ]; then
 
120
                logger -t dkms_autoinstaller "  Kernel headers for $kernel are not installed.  Cannot install this module."
 
121
                logger -t dkms_autoinstaller "  Try installing linux-headers-$kernel or equivalent."
 
122
                log_action_end_msg 1
 
123
            elif [ "$current_state" != "built" ] && [ -e /lib/modules/$kernel/build/include ]; then
 
124
                return_status=""
 
125
                if [ -z "$kernel_preparation_done" ]; then
 
126
                    invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q --no-clean-kernel" "." background
 
127
                    return_status="$?"
 
128
                    kernel_preparation_done="true"
 
129
                else
 
130
                    invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch --no-prepare-kernel --no-clean-kernel -q" "." background
 
131
                    return_status="$?"
 
132
                fi
 
133
                if [ "$return_status" -eq 0 ]; then
 
134
                    invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch" "." background
 
135
                    emit_module_status successful $module_in_tree
 
136
                    log_action_end_msg 0
 
137
                else
 
138
                    logger -t dkms_autoinstaller "  Build failed.  Installation skipped."
 
139
                    emit_module_status failed $module_in_tree
 
140
                    log_action_end_msg 1
 
141
                fi
185
142
            else
186
 
                echo -n "."
 
143
                invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q" "." background
 
144
                return_status=$?
 
145
                if [ "$return_status" -eq 0 ]; then
 
146
                    emit_module_status successful $module_in_tree
 
147
                elif [ "$return_status" -eq 101 ]; then
 
148
                    logger -t dkms_autoinstaller "  A newer module version than this already exists in kernel."
 
149
                    logger -t dkms_autoinstaller "  Skipping install... (you can manually install later with --force)"
 
150
                    emit_module_status successful $module_in_tree
 
151
                elif [ "$return_status" -ne 0 ]; then
 
152
                    logger -t dkms_autoinstaller "  Installation failed!"
 
153
                    emit_module_status failed $module_in_tree
 
154
                fi
187
155
            fi
188
156
        fi
189
 
        ;;
190
 
  stop)
191
 
        # ignore
192
 
        ;;
193
 
  restart)
194
 
        # ignore
195
 
        ;;
196
 
  force-reload)
197
 
        # ignore
198
 
        ;;
199
 
  status)
200
 
        # ignore
201
 
        ;;
202
 
  reload)
203
 
        exit 0
204
 
        ;;
 
157
    done
 
158
    if [ -z "$modules_needing_status" ]; then
 
159
        log_end_msg 0
 
160
    fi
 
161
    ;;
 
162
  stop|restart|force-reload|status|reload)
 
163
    # ignore
 
164
    ;;
205
165
  *)
206
 
        echo $"Usage: $0 {start|stop}"
 
166
    echo "Usage: $0 {start}"
207
167
esac
208
168
 
209
169
exit 0