|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +notice='################################################################################ |
| 4 | +# Copyright The Script It Authors |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +################################################################################' |
| 18 | + |
| 19 | +# Run from the root of the project |
| 20 | +cd $(dirname ${BASH_SOURCE[0]})/.. |
| 21 | + |
| 22 | +# Set FIX=1 in the env to fix missing headers |
| 23 | +fix=${FIX:-"0"} |
| 24 | + |
| 25 | +# Function helper to check and optionally fix headers |
| 26 | +function check_file { |
| 27 | + fname=$1 |
| 28 | + second_line=$(cat $fname | head -n2 | tail -n1) |
| 29 | + if [ "$second_line" != "# Copyright The Script It Authors" ] |
| 30 | + then |
| 31 | + if [ "$fix" == "1" ] |
| 32 | + then |
| 33 | + echo "Fixing missing copyright in $fname" |
| 34 | + file_content=$(cat $fname) |
| 35 | + echo "$notice" > $fname |
| 36 | + echo "$file_content" >> $fname |
| 37 | + else |
| 38 | + echo "Found missing copyright in $fname" |
| 39 | + return 1 |
| 40 | + fi |
| 41 | + fi |
| 42 | +} |
| 43 | + |
| 44 | +exit_code=0 |
| 45 | +for fname in $(find scriptit -name "*.py") |
| 46 | +do |
| 47 | + check_file $fname |
| 48 | + file_exit_code=$? |
| 49 | + if [ "$file_exit_code" != "0" ] |
| 50 | + then |
| 51 | + exit_code=$(expr "$exit_code" "+" "$file_exit_code") |
| 52 | + fi |
| 53 | +done |
| 54 | +exit $exit_code |
0 commit comments