| 1 | #!/bin/sh |
| 2 | # SPDX-FileCopyrightText: 2020-2026 Jonas Smedegaard <[email protected] |
| 3 | # |
| 4 | # SPDX-FileCopyrightText: 2020 Purism, SPC |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-3.0-or-later |
| 7 | # |
| 8 | # Description: helper script to update copyright_hints |
| 9 | # |
| 10 | # Depends: |
| 11 | # licensecheck, |
| 12 | # libimage-exiftool-perl, |
| 13 | |
| 14 | set -eu |
| 15 | |
| 16 | EXT_skip='ods zip' |
| 17 | EXT_meta='gif jpg pdf png' |
| 18 | #MERGE_LICENSES=1 |
| 19 | |
| 20 | ext2re() { perl -sE 'printf ".*\.(%s)", join "|", split " ", $e' -- -e="$1"; } |
| 21 | ext2opt() { perl -sE 'say map {" $o $_"} split " ", $e' -- -o="$1" -e="$2"; } |
| 22 | |
| 23 | RE_skip=$(ext2re "$EXT_skip") |
| 24 | RE_meta=$(ext2re "$EXT_meta") |
| 25 | RE_debian='debian/(changelog|copyright(_hints)?|source/lintian-overrides)' |
| 26 | RE_hint='skip|meta' |
| 27 | |
| 28 | # cleanup stray hint files from a previous run |
| 29 | find ./* -type f -regextype posix-egrep -regex "^\./.*:($RE_hint)$" -delete |
| 30 | |
| 31 | echo 'skip binary files without parsable metadata ...' 1>&2 |
| 32 | find ./* -type f -regextype posix-egrep -regex "^\./($RE_skip)$" \ |
| 33 | -exec sh -c 'echo "License: UNKNOWN" > "$1:skip"' shell {} ';' |
| 34 | |
| 35 | echo 'extract metadata from binary files ...' 1>&2 |
| 36 | exiftool '-textOut!' %d%f.%e:meta -short -short -recurse -extractEmbedded \ |
| 37 | $(ext2opt -ext "$EXT_meta") \ |
| 38 | -- ./* |
| 39 | |
| 40 | # check for copyright and licensing statements |
| 41 | licensecheck --copyright --deb-machine --recursive --lines 0 --check '.*' \ |
| 42 | --ignore "^($RE_skip|$RE_meta|$RE_debian)$" ${MERGE_LICENSES:+--merge-licenses} \ |
| 43 | -- * > debian/copyright_hints |
| 44 | |
| 45 | # strip hint suffix |
| 46 | sed -i -e 's/:meta$//' -e 's/:skip$//' debian/copyright_hints |
| 47 | |
| 48 | # cleanup hint files |
| 49 | find ./* -type f -regextype posix-egrep -regex "^\./.*:($RE_hint)$" -delete |