File: check_license_headers.bash

package info (click to toggle)
openvas-scanner 23.38.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,468 kB
  • sloc: ansic: 41,621; xml: 6,251; pascal: 3,723; yacc: 1,250; sh: 1,068; makefile: 333; sql: 282; javascript: 12
file content (33 lines) | stat: -rwxr-xr-x 1,027 bytes parent folder | download
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
#!/usr/bin/env bash

function comment_string () {
    ext=$1
    if [[ $ext == "c" || $ext == "h" || $ext == "rs" ]]; then
        echo "//"
    elif [[ $ext == "nasl" || $ext == "cmake" ]]; then
        echo "#"
    fi
}

any_missing_headers=0

exts="c h nasl cmake"

for ext in $exts; do
    find . -not -path "./rust/target/*" -not -path "./rust/crates/nasl-c-lib/tmp/*" -regex ".*\.\($ext\)" -print0 | while read -d $'\0' f; do
        header=$(head -n 3 "$f")
        if ! [[ "$header" =~ SPDX ]]; then
            echo "File does not contain license header: $f"
            any_missing_headers=1

            if [[ "$1" == add_header ]]; then
                tmpfile=$(mktemp)
                cp "$f" "$tmpfile"
                comment=$(comment_string $ext)
                echo -e "$comment SPDX-FileCopyrightText: 2025 Greenbone AG\n$comment\n$comment SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception\n" | cat - $tmpfile > "$f"
            fi
        fi
    done
done

exit $any_missing_headers