File: AddHeaders.sh

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (52 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (6)
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
#!/bin/bash

usage()
{
cat << EOF
usage: $0 options

This script adds a header to all files matching the provided pattern in the given directory

OPTIONS:
   -h      Show this message
   -l      license file 
   -d      directory to search
   -p      file pattern to match
EOF
}

license=
pattern=
directory=
while getopts "hl:p:d:" OPTION
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         l)
             license=$OPTARG
             ;;
         p)
             pattern=$OPTARG
             ;;
         d)
             directory=$OPTARG
             ;;
         ?)
             usage
             exit
             ;;
     esac
done

echo "Prepending ${license} to files with pattern ${pattern} in directory ${directory}"

for i in ${directory}/${pattern}
do
  if ! grep -q Copyright $i
  then
    cat ${license} $i >$i.new && mv $i.new $i
  fi
done