-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoddep
executable file
·108 lines (92 loc) · 2.73 KB
/
moddep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
outdir="$1"
if test -z "$outdir";then
echo "Usage: $0 outdir [-r \"missing_ok module list ...\"] [modules...]"
exit 1
fi
shift
test "x$1" != "x-r" || {
missing_ok="$2"
shift 2
}
: ${KVERS:=${KVERS:-$(uname -r)}}
: ${MODDIR:=${MODDIR:-/lib/modules/$KVERS}}
: ${MODDIR_OUT:=$outdir/lib/modules/$KVERS}
trap "exit 1" USR1
list_new_nondup() {
local have_list="$1" have new_list new
shift
for new;do
for have in $have_list;do
if test "z$new" = "z$have";then
new=""
break
fi
done
if test -n "$new";then
new_list="${new_list:+$new_list }$new"
have_list="${have_list:+$have_list }$new"
fi
done
echo $new_list
}
get_deps() {
modinfo -F depends $@ | sed -e 's/,/ /g'
}
to_filenames() {
local pat name n=0 found not_found names
for name;do
if test -z "${name#*.ko}" -o -z "${name#*.ko.xz}";then echo $name;else
names="${names:+$names }$name"
fi
done
if test -n "$names";then
found="$(grep -E "/($(echo $names | sed -e 's/ /|/g' -e 's/[_-]/[_-]/g'))\\.ko(\.xz)?:" "$MODDIR/modules.dep" | cut -f1 -d:)"
not_found="$(echo $names | sed -e 's/ /\n/g' | grep -vE "($(echo $found | sed -e 's@[^ ]*/@@g' -e 's/\.ko\(\.xz\)\?//g' -e 's/ /|/g' -e 's/[_-]/[_-]/g'))")"
test -z "$not_found" || {
not_found="$(list_new_nondup "$missing_ok" $not_found)"
}
test -z "$not_found" || {
echo "ERROR: not found:" $not_found >&2
kill -10 $$
}
echo $found | sed -e 's@\(^\| \)\([^/]\)@\1'"$MODDIR"'/\2@g'
fi
}
strip_path_prefix() {
local prefix="$1" without_prefix tmp
shift
for fname;do
without_prefix="${fname#$prefix}"
while test "x$without_prefix" != "x${without_prefix#/*}";do
without_prefix="${without_prefix#/*}"
done
echo "$without_prefix"
done
}
add_builtin_to_missing_ok() {
local mod
for mod in $(sed -e 's@.*/@@' -e 's@\.ko\(\.xz\)\?$@@' $MODDIR/modules.builtin);do
missing_ok="${missing_ok:+$missing_ok }$mod"
done
}
test ! -e "$MODDIR/modules.builtin" || add_builtin_to_missing_ok
resolv_list="$(to_filenames $@)"
copy_list="$resolv_list"
while test -n "$resolv_list";do
resolv_list="$(list_new_nondup "$copy_list" $(to_filenames $(get_deps $resolv_list)))"
copy_list="$copy_list $resolv_list"
done
test -e "$outdir" || mkdir -p "$outdir"
for firmware in $(modinfo -F firmware $copy_list);do
fw_file="/lib/firmware/$firmware"
if test -e "$fw_file";then
fw_list="${fw_list:+$fw_list }$(list_new_nondup "$fw_list" $fw_file)"
else
echo "WARN: missing firmware: $firmware" >&2
fi
done
mkdir -p "$MODDIR_OUT"
(cd "$MODDIR"; tar c $(strip_path_prefix "$MODDIR" $copy_list)) | tar xv -C "$MODDIR_OUT"
test -z "$fw_list" || cp -v --parents $fw_list "$outdir"
depmod -b $outdir $KVERS