Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gnss_utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
algorithms
gnss_utils
Merge requests
!18
Resolve "license headers"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "license headers"
16-license-headers
into
devel
Overview
0
Commits
9
Pipelines
8
Changes
1
Merged
Joan Vallvé Navarro
requested to merge
16-license-headers
into
devel
3 years ago
Overview
0
Commits
9
Pipelines
8
Changes
1
Expand
Closes
#16 (closed)
Edited
3 years ago
by
Joan Vallvé Navarro
0
0
Merge request reports
Viewing commit
6538f3a4
Prev
Next
Show latest version
1 file
+
127
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
6538f3a4
[skip ci]
· 6538f3a4
Joan Vallvé Navarro
authored
3 years ago
scripts/license_manager.sh
0 → 100644
+
127
−
0
Options
#!/bin/bash
# ------ WOLF license_manager script ------
#
# This script is used for managing the license headers of code files (.h, .c, .cpp, .hpp)
# This file is automatically called by the CI in gitlab.
line_start_mark
=
"//--------LICENSE_START--------"
line_end_mark
=
"//--------LICENSE_END--------"
#options
tmp
=
false
mode
=
"none"
path
=
""
#recursive=true
license
=
""
for
i
in
"
$@
"
;
do
case
$i
in
--temp
)
tmp
=
true
shift
# past argument=value
;;
--path
=
*
)
path
=
"
${
i
#*=
}
"
shift
# past argument=value
;;
--license-header
=
*
)
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
;;
*
)
# unknown option
;;
esac
done
# 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
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
==
true
]
;
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
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
${
line_start_mark
}
$i
;
then
echo
"skippping
${
i
}
"
else
(
echo
${
line_start_mark
}
$'
\n
//'
;
cat
${
license
}
;
echo
$'//
\n
'
${
line_end_mark
}
;
cat
$i
)
>
temp_file
mv
temp_file
$i
fi
done
\ No newline at end of file
Loading