Skip to content
Snippets Groups Projects
Commit 043e25b3 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

Update license_manager.sh

parent 16b596dc
No related branches found
No related tags found
No related merge requests found
Pipeline #7510 canceled
...@@ -12,6 +12,7 @@ line_end_mark="//--------LICENSE_END--------" ...@@ -12,6 +12,7 @@ line_end_mark="//--------LICENSE_END--------"
tmp=false tmp=false
mode="none" mode="none"
path="" path=""
exclude_folder=""
#recursive=true #recursive=true
license="" license=""
...@@ -45,6 +46,10 @@ for i in "$@"; do ...@@ -45,6 +46,10 @@ for i in "$@"; do
fi fi
shift # past argument=value shift # past argument=value
;; ;;
--exclude=*)
exclude_folder="${i#*=}"
shift # past argument=value
;;
*) *)
# unknown option # unknown option
;; ;;
...@@ -77,11 +82,19 @@ else ...@@ -77,11 +82,19 @@ else
fi fi
fi fi
echo "mode: ${mode}" if [ "$exclude_folder" == "" ]; then
echo "No folders will be excluded"
else
if [ -d "${path}/${exclude_folder}" ]; then
echo "Valid remove folder path: ${path}/${exclude_folder}"
fi
fi
if [ $mode == "none" ]; then if [ $mode == "none" ]; then
echo "Error: Script should be called with one of the following options: --update or --add" echo "Error: Script should be called with one of the following options: --update or --add"
exit 1 exit 1
else
echo "mode: ${mode}"
fi fi
# PATH (AND tmp FOLDER) # PATH (AND tmp FOLDER)
...@@ -93,10 +106,17 @@ if [ $tmp == true ]; then ...@@ -93,10 +106,17 @@ if [ $tmp == true ]; then
folder=${path}_tmp folder=${path}_tmp
fi fi
# LIST OF FILES TO BE ITERATED ON
if [ "$exclude_folder" == "" ]; then
file_list=$(find $folder -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
else
file_list=$(find $folder -path ${folder}/${exclude_folder} -prune -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
fi
# DETECT AND REMOVE EXISTING LICENSE # DETECT AND REMOVE EXISTING LICENSE
if [ $mode == "update" ]; then if [ "$mode" == "update" ]; then
echo "Recursely removing license header from all files (.c, .cpp, .h, .hpp)" 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') for i in $file_list
do do
if grep -Fxq ${line_start_mark} $i if grep -Fxq ${line_start_mark} $i
then then
...@@ -109,12 +129,11 @@ if [ $mode == "update" ]; then ...@@ -109,12 +129,11 @@ if [ $mode == "update" ]; then
#cat $i #cat $i
fi fi
done done
#TODO
fi fi
# ADD CONTENT OF license-file AT THE BEGINNING OF CODE FILES # ADD CONTENT OF license-file AT THE BEGINNING OF CODE FILES
echo "Recursively adding license header to all files (.c, .cpp, .h, .hpp)" 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') for i in $file_list
do do
if grep -Fxq ${line_start_mark} $i; then if grep -Fxq ${line_start_mark} $i; then
echo "skippping ${i}" echo "skippping ${i}"
...@@ -122,4 +141,4 @@ do ...@@ -122,4 +141,4 @@ do
( echo ${line_start_mark}$'\n//'; cat ${license}; echo $'//\n'${line_end_mark}; cat $i ) > temp_file ( echo ${line_start_mark}$'\n//'; cat ${license}; echo $'//\n'${line_end_mark}; cat $i ) > temp_file
mv temp_file $i mv temp_file $i
fi fi
done done
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment