-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate-copyright.sh
executable file
·80 lines (63 loc) · 1.87 KB
/
update-copyright.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#------------------------------------------------------------------------------
#
# update-copyright-year.sh
#
# This script will bump the copyright year in all of the MantisBT source files
# including docbook
#
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Initialization
#
# Reference file to retrieve current copyright year
if [ -z "$REF_FILE" ]
then
REF_FILE=core.php
fi
if [ ! -r "$REF_FILE" ]
then
echo "ERROR: Reference file '$REF_FILE' not found in '$PWD'"
echo "The script must be executed in the MantisBT root directory"
exit 1
fi
# Regular expressions
REGEX_MANTISBT="Copyright .*[0-9]{4} +MantisBT Team"
REGEX_SOAP_API="Copyright .*[0-9]{4} +Victor Boctor"
REGEX_DOCS='<year>[0-9]{4}<\/year>|<!ENTITY YEAR "[0-9]{4}">'
# Determine copyright year based on reference file
COPYRIGHT_YEAR_OLD=$(sed -rn "/$REGEX_MANTISBT/ s/^.*- *([0-4]{4}) .*$/\1/p" $REF_FILE)
COPYRIGHT_YEAR_NEW=$(( $COPYRIGHT_YEAR_OLD + 1 ))
#------------------------------------------------------------------------------
# Replace function
#
function bump_copyright()
{
git grep -E -l "$1" |
xargs sed -i.bak -r -e "/$1/ s/$COPYRIGHT_YEAR_OLD/$COPYRIGHT_YEAR_NEW/"
}
#------------------------------------------------------------------------------
# Main
#
echo "Ready to update MantisBT copyright year from $COPYRIGHT_YEAR_OLD to $COPYRIGHT_YEAR_NEW"
echo "Press enter to proceed"
read
if [ -n "$REPLY" ]
then
echo "Aborting !"
exit
fi
# MantisBT files
echo "Updading MantisBT core files"
bump_copyright "$REGEX_MANTISBT"
# SOAP API files
echo "Updading SOAP API files"
bump_copyright "$REGEX_SOAP_API"
# Documentation
echo "Updading Documentation"
bump_copyright "$REGEX_DOCS"
# Cleanup
echo
echo "Updates complete"
echo "Removing backup files"
find . -name "*.bak" -delete