Debian Codegraph @

build_tools/dkms-helper

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 mkdir -p /usr/src/dahdi-linux-${VERSION}
69 cp -f -r * /usr/src/dahdi-linux-${VERSION}/
70 fi
71 fi
72 make -C /usr/src/dahdi-linux-${VERSION} install-firmware firmware-loaders
73 build_tools/dkms-helper generate_conf > /usr/src/dahdi-linux-${VERSION}/dkms.conf
74 echo $VERSION > /usr/src/dahdi-linux-${VERSION}/.version
75 ${DKMS} add -m dahdi-linux -v ${VERSION}
76 ${DKMS} build -m dahdi-linux -v ${VERSION}
77 ${DKMS} install --force -m dahdi-linux -v ${VERSION}
78 }
79
80 remove() {
81 if [ $(id -u) != "0" ]; then
82 echo "You must run $0 as root."
83 exit 1
84 fi
85 REMOVE_ALL=false
86 shift
87 while getopts "a" opt; do
88 case $opt in
89 a) REMOVE_ALL=true ;;
90 *) echo "Unknown option to remove" ; exit 1;;
91 esac
92 done
93 if [ $REMOVE_ALL == true ]; then
94 # Remove all installed dahdi versions for all kernels.
95 for version in $(${DKMS} status -m dahdi-linux | cut -d, -f 2 | sed -e "s/^\s\+//"); do
96 echo "Removing version ${version}"
97 ${DKMS} remove -m dahdi-linux -v ${version} --all
98 rm -f -r /usr/src/dahdi-linux-${version}
99 done
100 else
101 # Just remove the version for the current tree.
102 GIT=$(which git)
103 VERSION="$(build_tools/make_version .)"
104 ${DKMS} remove -m dahdi-linux -v ${VERSION} --all
105 if [ -e /usr/src/dahdi-linux-${VERSION}/dkms.conf ]; then
106 rm -f -r /usr/src/dahdi-linux-${VERSION}
107 else
108 echo "/usr/src/dahdi-linux-${VERSION} not a dkms dir?"
109 exit 1
110 fi
111 fi
112 }
113
114 # Run the command...
115 shift $(($OPTIND-1))
116 COMMAND=$1
117 case $COMMAND in
118 add) add $*; exit $? ;;
119 remove) remove $* ; exit $? ;;
120 generate_conf) generate_configuration; exit $? ;;
121 *) echo "unknown command $0" ; usage; exit 1;;
122 esac
123
124 exit 0