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 for modname
in ${!modpaths[@]}; do
69 find_modlevel
$modname
71 ctrlfile
=${BUILD_DIR}/kmod-control
/kmod-
${modname}.control
72 ipkgdir
=${BUILD_DIR}/linux-modules
/ipkg
/$modname
75 Package: $(pkgname $modname)
78 Description: kernel module $modname
80 sh $
(dirname $0)/make-ipkg-dir.sh
$ipkgdir $ctrlfile $VER $ARCH
82 depline
="kernel ($VER)"
83 for m
in ${moddeps[$modname]}; do
84 depline
+=", $(pkgname ${m})"
86 echo "Depends: $depline" >>${ipkgdir}/CONTROL
/control
87 mkdir
-p ${ipkgdir}/lib
/modules
/${VER}
88 cp ${modpaths[$modname]} ${ipkgdir}/lib/modules/${VER}
89 cat >${ipkgdir}/CONTROL
/postinst
<<EOF
91 if [ -z \${IPKG_INSTROOT} ]; then
93 load_modules /etc/modules.d/${modlevels[$modname]}-$modname
96 chmod 0755 ${ipkgdir}/CONTROL
/postinst
97 mkdir
-p ${ipkgdir}/etc
/modules.d
98 echo $modname >${ipkgdir}/etc
/modules.d
/${modlevels[$modname]}-$modname
99 env
${PKG_BUILD} ${ipkgdir} ${PACKAGE_DIR} ||
exit 1