Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
7c1de2ba
Commit
7c1de2ba
authored
3 years ago
by
Joan Vallvé Navarro
Browse files
Options
Downloads
Patches
Plain Diff
script working!
parent
5661c55c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!427
Resolve "Wolf license"
Pipeline
#7276
failed
3 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wolf_scripts/license_header_2023.txt
+17
-0
17 additions, 0 deletions
wolf_scripts/license_header_2023.txt
wolf_scripts/license_manager.sh
+51
-8
51 additions, 8 deletions
wolf_scripts/license_manager.sh
with
68 additions
and
8 deletions
wolf_scripts/license_header_2023.txt
0 → 100644
+
17
−
0
View file @
7c1de2ba
// 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/>.
This diff is collapsed.
Click to expand it.
wolf_scripts/license_manager.sh
+
51
−
8
View file @
7c1de2ba
#!/bin/bash
#!/bin/bash
line_start_mark
=
"//--------LICENSE_START--------"
line_end_mark
=
"//--------LICENSE_END--------"
#options
#options
tmp
=
false
tmp
=
false
mode
=
"none"
path
=
""
path
=
""
#recursive=true
#recursive=true
license
=
""
license
=
""
remove
=
false
for
i
in
"
$@
"
;
do
for
i
in
"
$@
"
;
do
case
$i
in
case
$i
in
...
@@ -21,6 +24,22 @@ for i in "$@"; do
...
@@ -21,6 +24,22 @@ for i in "$@"; do
license
=
"
${
i
#*=
}
"
license
=
"
${
i
#*=
}
"
shift
# past argument=value
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)
# --non-recursive)
# recursive=false
# recursive=false
# shift # past argument=value
# shift # past argument=value
...
@@ -45,7 +64,7 @@ else
...
@@ -45,7 +64,7 @@ else
fi
fi
if
[
"
$license
"
==
""
]
;
then
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
exit
1
else
else
if
[
-f
"
$license
"
]
;
then
if
[
-f
"
$license
"
]
;
then
...
@@ -57,9 +76,16 @@ else
...
@@ -57,9 +76,16 @@ else
fi
fi
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)
# PATH (AND tmp FOLDER)
folder
=
$path
folder
=
$path
if
$tmp
;
then
if
[
$tmp
==
true
]
;
then
echo
"Creating temporary folder:
${
path
}
_tmp"
echo
"Creating temporary folder:
${
path
}
_tmp"
mkdir
-pv
${
path
}
_tmp
mkdir
-pv
${
path
}
_tmp
cp
-a
$path
/.
${
path
}
_tmp
cp
-a
$path
/.
${
path
}
_tmp
...
@@ -67,17 +93,34 @@ if $tmp; then
...
@@ -67,17 +93,34 @@ if $tmp; then
fi
fi
# DETECT AND REMOVE EXISTING LICENSE
# 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
# 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
$(
find
$folder
-name
'*.c'
-or
-name
'*.cpp'
-or
-name
'*.h'
-or
-name
'*.hpp'
)
do
do
if
grep
-Fxq
"//LICENSE_START"
$i
if
grep
-Fxq
${
line_start_mark
}
$i
;
then
then
echo
"skippping
${
i
}
"
echo
"skippping
${
i
}
"
else
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
mv
temp_file
$i
fi
fi
done
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