2019-08-15 19:52:36 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Read WHENCE from stdin and install the compressed firmware files into DESTDIR.
|
2019-10-23 11:50:13 +02:00
|
|
|
# The file list for each topic is created as files-xxx under the current dir.
|
2019-08-15 19:52:36 +02:00
|
|
|
#
|
2019-10-23 11:50:13 +02:00
|
|
|
# usage: install-split.sh [-v] topics.list DESTDIR < WHENCE
|
2019-08-15 19:52:36 +02:00
|
|
|
#
|
|
|
|
|
2019-10-23 11:50:13 +02:00
|
|
|
verbose=:
|
|
|
|
|
|
|
|
if [ x"$1" = x"-v" ]; then
|
|
|
|
verbose=echo
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2019-08-15 19:52:36 +02:00
|
|
|
topics="$1"
|
|
|
|
DESTDIR="$2"
|
2020-11-11 14:28:48 +01:00
|
|
|
fwdir=${3:-/lib/firmware}
|
2019-08-15 19:52:36 +02:00
|
|
|
dest=$DESTDIR/$fwdir
|
|
|
|
|
|
|
|
do_compress=1
|
|
|
|
|
|
|
|
if [ -n "$do_compress" ]; then
|
|
|
|
cext=".xz"
|
|
|
|
else
|
|
|
|
cext=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
make_dirs () {
|
|
|
|
local f="$1"
|
|
|
|
mkdir -p $(dirname "$dest/$f")
|
|
|
|
local d=$(dirname "$f")
|
|
|
|
if [ "$d" != "." ]; then
|
|
|
|
while true; do
|
|
|
|
if ! grep -q '%dir '"$fwdir/$d"'$' files-$topic; then
|
|
|
|
echo "%dir $fwdir/$d" >> files-$topic
|
|
|
|
fi
|
|
|
|
case "$d" in
|
|
|
|
*/*) d=${d%/*};;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_link () {
|
|
|
|
local f="$1"
|
2019-10-23 11:50:13 +02:00
|
|
|
local lf="$2"
|
2022-10-03 13:46:36 +02:00
|
|
|
local src
|
2019-08-15 19:52:36 +02:00
|
|
|
test -f "$dest/$f$cext" && return
|
2022-10-03 13:46:36 +02:00
|
|
|
if [ -z "$lf" ]; then
|
|
|
|
lf=$(readlink "$f")
|
|
|
|
src="$lf"
|
|
|
|
else
|
|
|
|
src="${f%/*}"
|
|
|
|
if [ "$src" = "$f" ]; then
|
|
|
|
src="$lf"
|
|
|
|
else
|
|
|
|
src="$src/$lf"
|
|
|
|
fi
|
|
|
|
fi
|
2019-08-15 19:52:36 +02:00
|
|
|
make_dirs "$f"
|
2022-10-03 13:46:36 +02:00
|
|
|
if [ -d "$dest/$src" ]; then
|
|
|
|
ln -sf "$lf" "$dest/$f"
|
|
|
|
echo "\"$fwdir/$f\"" >> files-$topic
|
|
|
|
$verbose "Link: $lf -> $f (directory) for topic $topic"
|
|
|
|
else
|
|
|
|
ln -sf "$lf$cext" "$dest/$f$cext"
|
|
|
|
echo "\"$fwdir/$f$cext\"" >> files-$topic
|
|
|
|
$verbose "Link: $lf$cext -> $f$cext for topic $topic"
|
|
|
|
fi
|
2019-08-15 19:52:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_file () {
|
|
|
|
local f="$1"
|
|
|
|
test -f "$dest/$f$cext" && return
|
|
|
|
make_dirs "$f"
|
|
|
|
install -c -m 0644 "$f" $(dirname "$dest/$f")
|
2021-07-27 18:13:55 +02:00
|
|
|
test -n "$do_compress" && xz -f -C crc32 --lzma2=dict=2MiB "$dest/$f"
|
2019-08-15 19:52:36 +02:00
|
|
|
echo "\"$fwdir/$f$cext\"" >> files-$topic
|
2019-10-23 11:50:13 +02:00
|
|
|
$verbose "Copy: $f$cext for topic $topic"
|
2019-08-15 19:52:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub="xxx"
|
|
|
|
while read l; do
|
|
|
|
test -z "$l" && continue
|
|
|
|
case "$l" in
|
|
|
|
----*)
|
|
|
|
sub=""
|
|
|
|
topic=""
|
|
|
|
;;
|
|
|
|
Driver:*)
|
|
|
|
test -n "$sub" && continue
|
|
|
|
sub=$(echo "$l" | sed -e's/Driver: *//' -e's/[ :].*$//')
|
|
|
|
m=$(grep -m1 "^$sub": "$topics" | sed -e's/^.*:[[:space:]]*//')
|
|
|
|
test -z "$m" && continue
|
|
|
|
set -- $m
|
|
|
|
topic="$1"
|
|
|
|
if [ "$topic" = "SKIP" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2019-10-23 11:50:13 +02:00
|
|
|
$verbose "Switching to topic $topic"
|
2019-08-15 19:52:36 +02:00
|
|
|
if [ -n "$topic" ]; then
|
|
|
|
if [ ! -s files-$topic ]; then
|
2020-11-11 14:28:48 +01:00
|
|
|
echo "%dir $fwdir" > files-$topic
|
2019-08-15 19:52:36 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
File:*)
|
|
|
|
test "$topic" = "SKIP" && continue
|
|
|
|
if [ -z "$topic" ]; then
|
|
|
|
echo "ERROR: no topic found for $l"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-27 11:02:43 +01:00
|
|
|
f=$(echo "$l" | sed -e's/^File: *//' -e's/"//g' -e's/\\//g')
|
2019-08-15 19:52:36 +02:00
|
|
|
if [ -L "$f" ]; then
|
|
|
|
copy_link "$f"
|
|
|
|
else
|
|
|
|
copy_file "$f"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
Link:*)
|
|
|
|
test "$topic" = "SKIP" && continue
|
|
|
|
if [ -z "$topic" ]; then
|
|
|
|
echo "ERROR: no topic found for $l"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-27 11:02:43 +01:00
|
|
|
f=$(echo "$l" | sed -e's/^Link: *//' -e's/ *->.*$//' -es'/\\//g')
|
|
|
|
d=$(echo "$l" | sed -e's/^.*-> *//' -e's/\\//g')
|
|
|
|
copy_link "$f" "$d"
|
2019-08-15 19:52:36 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2020-10-11 23:35:11 +02:00
|
|
|
|
|
|
|
exit 0
|