| #! /bin/bash |
| |
| |
| RpmDir=$1 |
| ModDir=$2 |
| Dir="$1/$2" |
| |
| |
| |
| List=$3 |
| Dest="$4" |
| |
| blacklist() |
| { |
| cat > "$RpmDir/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__ |
| |
| |
| |
| |
| |
| |
| blacklist $1 |
| __EOF__ |
| } |
| |
| check_blacklist() |
| { |
| mod=$(find "$RpmDir/$ModDir" -name "$1") |
| [ ! "$mod" ] && return 0 |
| if modinfo "$mod" | grep -q '^alias:\s\+net-'; then |
| mod="${1##*/}" |
| mod="${mod%.ko*}" |
| echo "$mod has an alias that allows auto-loading. Blacklisting." |
| blacklist "$mod" |
| fi |
| } |
| |
| find_depends() |
| { |
| dep=$1 |
| depends=$(modinfo "$dep" | sed -n -e "/^depends/ s/^depends:[ \t]*//p") |
| [ -z "$depends" ] && exit |
| for mod in ${depends//,/ } |
| do |
| match=$(grep "^$mod.ko" "$ListName") |
| [ -z "$match" ] && continue |
| |
| |
| mod2=${dep##*/} |
| match2=$(grep "^$mod2" "$ListName") |
| if [ -n "$match2" ] |
| then |
| |
| continue |
| fi |
| echo "$mod".ko >> req.list |
| done |
| } |
| |
| foreachp() |
| { |
| P=$(nproc) |
| bgcount=0 |
| while read -r mod; do |
| $1 "$mod" & |
| |
| bgcount=$((bgcount + 1)) |
| if [ $bgcount -eq "$P" ]; then |
| wait -n |
| bgcount=$((bgcount - 1)) |
| fi |
| done |
| |
| wait |
| } |
| |
| |
| test -n "$4" && echo "$0: Override Destination $Dest has been specified." |
| |
| pushd "$Dir" |
| |
| OverrideDir=$(basename "$List") |
| OverrideDir=${OverrideDir%.*} |
| OverrideDir=${OverrideDir#*-} |
| mkdir -p "$OverrideDir" |
| |
| rm -rf modnames |
| find . -name "*.ko" -type f > modnames |
| |
| |
| rm -rf dep.list dep2.list |
| rm -rf req.list req2.list |
| touch dep.list req.list |
| cp "$List" . |
| |
| |
| |
| ListName=$(basename "$List") |
| export ListName |
| |
| foreachp find_depends < modnames |
| |
| sort -u req.list > req2.list |
| sort -u "$ListName" > modules2.list |
| join -v 1 modules2.list req2.list > modules3.list |
| |
| while IFS= read -r mod |
| do |
| |
| modpath=$(grep /"$mod" modnames) |
| [ -z "$modpath" ] && continue |
| echo "$modpath" >> dep.list |
| done < modules3.list |
| |
| sort -u dep.list > dep2.list |
| |
| if [ -n "$Dest" ]; then |
| |
| while IFS= read -r mod |
| do |
| newpath=$(dirname "$mod" | sed -e "s/kernel\\//$Dest\//") |
| mkdir -p "$newpath" |
| mv "$mod" "$newpath" |
| echo "$mod" | sed -e "s/kernel\\//$Dest\//" | sed -e "s|^.|${ModDir}|g" >> "$RpmDir"/"$ListName" |
| done < dep2.list |
| fi |
| |
| popd |
| |
| |
| |
| |
| |
| |
| while IFS= read -r mod |
| do |
| modfile=$(basename "$mod" | sed -e 's/.ko/.mod/') |
| rm .tmp_versions/"$modfile" |
| done < "$Dir"/dep2.list |
| |
| if [ -z "$Dest" ]; then |
| sed -e "s|^.|${ModDir}|g" "$Dir"/dep2.list > "$RpmDir/$ListName" |
| echo "./$RpmDir/$ListName created." |
| [ -d "$RpmDir/etc/modprobe.d/" ] || mkdir -p "$RpmDir/etc/modprobe.d/" |
| foreachp check_blacklist < "$List" |
| fi |
| |
| |
| |
| |
| |
| |
| floppylist=("$RpmDir"/"$ModDir"/kernel/drivers/block/floppy.ko*) |
| if [[ -n ${floppylist[0]} && -f ${floppylist[0]} ]]; then |
| blacklist "floppy" |
| fi |
| |
| |
| echo "$ModDir/$OverrideDir" >> "$RpmDir/$ListName" |
| |
| pushd "$Dir" |
| rm modnames dep.list dep2.list req.list req2.list |
| rm "$ListName" modules2.list modules3.list |
| popd |