-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyright_fix.sh
executable file
·54 lines (52 loc) · 1.66 KB
/
copyright_fix.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
#!/bin/bash
currYear=`date +"%Y"`
searchStr="Copyright ©"
copyLine=`grep -h "$searchStr" LICENSE`
if [[ "$1" == "replace" ]]
then
for i in $(find -name \*.go); do
result=$(grep "$searchStr" $i)
if [ $? -ne 1 ]
then
echo "Replacing in $i"
# find the start and end line of the existing license
firstLine=$(($(grep -n -m 1 "\/\*" $i | cut -f1 -d:)+1))
lastLine=$(($(grep -n -m 1 "\*\/" $i | cut -f1 -d:)-1))
sed -i -e "$firstLine,$lastLine{R LICENSE" -e "d}" $i
fi
done
else
for i in $(find -name \*.go); do
result=$(grep "$searchStr" $i)
if [ $? -eq 1 ]
then
echo "Adding Copyright to $i"
# capture compilation directives
result=$(grep "[+:]build" $i)
if [ $? -ne 1 ]
then
echo "$result" > __temp__
echo -n >> __temp__
echo "/*" >> __temp__
cat LICENSE >> __temp__
echo -e "*/" >> __temp__
skipLines=$(($(grep -c "[+:]build" $i)+1))
tail -n+$skipLines $i >> __temp__
else
echo "/*" > __temp__
cat LICENSE >> __temp__
echo -e "*/\n" >> __temp__
cat $i >> __temp__
fi
mv __temp__ $i
else
currYear_found=$(echo $result | grep $currYear)
if [ $? -eq 1 ]
then
#TODO: handle multiple copyright lines properly
echo "Updating Copyright in $i"
sed -i "/$searchStr/c\\$copyLine" $i
fi
fi
done
fi