diff --git a/wolf_scripts/license_header_2023.txt b/wolf_scripts/license_header_2023.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba6dec6a0431ce25384233ada18e868179af0640 --- /dev/null +++ b/wolf_scripts/license_header_2023.txt @@ -0,0 +1,17 @@ +// Copyright (C) 2021-2023 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. diff --git a/wolf_scripts/license_manager.sh b/wolf_scripts/license_manager.sh index 8401b804c3f9e2455f053048d7e2a9ddd1ffdba1..59728c2dc481409b50d8d3943e78909ee3c4e418 100755 --- a/wolf_scripts/license_manager.sh +++ b/wolf_scripts/license_manager.sh @@ -1,11 +1,14 @@ #!/bin/bash +line_start_mark="//--------LICENSE_START--------" +line_end_mark="//--------LICENSE_END--------" + #options tmp=false +mode="none" path="" #recursive=true license="" -remove=false for i in "$@"; do case $i in @@ -21,6 +24,22 @@ for i in "$@"; do license="${i#*=}" shift # past argument=value ;; + --add) + mode="add" + if [ $mode == "update" ]; then + echo "Error: Script cannot be called with both options: --update or --add" + exit 1 + fi + shift # past argument=value + ;; + --update) + mode="update" + if [ $mode == "add" ]; then + echo "Error: Script cannot be called with both options: --update or --add" + exit 1 + fi + shift # past argument=value + ;; # --non-recursive) # recursive=false # shift # past argument=value @@ -45,7 +64,7 @@ else fi if [ "$license" == "" ]; then - echo "Error: Please, provide the path to the folder containing the code with --license-header=/my/license/header/file.txt" + 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 @@ -57,9 +76,16 @@ else fi fi +echo "mode: ${mode}" + +if [ $mode == "none" ]; then + echo "Error: Script should be called with one of the following options: --update or --add" + exit 1 +fi + # PATH (AND tmp FOLDER) folder=$path -if $tmp; then +if [ $tmp == true ]; then echo "Creating temporary folder: ${path}_tmp" mkdir -pv ${path}_tmp cp -a $path/. ${path}_tmp @@ -67,17 +93,34 @@ if $tmp; then fi # DETECT AND REMOVE EXISTING LICENSE -#TODO +if [ $mode == "update" ]; then + echo "Recursely removing license header from 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 ${line_start_mark} $i + then + echo " Removing license header from file ${i}" + line_start="$(grep -wn $line_start_mark ${i} | head -n 1 | cut -d: -f1)" + line_end="$(grep -wn $line_end_mark ${i} | head -n 1 | cut -d: -f1)" + echo ${line_start} + echo ${line_end} + #echo "${line_start},${line_end}d" $i + #sed $('${line_start},${line_end}d)' $i + awk -v m=$line_start -v n=$line_end 'm <= NR && NR <= n {next} {print}' $i > tmpfile && mv tmpfile $i + cat $i + fi + done + #TODO +fi # 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 + if grep -Fxq ${line_start_mark} $i; then echo "skippping ${i}" else - ( echo $'//LICENSE_START\n'; cat ${license}; echo $'\n//LICENSE_END\n'; cat $i ) > temp_file + ( echo ${line_start_mark}$'\n//'; cat ${license}; echo $'//\n'${line_end_mark}; cat $i ) > temp_file mv temp_file $i fi -done +done \ No newline at end of file