Skip to content

Commit 703c538

Browse files
author
Charlie Shirron
committed
common.postinst: continue on error
In the postinst script, if we hit an error building for one kernel, record the error and continue on to the next kernel. When done, exit with the value of any recorded error. This allows us to do a best- effort build for all installed kernels. Allow this feature to be turned off if this behavior isn't desired.
1 parent 3996b87 commit 703c538

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

dkms_common.postinst.in

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ARCH=$4
105105
UPGRADE=$5
106106

107107
if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
108-
echo "Need NAME, and VERSION defined"
108+
echo "Need NAME and VERSION defined"
109109
echo "ARCH is optional"
110110
exit 1
111111
fi
@@ -115,6 +115,8 @@ if [ -f /etc/dkms/no-autoinstall ]; then
115115
exit 0
116116
fi
117117

118+
continue_on_error="true"
119+
118120
# read framework configuration options
119121
for fwcf in /etc/dkms/framework.conf /etc/dkms/framework.conf.d/*.conf ; do
120122
if [ -f "$fwcf" ] && [ -r "$fwcf" ]; then
@@ -128,13 +130,13 @@ done
128130
KERNELS=$(ls -dv "$MODDIR"/*/build 2>/dev/null | sed 's|'"$MODDIR"'/\(.*\)/build|\1|' || true)
129131
CURRENT_KERNEL=$(uname -r)
130132

131-
#We never want to keep an older version side by side to prevent conflicts
133+
# We never want to keep an older version side by side to prevent conflicts
132134
if [ -e "/var/lib/dkms/$NAME/$VERSION" ]; then
133135
echo "Removing old $NAME/$VERSION DKMS files..."
134136
dkms remove -m "$NAME" -v "$VERSION" --all
135137
fi
136138

137-
#Load new files, by source package and by tarball
139+
# Load new files, by source package and by tarball
138140
if [ -f "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz" ]; then
139141
if ! dkms ldtarball --archive "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz"; then
140142
echo ""
@@ -216,16 +218,18 @@ if [ -n "$ARCH" ]; then
216218
echo "Building for architecture $ARCH"
217219
fi
218220

221+
exit_code=0
222+
failed_kernels=""
219223
for KERNEL in $KERNELS; do
220224
echo ""
221-
dkms_status=$(dkms status -m "$NAME" -v "$VERSION" -k "$KERNEL" ${ARCH:+-a "$ARCH"})
222225
if [ "$(echo "$KERNEL" | grep -c "BOOT")" -gt 0 ]; then
223226
echo "Module build and install for $KERNEL was skipped as "
224227
echo "it is a BOOT variant"
225228
continue
226229
fi
227230

228-
#if the module isn't yet built, try to build it
231+
# if the module isn't yet built, try to build it
232+
dkms_status=$(dkms status -m "$NAME" -v "$VERSION" -k "$KERNEL" ${ARCH:+-a "$ARCH"})
229233
if [ "$(echo "$dkms_status" | grep -c ": built")" -eq 0 ]; then
230234
if [ ! -L "/var/lib/dkms/$NAME/$VERSION/source" ]; then
231235
echo "This package appears to be a binaries-only package"
@@ -245,21 +249,28 @@ for KERNEL in $KERNELS; do
245249
0)
246250
;;
247251
*)
248-
exit $res
252+
exit_code=$res
253+
[ "$continue_on_error" != "true" ] && break
254+
failed_kernels+=" $KERNEL"
255+
continue
249256
;;
250257
esac
251-
dkms_status=$(dkms status -m "$NAME" -v "$VERSION" -k "$KERNEL" ${ARCH:+-a "$ARCH"})
252258
else
253259
echo "Module build for kernel $KERNEL was skipped since the"
254260
echo "kernel headers for this kernel do not seem to be installed."
261+
continue
255262
fi
263+
dkms_status=$(dkms status -m "$NAME" -v "$VERSION" -k "$KERNEL" ${ARCH:+-a "$ARCH"})
256264
fi
257265

258-
#if the module is built (either pre-built or just now), install it
259-
if [ "$(echo "$dkms_status" | grep -c ": built")" -eq 1 ] &&
260-
[ "$(echo "$dkms_status" | grep -c ": installed")" -eq 0 ]; then
266+
# if the module is built (either pre-built or just now), install it
267+
if [ "$(echo "$dkms_status" | grep -c ": built")" -ne 0 ]; then
261268
dkms install -m "$NAME" -v "$VERSION" -k "$KERNEL" ${ARCH:+-a "$ARCH"}
262269
fi
263270
done
264271

272+
[ -n "$failed_kernels" ] && echo "Builds for the following kernel(s) failed:$failed_kernels"
273+
274+
exit $exit_code
275+
265276
# vim: et:ts=4:sw=4

dkms_framework.conf.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@
6262
# The command listed is executed if set to any non null value. $kernelver can be
6363
# used in path to represent the target kernel version.
6464
# post_transaction=""
65+
66+
# In common.postinst, if en error is encountered while building a module for
67+
# a kernel, continue on to the next kernel if true, otherwise stop.
68+
# continue_on_error="true"

0 commit comments

Comments
 (0)