-
Notifications
You must be signed in to change notification settings - Fork 209
/
copyright_fix.sh
executable file
·54 lines (52 loc) · 1.44 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"
result=$(grep "+build" $i)
if [ $? -ne 1 ]
then
sed -i -e '5,32{R LICENSE' -e 'd}' $i
else
sed -i -e '2,31{R LICENSE' -e 'd}' $i
fi
fi
done
else
for i in $(find -name \*.go); do
result=$(grep "$searchStr" $i)
if [ $? -eq 1 ]
then
echo "Adding Copyright to $i"
result=$(grep "+build" $i)
if [ $? -ne 1 ]
then
echo $result > __temp__
echo -n >> __temp__
echo "/*" >> __temp__
cat LICENSE >> __temp__
echo -e "*/" >> __temp__
tail -n+2 $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
echo "Updating Copyright in $i"
sed -i "/$searchStr/c\\$copyLine" $i
fi
fi
done
fi