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

working script

parent 1a81c79d
No related branches found
No related tags found
1 merge request!427Resolve "Wolf license"
Pipeline #7264 failed
......@@ -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
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