3 # make-module-ipkgs.sh - scan through modules directory and create a package
4 # for each of them automatically.
6 # Copyright (C) 2015 - Phil Sutter <phil@nwl.cc>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # $0 <ARCH> <KERNEL_VERSION> <LINUX_BUILD_DIR> <pkg-build-cmd> <PACKAGE_DIR>
31 # declare associative arrays
32 declare -A modpaths moddeps modlevels
34 # recursively find a level for given module which is high enough so all
35 # dependencies are in a lower level
36 find_modlevel
() { # (modname)
38 for dep
in ${moddeps[$1]}; do
39 [[ -n "${modlevels[$dep]}" ]] || find_modlevel
$dep
40 [[ ${modlevels[$dep]} -lt $level ]] || level
=$
((modlevels
[$dep] + 1))
45 # sanitize modname, ipkg does not allow uppercase or underscores
46 pkgname
() { # (modname)
47 tr 'A-Z_' 'a-z-' <<< "kmod-$1"
50 for modpath
in $
(find ${BUILD_DIR}/modules
-name \
*.ko |
xargs); do
51 modname
="$(basename $modpath .ko)"
52 moddep
="$(strings $modpath | awk -F= '/^depends=/{print $2}' | sed 's/,/ /g')"
53 modpaths
[$modname]="$modpath"
54 moddeps
[$modname]="$moddep"
58 #for modname in ${!modpaths[@]}; do
59 # echo "$modname: ${modpaths[$modname]}"
63 #for modname in ${!moddeps[@]}; do
64 # echo "$modname: ${moddeps[$modname]}"
68 # start with empty directory, avoid leftovers after version change
69 rm -rf ${BUILD_DIR}/linux-modules
71 for modname
in ${!modpaths[@]}; do
72 find_modlevel
$modname
74 ctrlfile
=${BUILD_DIR}/kmod-control
/kmod-
${modname}.control
75 ipkgdir
=${BUILD_DIR}/linux-modules
/ipkg
/$modname
78 Package: $(pkgname $modname)
81 Description: kernel module $modname
83 bash $
(dirname $0)/make-ipkg-dir.sh
$ipkgdir $ctrlfile $VER $ARCH
85 depline
="kernel ($VER)"
86 for m
in ${moddeps[$modname]}; do
87 depline
+=", $(pkgname ${m})"
89 echo "Depends: $depline" >>${ipkgdir}/CONTROL
/control
90 mkdir
-p ${ipkgdir}/lib
/modules
/${VER}
91 cp ${modpaths[$modname]} ${ipkgdir}/lib/modules/${VER}
92 cat >${ipkgdir}/CONTROL
/postinst
<<EOF
94 if [ -z \${IPKG_INSTROOT} ]; then
96 load_modules /etc/modules.d/${modlevels[$modname]}-$modname
99 chmod 0755 ${ipkgdir}/CONTROL
/postinst
100 mkdir
-p ${ipkgdir}/etc
/modules.d
101 echo $modname >${ipkgdir}/etc
/modules.d
/${modlevels[$modname]}-$modname
102 ${PKG_BUILD} ${ipkgdir} ${PACKAGE_DIR} ||
exit 1