annual_copyright_updater.sh 1.54 KB
Newer Older
1
#!/bin/bash
2
# Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
3 4 5 6 7 8 9 10 11 12 13 14 15
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

16
if [[ "$#" -eq 0 ]]; then
17 18 19 20
  dirs=$(pwd)
else
  dirs=$@
fi
21

22 23
original_wd=$(pwd)

24
for var in $dirs; do
25 26 27 28 29 30 31 32 33 34 35

  if [ ! -d $var ] ; then
    echo "$var is not a directory. Skipping"
    continue
  fi

  cd $var

  year=$(date "+%Y")
  last_year=$(($year - 1))

36
  search="\\[1999-[0-9]*\\] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute"
37
  replacement="[1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute\nCopyright [2016] EMBL-European Bioinformatics Institute"
38 39 40 41 42

  echo "About to scan $(pwd) for files to replace '$search' with '$replacement'"

  for file in $(grep -R --files-with-matches "$search" .); do
    echo "Replacing date in $file"
43
    if [ "$(uname)" = "Darwin" ]; then
44
      LC_CTYPE=C LANG=C sed -i '' -e "s/$search/$replacement/g" $file
45 46 47
    else
      sed --in-place -e "s/$search/$replacement/g" $file
    fi
48 49 50
  done

  cd $original_wd
51
done