forked from mongodb-labs/mongo-web-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense.sh
executable file
·43 lines (37 loc) · 1.4 KB
/
license.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
#!/bin/bash
# applyLicense(path, check?)
# Applies/checks for licenses in the current file
function applyLicense {
# Pull filename and extension from arg
f=$(basename $1)
ext="${f##*.}"
# If a license file for the extension exists
if [[ -e licenses/LICENSE.$ext ]]; then
# Get the size of the license file and compare the file to the first
# size bytes of the source
filesize=$(wc -c < $1 | tr -d ' ')
dd if="$1" bs=1 count=$(wc -c < licenses/LICENSE.$ext | tr -d ' ') 2>/dev/null \
| diff licenses/LICENSE.$ext - &>/dev/null
# If they do not match and the file is not empty, output name of file
if [[ $? -ne 0 ]] && [[ $filesize -gt 0 ]]; then
echo $1
# If not run with --check flag, then prepend license to file
if [[ $2 != '--check' ]]; then
cp $1 licenses/temp$$
cat licenses/LICENSE.$ext licenses/temp$$ > $1
rm licenses/temp$$
fi
fi
fi
}
# Trap signals and remove temp file on interrupt
trap "rm -f licenses/temp$$" SIGHUP SIGINT SIGPIPE SIGTERM
# List all files in the current tree with certain exclusions, execute applyLicense foreach
find . -type f ! -path './frontend/lib/*' \
! -path './node_modules/*' \
! -path './venv/*' \
! -path './.git/*' \
! -path './frontend/dist/*' \
! -path './.grunt/*' \
! -path './_SpecRunner.html' \
| while read file; do applyLicense "$file" $1; done