123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #!/usr/bin/env bash
- ARCH="$1"
- VER="$2"
- BUILD_DIR="$3"
- PKG_BUILD="$4"
- PACKAGE_DIR="$5"
- declare -A modpaths moddeps modlevels
- find_modlevel() {
- local dep level=0
- for dep in ${moddeps[$1]}; do
- [[ -n "${modlevels[$dep]}" ]] || find_modlevel $dep
- [[ ${modlevels[$dep]} -lt $level ]] || level=$((modlevels[$dep] + 1))
- done
- modlevels[$1]=$level
- }
- pkgname() {
- tr 'A-Z_' 'a-z-' <<< "kmod-$1"
- }
- for modpath in $(find ${BUILD_DIR}/modules -name \*.ko | xargs); do
- modname="$(basename $modpath .ko)"
- moddep="$(strings $modpath | awk -F= '/^depends=/{print $2}' | sed 's/,/ /g')"
- modpaths[$modname]="$modpath"
- moddeps[$modname]="$moddep"
- done
- rm -rf ${BUILD_DIR}/linux-modules
- for modname in ${!modpaths[@]}; do
- find_modlevel $modname
- ctrlfile=${BUILD_DIR}/kmod-control/kmod-${modname}.control
- ipkgdir=${BUILD_DIR}/linux-modules/ipkg/$modname
- cat >$ctrlfile <<-EOF
- Package: $(pkgname $modname)
- Priority: optional
- Section: sys
- Description: kernel module $modname
- EOF
- bash $(dirname $0)/make-ipkg-dir.sh $ipkgdir $ctrlfile $VER $ARCH
- depline="kernel ($VER)"
- for m in ${moddeps[$modname]}; do
- depline+=", $(pkgname ${m})"
- done
- echo "Depends: $depline" >>${ipkgdir}/CONTROL/control
- mkdir -p ${ipkgdir}/lib/modules/${VER}
- cp ${modpaths[$modname]} ${ipkgdir}/lib/modules/${VER}
- cat >${ipkgdir}/CONTROL/postinst <<EOF
- #!/bin/sh
- if [ -z \${IPKG_INSTROOT} ]; then
- . /etc/functions.sh
- load_modules /etc/modules.d/${modlevels[$modname]}-$modname
- fi
- EOF
- chmod 0755 ${ipkgdir}/CONTROL/postinst
- mkdir -p ${ipkgdir}/etc/modules.d
- echo $modname >${ipkgdir}/etc/modules.d/${modlevels[$modname]}-$modname
- ${PKG_BUILD} ${ipkgdir} ${PACKAGE_DIR} || exit 1
- done
|