]>
Commit | Line | Data |
---|---|---|
433a2e03 | 1 | #!/usr/bin/env bash |
b26d696c DMSP |
2 | # |
3 | # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. | |
4 | # | |
9059ab42 | 5 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
b26d696c DMSP |
6 | # this file except in compliance with the License. You can obtain a copy |
7 | # in the file LICENSE in the source distribution or at | |
8 | # https://www.openssl.org/source/license.html | |
9 | ||
10 | ||
11 | myname="$(basename $0)" | |
12 | ||
13 | this_year="$(date '+%Y')" | |
14 | some_year="[12][0-9][0-9][0-9]" | |
433a2e03 | 15 | year_range="(${some_year})(-${some_year})?" |
b26d696c DMSP |
16 | |
17 | copyright_owner="The OpenSSL Project" | |
433a2e03 | 18 | copyright="Copyright .*${year_range} .*${copyright_owner}" |
b26d696c | 19 | |
433a2e03 DMSP |
20 | # sed_script: |
21 | # for all lines that contain ${copyright} : { | |
22 | # replace years yyyy-zzzz (or year yyyy) by yyyy-${this_year} | |
23 | # replace repeated years yyyy-yyyy by yyyy | |
24 | # } | |
25 | sed_script="/${copyright}/{ s/${year_range}/\1-${this_year}/ ; s/(${some_year})-\1/\1/ }" | |
b26d696c DMSP |
26 | |
27 | function usage() { | |
28 | cat >&2 <<EOF | |
29 | usage: $myname [-h|--help] [file|directory] ... | |
30 | ||
31 | Updates the year ranges of all OpenSSL copyright statements in the given | |
32 | files or directories. (Directories are traversed recursively.) | |
33 | EOF | |
34 | } | |
35 | ||
36 | if [ $# -eq 0 ]; then | |
37 | usage | |
38 | exit 0 | |
39 | fi | |
40 | ||
41 | ||
42 | for arg in "$@"; do | |
43 | case $arg in | |
44 | -h|--help) | |
45 | usage | |
46 | exit 0 | |
47 | ;; | |
48 | -*) | |
49 | echo -e "illegal option: $arg\n" >& 2 | |
50 | usage | |
51 | exit 1 | |
52 | ;; | |
53 | *) | |
54 | if [ -f "$arg" ]; then | |
433a2e03 | 55 | sed -E -i "${sed_script}" "$arg" |
b26d696c | 56 | elif [ -d "$arg" ]; then |
433a2e03 | 57 | find "$arg" -name '.[a-z]*' -prune -o -type f -exec sed -E -i "${sed_script}" {} + |
b26d696c DMSP |
58 | else |
59 | echo "$arg: no such file or directory" >&2 | |
60 | fi | |
61 | ;; | |
62 | esac | |
63 | done |