Debian Codegraph @

build_tools/dkms-helper

raw
1 #!/bin/bash
2
3 set -e
4
5 DKMS=$(which dkms)
6
7 usage() {
8 echo "$(basename $0): Helper functions for DKMS (Dynamic Kernel Module Support)"
9 echo "Usage: $0 [add|remove|generate_conf]"
10 echo "Options:"
11 echo " remove -a : Remove all versions of DAHDI for all kernels."
12 echo ""
13 echo "Examples:"
14 echo ""
15 echo " build_tools/dkms-helper add"
16 echo " Installs the current version of DAHDI into the DKMS system."
17 echo ""
18 echo " build_tools/dkms-helper remove"
19 echo " Removes the current version of DAHDI from all kernels."
20 echo ""
21 echo " build_tools/dkms-helper generate_conf > dkms.conf"
22 echo " Create a dkms.conf based on the currently compiled kernel"
23 echo " modules. This is also done as part of add and is not"
24 echo " normally needed as a separate step."
25 echo ""
26 echo "NOTE: Because firmware files could be different between different"
27 echo "versions of DAHDI, and the firmware files are installed into the common"
28 echo "/lib/firmware directory, you should remove a given version of DAHDI from all"
29 echo "kernels before installing a new version of DAHDI to avoid potential"
30 echo "conflicts."
31 echo ""
32 }
33
34 generate_configuration() {
35 echo 'PACKAGE_NAME="dahdi-linux"'
36 echo "PACKAGE_VERSION=\"$(build_tools/make_version .)\""
37 echo 'MAKE="make KSRC=/lib/modules/${kernelver}/build"'
38 echo 'CLEAN="make clean"'
39 echo 'AUTOINSTALL="yes"'
40 let "module_number=0" || true
41 for file in $(find ./ -type f -name "*.ko"); do
42 MODULE_LOCATION=$(dirname $file | cut -d\/ -f 2-)
43 echo "BUILT_MODULE_NAME[$module_number]=\"$(basename $file .ko)\""
44 echo "BUILT_MODULE_LOCATION[$module_number]=\"$MODULE_LOCATION\""
45 echo "DEST_MODULE_LOCATION[$module_number]=\"/kernel/dahdi/$(echo $MODULE_LOCATION | cut -d\/ -f 3-)\""
46 let "module_number=${module_number}+1" || true
47 done
48 if [ $module_number -eq 0 ]; then
49 echo "WARNING: You should build the modules before generating a config." >&2
50 exit 1
51 fi
52 }
53
54 add() {
55 GIT=$(which git)
56 VERSION="$(build_tools/make_version .)"
57 if [ $(id -u) != "0" ]; then
58 echo "You must run $0 as root."
59 exit 1
60 fi
61 echo "Building for version ${VERSION}"
62 make > /dev/null
63 echo "Copying to /usr/src/dahdi-linux-${VERSION}"
64 if [ ! -d /usr/src/dahdi-linux-${VERSION} ]; then
65 if [ -d .git ]; then
66 ${GIT} checkout-index -a --prefix=/usr/src/dahdi-linux-${VERSION}/
67 else
68 cp -f -r * /usr/src/dahdi-linux-${VERSION}/
69 fi
70 fi
71 make -C /usr/src/dahdi-linux-${VERSION} install-firmware firmware-loaders
72 build_tools/dkms-helper generate_conf > /usr/src/dahdi-linux-${VERSION}/dkms.conf
73 echo $VERSION > /usr/src/dahdi-linux-${VERSION}/.version
74 ${DKMS} add -m dahdi-linux -v ${VERSION}
75 ${DKMS} build -m dahdi-linux -v ${VERSION}
76 ${DKMS} install --force -m dahdi-linux -v ${VERSION}
77 }
78
79 remove() {
80 if [ $(id -u) != "0" ]; then
81 echo "You must run $0 as root."
82 exit 1
83 fi
84 REMOVE_ALL=false
85 shift
86 while getopts "a" opt; do
87 case $opt in
88 a) REMOVE_ALL=true ;;
89 *) echo "Unknown option to remove" ; exit 1;;
90 esac
91 done
92 if [ $REMOVE_ALL == true ]; then
93 # Remove all installed dahdi versions for all kernels.
94 for version in $(${DKMS} status -m dahdi-linux | cut -d, -f 2 | sed -e "s/^\s\+//"); do
95 echo "Removing version ${version}"
96 ${DKMS} remove -m dahdi-linux -v ${version} --all
97 rm -f -r /usr/src/dahdi-linux-${version}
98 done
99 else
100 # Just remove the version for the current tree.
101 GIT=$(which git)
102 VERSION="$(build_tools/make_version .)"
103 ${DKMS} remove -m dahdi-linux -v ${VERSION} --all
104 if [ -e /usr/src/dahdi-linux-${VERSION}/dkms.conf ]; then
105 rm -f -r /usr/src/dahdi-linux-${VERSION}
106 else
107 echo "/usr/src/dahdi-linux-${VERSION} not a dkms dir?"
108 exit 1
109 fi
110 fi
111 }
112
113 # Run the command...
114 shift $(($OPTIND-1))
115 COMMAND=$1
116 case $COMMAND in
117 add) add $*; exit $? ;;
118 remove) remove $* ; exit $? ;;
119 generate_conf) generate_configuration; exit $? ;;
120 *) echo "unknown command $0" ; usage; exit 1;;
121 esac
122
123 exit 0