kernel-source/split-into-symsets

41 lines
684 B
Bash

#! /bin/bash
usage() {
echo "Usage: ${0##*/} {dir} < Module.symvers"
exit $1
}
[ $# -eq 1 ] || usage 1
dir=$1
tmpdir=$(mktemp -dt ${0##*/}.XXXXXXXXXX)
trap "rm -rf $tmpdir" EXIT
split_into_sets() {
local dir=$1
awk '
{ set = gensub(/\/[^\/]+$/, "", "", $3)
sets[set] = sets[set] $0 "\n"
}
END {
for (set in sets) {
filename = gensub(/\//, "_", "g", set)
printf "%s", sets[set] > dir "/" filename
}
}
' dir="$dir"
}
sort -k2 \
| split_into_sets "$tmpdir"
shopt -s nullglob
set -- $tmpdir/*
if [ $# -ne 0 ]; then
md5sum "$@" \
| while read md5sum set; do
cp $set $dir/${set##*/}.${md5sum:0:16}
done
fi