98d1365625961b84a8a58bede8268a561fc0d418
[openssl.git] / util / openssl-update-copyright
1 #!/bin/bash
2 #
3 # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
4 #
5 # Licensed under the OpenSSL license (the "License").  You may not use
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]"
15
16 copyright_owner="The OpenSSL Project"
17
18 search="Copyright \(([cC]) \)\?\(${some_year}\)\(-${some_year}\)\? ${copyright_owner}"
19 replace="Copyright \1\2-${this_year} ${copyright_owner}"
20
21
22 function usage() {
23         cat >&2 <<EOF
24 usage: $myname [-h|--help] [file|directory] ...
25
26 Updates the year ranges of all OpenSSL copyright statements in the given
27 files or directories. (Directories are traversed recursively.)
28 EOF
29 }
30
31 if [ $# -eq 0 ]; then
32         usage
33         exit 0
34 fi
35
36
37 for arg in "$@"; do
38         case $arg in
39                 -h|--help)
40                         usage
41                         exit 0
42                         ;;
43                 -*)
44                         echo -e "illegal option: $arg\n" >& 2
45                         usage
46                         exit 1
47                         ;;
48                 *)
49                         if [ -f "$arg" ]; then
50                                 sed -i "s/${search}/${replace}/g" "$arg"
51                         elif [ -d "$arg" ]; then
52                                 find "$arg" -name '.[a-z]*' -prune -o -type f -exec sed -i "s/${search}/${replace}/g" {} +
53                         else
54                                 echo "$arg: no such file or directory" >&2
55                         fi
56                         ;;
57         esac
58 done