v0.2.50..v0.2.51 changeset UpdateAllCopyrightHeaders.sh
Garret Voltz edited this page Jan 15, 2020
·
1 revision
diff --git a/scripts/copyright/UpdateAllCopyrightHeaders.sh b/scripts/copyright/UpdateAllCopyrightHeaders.sh
index 9d8fd28..c1a63ec 100755
--- a/scripts/copyright/UpdateAllCopyrightHeaders.sh
+++ b/scripts/copyright/UpdateAllCopyrightHeaders.sh
@@ -15,6 +15,7 @@
# 9 = Unrecognized updateMode.
# 10 = Python error(s) found.
# 11 = Log file not found.
+# 12 = Search directory not found
GetExitCodeText(){
if [ $1 > 0 ]; then
@@ -55,6 +56,9 @@ GetExitCodeText(){
"11")
echo " Error: Log file not found"
;;
+ "12")
+ echo " Error: Search directory not found"
+ ;;
*)
echo " Error: Unknown"
;;
@@ -62,46 +66,60 @@ GetExitCodeText(){
fi
}
+
+ExitScript() {
+ echo "Exit code: $1"
+ GetExitCodeText $1
+ exit $1
+}
+
updateMode=false
exitCode=0
# Determine the log file name.
NOW=$(date +"%Y-%m-%d_%H:%M:%S")
-logFile="$HOOT_HOME/updateCopyrightHeader_$NOW.log"
+logBase="$HOOT_HOME/updateCopyrightHeader_$NOW"
+logFile="$logBase.log"
+logJobs="$logBase.jobs.log"
echo "logFile: " $logFile
-#exit 0
-# Updates all the copyright headers in all source directories.
-for i in $HOOT_HOME/hoot-cmd $HOOT_HOME/hoot-core $HOOT_HOME/hoot-core-test $HOOT_HOME/hoot-js $HOOT_HOME/hoot-rnd $HOOT_HOME/hoot-services $HOOT_HOME/hoot-test $HOOT_HOME/tbs $HOOT_HOME/tgs
-do
- #echo $i
- cd $i
- if [ $# -eq 0 ]; then
- # No arguments/parameters which means we are only CHECKING copyright headers.
- updateMode=false
- $HOOT_HOME/scripts/copyright/UpdateDirCopyrightHeaders.sh $logFile
- exitCode=$?
+# Check the argument count and content
+if [ $# -eq 0 ]; then
+ updateMode=false
+ updateParam=""
+elif [ $# -eq 1 ]; then
+ if [ $1 == '--update' ] || [ $1 == '-u' ]; then
+ updateMode=true
+ updateParam='-u'
else
- if [ $? -eq 1 ]; then
- if [ $1 == '--update' ] || [ $1 == '-u' ]; then
- updateMode=true
- $HOOT_HOME/scripts/copyright/UpdateDirCopyrightHeaders.sh $logFile $1
- exitCode=$?
- else
- # Unrecognized parameter.
- exitCode=6
- fi
- else
- # Too many arguments.
- exitCode=7
- fi
+ ExitScript 6 # Unrecognized parameter
fi
- echo $i "exitCode:" $exitCode
- # Output the exit code message if non-zero.
- if [[ $exitCode -ne 0 ]]; then
- GetExitCodeText $exitCode
- fi
-done
+else
+ ExitScript 7 # Too many arguments
+fi
+
+# Check for the existance of the license template
+if [ ! -f $HOOT_HOME/scripts/copyright/LicenseTemplate.txt ]; then
+ ExitScript 1 # LicenseTemplate.txt not found
+fi
+
+# Run the checks in parallel
+parallel --joblog $logJobs $HOOT_HOME/scripts/copyright/UpdateDirCopyrightHeaders.sh {} $logFile $updateParam ::: \
+ $HOOT_HOME/hoot-core \
+ $HOOT_HOME/hoot-core-test \
+ $HOOT_HOME/hoot-services \
+ $HOOT_HOME/tgs \
+ $HOOT_HOME/hoot-js \
+ $HOOT_HOME/hoot-rnd \
+ $HOOT_HOME/tbs \
+ $HOOT_HOME/hoot-test \
+ $HOOT_HOME/hoot-cmd
+
+# Get the first non-zero exit status from the parallel command
+codes=`tail -n +2 $logJobs | awk '{print $7}' | grep "[1-9]" | head -n 1`
+if [ -z "$codes" ]; then
+ exitCode=$codes
+fi
# Now examine the log file contents only if exitCode is 0.
if [[ $exitCode -eq 0 ]]; then
@@ -174,7 +192,4 @@ if [[ $exitCode -eq 0 ]]; then
fi
fi
-echo "exitCode:" $exitCode
-GetExitCodeText $exitCode
-exit $exitCode
-
+ExitScript $exitCode