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
Commits
6538f3a4
Commit
6538f3a4
authored
3 years ago
by
Joan Vallvé Navarro
Browse files
Options
Downloads
Patches
Plain Diff
[skip ci]
parent
4d5e9a0a
No related branches found
No related tags found
1 merge request
!18
Resolve "license headers"
Pipeline
#7454
skipped
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/license_manager.sh
+127
-0
127 additions, 0 deletions
scripts/license_manager.sh
with
127 additions
and
0 deletions
scripts/license_manager.sh
0 → 100644
+
127
−
0
View file @
6538f3a4
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment