144 lines
3.3 KiB
Bash
Executable File
144 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# DKMS trigger. Used to add/build/install or remove the specified modules
|
|
# from all kernels.
|
|
#
|
|
# Modules can be specified like:
|
|
# dkms_modules="<modulename> <version> ..."
|
|
#
|
|
# Arguments: $ACTION = [run/targets]
|
|
# $TARGET = [post-install/pre-remove]
|
|
# $PKGNAME
|
|
# $VERSION
|
|
# $UPDATE = [yes/no]
|
|
#
|
|
ACTION="$1"
|
|
TARGET="$2"
|
|
PKGNAME="$3"
|
|
VERSION="$4"
|
|
UPDATE="$5"
|
|
|
|
export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
remove_modules() {
|
|
local _modver _kver
|
|
|
|
# Remove the specified modules from all kernels.
|
|
set -- ${dkms_modules}
|
|
while [ $# -gt 0 ]; do
|
|
$DKMS status -m "$1" | while read line; do
|
|
if $(echo "$line" | egrep -vq '(added|built|installed)'); then
|
|
shift 2; continue
|
|
fi
|
|
_modver=$(echo "$line"|sed "s/$1,[[:blank:]]\([^,]*\)[,:].*/\1/;t;d")
|
|
_kver=$(echo "$line"|awk '{print $3}'|sed "s/\(.*\),$/\1/")
|
|
echo -n "Removing DKMS module '${1}-${_modver}' for kernel-${_kver}... "
|
|
$DKMS remove -m "$1" -v "${_modver}" -k "${_kver}" >/dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "done."
|
|
else
|
|
echo "FAILED!"
|
|
fi
|
|
done
|
|
shift 2
|
|
done
|
|
}
|
|
|
|
add_modules() {
|
|
local rval=
|
|
|
|
# Add/build and install the specified modules for all kernels.
|
|
set -- ${dkms_modules}
|
|
while [ $# -gt 0 ]; do
|
|
$DKMS add -m "$1" -v "$2" >/dev/null 2>&1
|
|
rval=$?
|
|
if [ $rval -eq 0 ]; then
|
|
echo "Added DKMS module '$1-$2'."
|
|
elif [ $rval -eq 3 ]; then
|
|
echo "DKMS module '$1-$2' already added, skipping."
|
|
else
|
|
echo "Failed to add DKMS module: '$1-$2'..."
|
|
err=1
|
|
fi
|
|
shift 2
|
|
done
|
|
[ -n "$err" ] && exit $err
|
|
|
|
for f in $(echo lib/modules/*); do
|
|
_kver=$(basename $f)
|
|
if [ ! -e "${f}/build/include" ]; then
|
|
echo "Skipping kernel-${_kver}. kernel-headers package not installed..."
|
|
continue
|
|
fi
|
|
if [ ! -f ${f}/build/scripts/basic/fixdep ] || [ ! -f ${f}/build/scripts/mod/modpost ] ; then
|
|
echo -n "Prepare to build modules for kernel-${_kver}... "
|
|
yes "" | make -j$(nproc) -C ${f}/build prepare0 > ${f}/build/make.log 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "done."
|
|
else
|
|
echo "FAILED!"
|
|
echo "Kernel scripts failed to build, please check /${f}/build/make.log"
|
|
echo "for errors in the log file."
|
|
fi
|
|
fi
|
|
set -- ${dkms_modules}
|
|
while [ $# -gt 0 ]; do
|
|
echo -n "Building DKMS module '$1-$2' for kernel-${_kver}... "
|
|
$DKMS build -m "$1" -v "$2" -k "${_kver}" >/dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "done."
|
|
else
|
|
echo "FAILED!"
|
|
echo "DKMS module '$1-$2' failed to build, please check /var/lib/dkms"
|
|
echo "for errors in the log file."
|
|
shift 2; continue
|
|
fi
|
|
echo -n "Installing DKMS module '$1-$2' for kernel-${_kver}... "
|
|
$DKMS install -m "$1" -v "$2" -k "${_kver}" >/dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "done."
|
|
else
|
|
echo "FAILED!"
|
|
echo "DKMS module '$1-$2' failed to install, please do this manually"
|
|
echo "and check for errors in the log file."
|
|
fi
|
|
shift 2
|
|
done
|
|
done
|
|
}
|
|
|
|
case "$ACTION" in
|
|
targets)
|
|
echo "post-install pre-remove"
|
|
;;
|
|
run)
|
|
if [ -x /usr/bin/dkms ]; then
|
|
DKMS=/usr/bin/dkms
|
|
elif [ -x /usr/sbin/dkms ]; then
|
|
DKMS=/usr/sbin/dkms
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
[ ! -x $DKMS -o -z "$dkms_modules" ] && exit 0
|
|
|
|
case "$TARGET" in
|
|
post-install)
|
|
export IGNORE_CC_MISMATCH=1
|
|
add_modules
|
|
;;
|
|
pre-remove)
|
|
remove_modules
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|