2022-02-09 19:42:28 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
currYear=`date +"%Y"`
|
|
|
|
searchStr="Copyright ©"
|
|
|
|
copyLine=`grep -h $searchStr LICENSE`
|
|
|
|
|
|
|
|
if [[ "$1" == "replace" ]]
|
|
|
|
then
|
2022-07-28 07:39:41 +03:00
|
|
|
for i in $(find -name \*.go); do
|
2022-02-09 19:42:28 +03:00
|
|
|
result=$(grep "$searchStr" $i)
|
|
|
|
if [ $? -ne 1 ]
|
|
|
|
then
|
|
|
|
echo "Replacing in $i"
|
2022-07-28 07:39:41 +03:00
|
|
|
result=$(grep "+build" $i)
|
2022-02-09 19:42:28 +03:00
|
|
|
if [ $? -ne 1 ]
|
|
|
|
then
|
2023-05-10 12:23:05 +03:00
|
|
|
sed -i -e '5,32{R LICENSE' -e 'd}' $i
|
2022-02-09 19:42:28 +03:00
|
|
|
else
|
|
|
|
sed -i -e '2,31{R LICENSE' -e 'd}' $i
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
for i in $(find -name \*.go); do
|
2022-07-28 07:39:41 +03:00
|
|
|
result=$(grep "$searchStr" $i)
|
|
|
|
if [ $? -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "Adding Copyright to $i"
|
|
|
|
result=$(grep "+build" $i)
|
|
|
|
if [ $? -ne 1 ]
|
2022-02-09 19:42:28 +03:00
|
|
|
then
|
2022-07-28 07:39:41 +03:00
|
|
|
echo $result > __temp__
|
|
|
|
echo -n >> __temp__
|
|
|
|
echo "/*" >> __temp__
|
|
|
|
cat LICENSE >> __temp__
|
|
|
|
echo -e "*/" >> __temp__
|
|
|
|
tail -n+2 $i >> __temp__
|
|
|
|
else
|
2022-02-09 19:42:28 +03:00
|
|
|
echo "/*" > __temp__
|
|
|
|
cat LICENSE >> __temp__
|
2022-08-27 17:17:39 +03:00
|
|
|
echo -e "*/\n" >> __temp__
|
2022-02-09 19:42:28 +03:00
|
|
|
cat $i >> __temp__
|
2022-07-28 07:39:41 +03:00
|
|
|
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
|
2022-02-09 19:42:28 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|