aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2014-12-30 16:53:03 -0800
committerPhil Burk <[email protected]>2014-12-30 16:53:03 -0800
commit534969d42ca5168d645678345cd21242fe41f389 (patch)
treee8f5d1cba1ec57685e76ceb923d8da25a7846cfb /scripts
parenta4d8ca95178d2e3acfc3299a4b73e84c2646d24e (diff)
Initial commit of code.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/addlicenses.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/addlicenses.sh b/scripts/addlicenses.sh
new file mode 100755
index 0000000..112dfff
--- /dev/null
+++ b/scripts/addlicenses.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+echo "Prepend Apache Licenses to JSyn source."
+
+
+file_year=0
+files_missed=0
+files_processed=0
+license_dir=$HOME/Documents/workspace/JSyn/licenses
+
+function prepend_license_file {
+ filename=$1
+ year=$2
+ add_author=0
+ if [ $year -eq 0 ]; then
+ year=2009
+ add_author=1
+ fi
+ grep "Licensed under the Apache License" $filename > /dev/null
+ if [ $? -eq 1 ]; then
+ mv $filename temp2.txt
+ cat $license_dir/license_part1.txt >temp1.txt
+ echo " * Copyright $year Phil Burk, Mobileer Inc" >> temp1.txt
+ cat $license_dir/license_part2.txt >> temp1.txt
+ if [ $add_author -eq 1 ]; then
+ cat $license_dir/license_part3.txt >> temp1.txt
+ fi
+ cat temp1.txt temp2.txt > $filename
+ rm temp1.txt
+ rm temp2.txt
+ (( files_processed += 1 ))
+ fi
+}
+
+function process_file_year {
+ filename=$1
+ year=$2
+ grep "(C) $year" $filename > /dev/null
+ if [ $? -eq 0 ]; then
+ # echo "prepend $year license file"
+ prepend_license_file $filename $year
+ file_year=$year
+ fi
+}
+
+function process_java_file {
+ filename=$1
+ # echo "process $filename"
+ file_year=0
+ N=1997
+ while [[ $N -lt 2015 && $file_year -eq 0 ]]; do
+ process_file_year $filename $N
+ let N=N+1
+ done
+ if [ $file_year -eq 0 ]; then
+ (( files_missed += 1 ))
+ echo "FILE $1 did not have a copyright."
+ prepend_license_file $filename 0
+ fi
+}
+
+function process_directory {
+ for filename in *.java; do
+ if [ -e $filename ]; then
+ process_java_file $filename
+ fi
+ done
+ # now scan subdirectories
+ for filename in *; do
+ if [ -d "$filename" ]; then
+ echo "$filename is a directory"
+ cd $filename
+ pwd
+ process_directory
+ cd ../
+ fi
+ done
+}
+
+process_directory
+# prepend_license_file src/com/jsyn/JSyn.java 2007
+echo "$files_missed files missed"
+echo "$files_processed files processed"