l30013671 / rpms / kernel

Forked from rpms/kernel 2 years ago
Clone
Pablo Greco ceb317
#! /bin/bash
Pablo Greco ceb317
Pablo Greco ceb317
Dir=$1
Pablo Greco ceb317
List=$2
Pablo Greco ceb317
Dest="extra"
Pablo Greco ceb317
Pablo Greco ceb317
# Destination was specified on the command line
Pablo Greco ceb317
test -n "$3" && Dest="$3"
Pablo Greco ceb317
Pablo Greco ceb317
pushd $Dir
Pablo Greco ceb317
rm -rf modnames
Pablo Greco ceb317
find . -name "*.ko" -type f > modnames
Pablo Greco ceb317
# Look through all of the modules, and throw any that have a dependency in
Pablo Greco ceb317
# our list into the list as well.
Pablo Greco ceb317
rm -rf dep.list dep2.list
Pablo Greco ceb317
rm -rf req.list req2.list
Pablo Greco ceb317
touch dep.list req.list
Pablo Greco ceb317
cp "$List" .
Pablo Greco ceb317
Pablo Greco ceb317
# This variable needs to be exported because it is used in sub-script
Pablo Greco ceb317
# executed by xargs
Pablo Greco ceb317
export ListName=$(basename "$List")
Pablo Greco ceb317
Pablo Greco ceb317
# NB: this loop runs 2000+ iterations. Try to be fast.
Pablo Greco ceb317
NPROC=`nproc`
Pablo Greco ceb317
[ -z "$NPROC" ] && NPROC=1
Pablo Greco ceb317
cat modnames | xargs -r -n1 -P $NPROC sh -c '
Pablo Greco ceb317
  dep=$1
Pablo Greco ceb317
  depends=`modinfo $dep | sed -n -e "/^depends/ s/^depends:[ \t]*//p"`
Pablo Greco ceb317
  [ -z "$depends" ] && exit
Pablo Greco ceb317
  for mod in ${depends//,/ }
Pablo Greco ceb317
  do
Pablo Greco ceb317
    match=$(grep "^$mod.ko" "$ListName")
Pablo Greco ceb317
    [ -z "$match" ] && continue
Pablo Greco ceb317
    # check if the module we are looking at is in mod-extra too.
Pablo Greco ceb317
    # if so we do not need to mark the dep as required.
Pablo Greco ceb317
    mod2=${dep##*/}  # same as `basename $dep`, but faster
Pablo Greco ceb317
    match2=$(grep "^$mod2" "$ListName")
Pablo Greco ceb317
    if [ -n "$match2" ]
Pablo Greco ceb317
    then
Pablo Greco ceb317
      #echo $mod2 >> notreq.list
Pablo Greco ceb317
      continue
Pablo Greco ceb317
    fi
Pablo Greco ceb317
    echo $mod.ko >> req.list
Pablo Greco ceb317
  done
Pablo Greco ceb317
' DUMMYARG0   # xargs appends MODNAME, which becomes $dep in the script above
Pablo Greco ceb317
Pablo Greco ceb317
sort -u req.list > req2.list
Pablo Greco ceb317
sort -u "$ListName" > modules2.list
Pablo Greco ceb317
join -v 1 modules2.list req2.list > modules3.list
Pablo Greco ceb317
Pablo Greco ceb317
for mod in $(cat modules3.list)
Pablo Greco ceb317
do
Pablo Greco ceb317
  # get the path for the module
Pablo Greco ceb317
  modpath=`grep /$mod modnames`
Pablo Greco ceb317
  [ -z "$modpath" ] && continue
Pablo Greco ceb317
  echo $modpath >> dep.list
Pablo Greco ceb317
done
Pablo Greco ceb317
Pablo Greco ceb317
sort -u dep.list > dep2.list
Pablo Greco ceb317
Pablo Greco ceb317
# now move the modules into the extra/ directory
Pablo Greco ceb317
for mod in `cat dep2.list`
Pablo Greco ceb317
do
Pablo Greco ceb317
  newpath=`dirname $mod | sed -e "s/kernel\\//$Dest\//"`
Pablo Greco ceb317
  mkdir -p $newpath
Pablo Greco ceb317
  mv $mod $newpath
Pablo Greco ceb317
done
Pablo Greco ceb317
Pablo Greco ceb317
popd
Pablo Greco ceb317
Pablo Greco ceb317
# If we're signing modules, we can't leave the .mod files for the .ko files
Pablo Greco ceb317
# we've moved in .tmp_versions/.  Remove them so the Kbuild 'modules_sign'
Pablo Greco ceb317
# target doesn't try to sign a non-existent file.  This is kinda ugly, but
Pablo Greco ceb317
# so is modules-extra.
Pablo Greco ceb317
Pablo Greco ceb317
for mod in `cat ${Dir}/dep2.list`
Pablo Greco ceb317
do
Pablo Greco ceb317
  modfile=`basename $mod | sed -e 's/.ko/.mod/'`
Pablo Greco ceb317
  rm .tmp_versions/$modfile
Pablo Greco ceb317
done
Pablo Greco ceb317
Pablo Greco ceb317
pushd $Dir
Pablo Greco ceb317
rm modnames dep.list dep2.list req.list req2.list
Pablo Greco ceb317
rm "$ListName" modules2.list modules3.list
Pablo Greco ceb317
popd