diff --git a/wolf_scripts/license_text.txt b/wolf_scripts/license_header_2022.txt similarity index 100% rename from wolf_scripts/license_text.txt rename to wolf_scripts/license_header_2022.txt diff --git a/wolf_scripts/license_manager.sh b/wolf_scripts/license_manager.sh old mode 100644 new mode 100755 index 9323da065fe0547e2e2493dcfeb1f69acdb88403..8401b804c3f9e2455f053048d7e2a9ddd1ffdba1 --- a/wolf_scripts/license_manager.sh +++ b/wolf_scripts/license_manager.sh @@ -2,9 +2,10 @@ #options tmp=false -path=$PWD -recursive=true +path="" +#recursive=true license="" +remove=false for i in "$@"; do case $i in @@ -16,38 +17,67 @@ for i in "$@"; do path="${i#*=}" shift # past argument=value ;; - --non-recursive) - recursive=false - shift # past argument=value - ;; - --license-file=*) + --license-header=*) license="${i#*=}" shift # past argument=value ;; +# --non-recursive) +# recursive=false +# shift # past argument=value +# ;; *) # unknown option ;; esac done -echo "tmp = ${tmp}" -echo "path = ${path}" -echo "recursive = ${recursive}" -echo "license = ${license} containing:" -cat ${license} +# check options +if [ "$path" == "" ]; then + echo 'Please, provide the path to the folder containing the code with --path=/my/folder/code' + exit 1 +else + if [ -d "$path" ]; then + echo "Valid path: ${path}" + else + echo "Error: ${path} not found. Can not continue." + exit 1 + fi +fi + +if [ "$license" == "" ]; then + echo "Error: Please, provide the path to the folder containing the code with --license-header=/my/license/header/file.txt" + exit 1 +else + if [ -f "$license" ]; then + echo "Valid license header file: ${license} containing:" + cat ${license} + else + echo "Error: License header file ${license} not found. Can not continue." + exit 1 + fi +fi # PATH (AND tmp FOLDER) folder=$path -if [ $tmp ]; then -mkdir -pv ${path}_tmp -cp -a $path/. ${path}_tmp -folder=${path}_tmp +if $tmp; then + echo "Creating temporary folder: ${path}_tmp" + mkdir -pv ${path}_tmp + cp -a $path/. ${path}_tmp + folder=${path}_tmp fi # DETECT AND REMOVE EXISTING LICENSE #TODO # ADD CONTENT OF license-file AT THE BEGINNING OF CODE FILES +echo "Recursively adding license header to all files (.c, .cpp, .h, .hpp)" for i in $(find $folder -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp') do + if grep -Fxq "//LICENSE_START" $i + then + echo "skippping ${i}" + else + ( echo $'//LICENSE_START\n'; cat ${license}; echo $'\n//LICENSE_END\n'; cat $i ) > temp_file + mv temp_file $i + fi done