summaryrefslogtreecommitdiff
path: root/copy-firmware.sh
blob: bbacb925a03f9d4ccd0ad33c03d28f37f048199f (plain)
    1 #!/bin/sh
    2 # SPDX-License-Identifier: GPL-2.0
    3 #
    4 # Copy firmware files based on WHENCE list
    5 #
    6 
    7 verbose=:
    8 prune=no
    9 
   10 while test $# -gt 0; do
   11     case $1 in
   12         -v | --verbose)
   13             verbose=echo
   14             shift
   15             ;;
   16 
   17         -P | --prune)
   18             prune=yes
   19             shift
   20             ;;
   21 
   22         *)
   23             if test "x$destdir" != "x"; then
   24                 echo "ERROR: unknown command-line options: $@"
   25                 exit 1
   26             fi
   27 
   28             destdir="$1"
   29             shift
   30             ;;
   31     esac
   32 done
   33 
   34 grep '^File:' WHENCE | sed -e's/^File: *//g' -e's/"//g' | while read f; do
   35     test -f "$f" || continue
   36     $verbose "copying file $f"
   37     install -d $destdir/$(dirname "$f")
   38     cp -d "$f" $destdir/"$f"
   39 done
   40 
   41 grep -E '^Link:' WHENCE | sed -e's/^Link: *//g' -e's/-> //g' | while read f d; do
   42     if test -L "$f"; then
   43         test -f "$destdir/$f" && continue
   44         $verbose "copying link $f"
   45         install -d $destdir/$(dirname "$f")
   46         cp -d "$f" $destdir/"$f"
   47 
   48         if test "x$d" != "x"; then
   49             target=`readlink "$f"`
   50 
   51             if test "x$target" != "x$d"; then
   52                 $verbose "WARNING: inconsistent symlink target: $target != $d"
   53             else
   54                 if test "x$prune" != "xyes"; then
   55                     $verbose "WARNING: unneeded symlink detected: $f"
   56                 else
   57                     $verbose "WARNING: pruning unneeded symlink $f"
   58                     rm -f "$f"
   59                 fi
   60             fi
   61         else
   62             $verbose "WARNING: missing target for symlink $f"
   63         fi
   64     else
   65         $verbose "creating link $f -> $d"
   66         install -d $destdir/$(dirname "$f")
   67         ln -sf "$d" "$destdir/$f"
   68     fi
   69 done
   70 
   71 exit 0
   72 
   73 # vim: et sw=4 sts=4 ts=4

Generated by cgit