github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/check.sh (about) 1 #!/usr/bin/env bash 2 3 # ./check.sh 4 # Adds licence header to every relevant file. 5 # NOTE: This script assumes that in any file there is either no licence header or exactly the one listed here. 6 7 GO_COPY_RIGHT="/*This file is part of kuberpult. 8 9 Kuberpult is free software: you can redistribute it and/or modify 10 it under the terms of the Expat(MIT) License as published by 11 the Free Software Foundation. 12 13 Kuberpult is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MIT License for more details. 17 18 You should have received a copy of the MIT License 19 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 20 21 Copyright 2023 freiheit.com*/" 22 23 YAML_COPY_RIGHT="# This file is part of kuberpult. 24 25 # Kuberpult is free software: you can redistribute it and/or modify 26 # it under the terms of the Expat(MIT) License as published by 27 # the Free Software Foundation. 28 29 # Kuberpult is distributed in the hope that it will be useful, 30 # but WITHOUT ANY WARRANTY; without even the implied warranty of 31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 # MIT License for more details. 33 34 # You should have received a copy of the MIT License 35 # along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 36 37 # Copyright 2023 freiheit.com" 38 39 RET_CODE=0 40 set eu -pipefail 41 42 check_file() { 43 x=$(head -n 15 $1 | wc -l) 44 if [ $x -lt 15 ]; 45 then 46 return 1 47 fi 48 # check the first 15 lines 49 lines=$(head -n 15 $1 ) 50 if [[ $2 -eq 1 ]]; 51 then 52 if [ "$lines" = "$GO_COPY_RIGHT" ]; 53 then 54 return 0 55 fi 56 else 57 if [ "$lines" = "$YAML_COPY_RIGHT" ]; 58 then 59 return 0 60 fi 61 fi 62 return 1 63 } 64 65 # Read all go files 66 go_files=$(find . -type f -name *.go) 67 68 69 fix_file() { 70 check_file $1 1 71 if [ $? -ne 0 ]; 72 then 73 echo "error in file $1" 74 RET_CODE=1 75 FILE=$(cat $1) 76 cat > $1 <<- EOF 77 $GO_COPY_RIGHT 78 $FILE 79 EOF 80 fi 81 } 82 83 fix_file_yaml_make() { 84 check_file $1 2 85 if [ $? -ne 0 ]; 86 then 87 echo "error in file $1" 88 RET_CODE=1 89 FILE=$(cat $1) 90 cat > $1 <<- EOF 91 $YAML_COPY_RIGHT 92 $FILE 93 EOF 94 fi 95 } 96 97 echo fixing go files... 98 for go_file in $go_files 99 do 100 fix_file "$go_file" 101 done 102 103 # Read all scss files 104 css_files=$(find . -type f -name '*.scss') 105 106 echo fixing css files... 107 for css_file in $css_files 108 do 109 if [[ $css_file =~ .*node_modules.* ]]; 110 then 111 continue 112 fi 113 fix_file "$css_file" 114 done 115 116 # Read all ts files 117 ts_files=$(find . -type f -name '*.ts') 118 119 echo fixing ts files... 120 for ts_file in $ts_files 121 do 122 if [[ $ts_file =~ .*node_modules.* ]]; 123 then 124 continue 125 fi 126 fix_file "$ts_file" 127 done 128 129 # Read all tsx files 130 tsx_files=$(find . -type f -name '*.tsx') 131 echo fixing tsx files... 132 for tsx_file in $tsx_files 133 do 134 if [[ $tsx_file =~ .*node_modules.* ]]; 135 then 136 continue 137 fi 138 fix_file "$tsx_file" 139 done 140 141 # Read all yaml files 142 yaml_files=$(find . -type f -name '*.yaml') 143 echo fixing yaml files... 144 for yaml_file in $yaml_files 145 do 146 if [[ $yaml_file =~ .*pnpm-lock.* ]] || [[ $yaml_file =~ .*Buildfile.yaml.* ]]; 147 then 148 continue 149 fi 150 fix_file_yaml_make $yaml_file 151 done 152 153 # Read all c/h files 154 c_files=$(find . -type f -name '*.[ch]') 155 echo fixing c files... 156 for c_file in $c_files 157 do 158 fix_file "$c_file" 159 done 160 161 162 # Read all Make files 163 make_files=$(find . -type f -name "Makefile*") 164 echo fixing make files... 165 for make_file in $make_files 166 do 167 if [[ $make_file =~ .*node_modules.* ]]; 168 then 169 continue 170 fi 171 fix_file_yaml_make "$make_file" 172 done 173 174 exit $RET_CODE