-
Notifications
You must be signed in to change notification settings - Fork 1
/
addmod.sh
executable file
·96 lines (79 loc) · 2.17 KB
/
addmod.sh
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
#!/bin/bash
# Add modules to an LZMA compressed initramfs
# Copyright (C) 2007-2010 Daniel Collins <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
tmp="addmod.tmp"
initramfs=""
abort() {
if [ $# -eq "1" ]
then
echo "$1" 1>&2
fi
rm -rf "$tmp"
exit 1
}
cprog() {
if which "$1" > /dev/null; then
return 0
fi
abort "No executable '$1' program found in \$PATH"
}
if [ $# -lt 2 ]; then
abort "Usage: $0 <initramfs> <module> [<module> ...]"
fi
cprog tar
cprog lzcat
cprog find
cprog cpio
cprog lzma
rm -rf "$tmp"
mkdir -p "$tmp/modules/"
for mod in "$@"
do
if [ -z "$initramfs" ]
then
initramfs="$mod"
else
is_ko=`echo "$mod" | grep -E '\.ko$'`
is_tar=`echo "$mod" | grep -E '\.(tar(\.(gz|bz2))?|tgz)$'`
is_tlz=`echo "$mod" | grep -E '\.(tar\.lzma|tlz)$'`
if [ -n "$is_ko" ]
then
cp "$mod" "$tmp/modules/" || abort
fi
if [ -n "$is_tar" ]
then
tar -xf "$mod" -C "$tmp/modules/" || abort
fi
if [ -n "$is_tlz" ]
then
# TAR is really stupid
tar --lzma -xf "$mod" -C "$tmp/modules/" || abort
fi
if [ -z "$is_ko" -a -z "$is_tar" -a -z "$is_tlz" ]
then
abort "Unknown file extension: $mod"
fi
fi
done
lzcat -S "" "$initramfs" > "$tmp/initramfs.cpio" || abort
for f in `cpio -it --quiet < "$tmp/initramfs.cpio" | egrep '^modules\/.+'`
do
rm -f "$tmp/$f"
done
bash -c "cd \"$tmp\" && find modules -iname '*.ko' | cpio -o --format=newc --quiet --append -F initramfs.cpio" || abort
lzma -9 "$tmp/initramfs.cpio" -c > "$initramfs" || abort
rm -rf "$tmp"