]> git.proxmox.com Git - mirror_linux-firmware.git/blame - copy-firmware.sh
copy-firmware: Fix test: unexpected operator
[mirror_linux-firmware.git] / copy-firmware.sh
CommitLineData
07b925b4
TI
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Copy firmware files based on WHENCE list
5#
6
7verbose=:
2de7abd4 8prune=no
ee91452d
EV
9# shellcheck disable=SC2209
10compress=cat
11compext=
07b925b4 12
2de7abd4
TR
13while test $# -gt 0; do
14 case $1 in
15 -v | --verbose)
ad2ce8be 16 # shellcheck disable=SC2209
2de7abd4
TR
17 verbose=echo
18 shift
19 ;;
20
21 -P | --prune)
22 prune=yes
23 shift
24 ;;
25
ee91452d 26 --xz)
0a51959c 27 if test "$compext" = ".zst"; then
ee91452d
EV
28 echo "ERROR: cannot mix XZ and ZSTD compression"
29 exit 1
30 fi
31 compress="xz --compress --quiet --stdout --check=crc32"
32 compext=".xz"
33 shift
34 ;;
35
36 --zstd)
0a51959c 37 if test "$compext" = ".xz"; then
ee91452d
EV
38 echo "ERROR: cannot mix XZ and ZSTD compression"
39 exit 1
40 fi
41 # shellcheck disable=SC2209
42 compress="zstd --compress --quiet --stdout"
43 compext=".zst"
44 shift
45 ;;
46
2de7abd4
TR
47 *)
48 if test "x$destdir" != "x"; then
ad2ce8be 49 echo "ERROR: unknown command-line options: $*"
2de7abd4
TR
50 exit 1
51 fi
52
53 destdir="$1"
54 shift
55 ;;
56 esac
57done
07b925b4 58
ad2ce8be 59# shellcheck disable=SC2162 # file/folder name can include escaped symbols
77f31a80 60grep '^File:' WHENCE | sed -e 's/^File: *//g;s/"//g' | while read f; do
07b925b4 61 test -f "$f" || continue
40fa2b20 62 install -d "$destdir/$(dirname "$f")"
ee91452d
EV
63 $verbose "copying/compressing file $f$compext"
64 if test "$compress" != "cat" && grep -q "^Raw: $f\$" WHENCE; then
65 $verbose "compression will be skipped for file $f"
66 cat "$f" > "$destdir/$f"
67 else
68 $compress "$f" > "$destdir/$f$compext"
69 fi
07b925b4
TI
70done
71
ad2ce8be 72# shellcheck disable=SC2162 # file/folder name can include escaped symbols
77f31a80 73grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do
ee91452d
EV
74 if test -L "$f$compext"; then
75 test -f "$destdir/$f$compext" && continue
76 $verbose "copying link $f$compext"
40fa2b20 77 install -d "$destdir/$(dirname "$f")"
ee91452d 78 cp -d "$f$compext" "$destdir/$f$compext"
2de7abd4
TR
79
80 if test "x$d" != "x"; then
67bf50e7 81 target="$(readlink "$f")"
2de7abd4
TR
82
83 if test "x$target" != "x$d"; then
84 $verbose "WARNING: inconsistent symlink target: $target != $d"
85 else
86 if test "x$prune" != "xyes"; then
87 $verbose "WARNING: unneeded symlink detected: $f"
88 else
89 $verbose "WARNING: pruning unneeded symlink $f"
ee91452d 90 rm -f "$f$compext"
2de7abd4
TR
91 fi
92 fi
93 else
94 $verbose "WARNING: missing target for symlink $f"
95 fi
96 else
40fa2b20 97 install -d "$destdir/$(dirname "$f")"
ee91452d
EV
98 $verbose "creating link $f$compext -> $d$compext"
99 ln -s "$d$compext" "$destdir/$f$compext"
2de7abd4 100 fi
07b925b4
TI
101done
102
103exit 0
2de7abd4
TR
104
105# vim: et sw=4 sts=4 ts=4