public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 4/9] Add replace-spdx-license.sh script
@ 2020-07-10 14:08 Dodji Seketeli
  2020-07-10 17:29 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Dodji Seketeli @ 2020-07-10 14:08 UTC (permalink / raw)
  To: Benjamin Kosnik, Ben Woodard, Chenxiong Qi, Dodji Seketeli,
	Giuliano Procida, Jan Engelhardt, Jessica Yu, Jonathan Wakely,
	Mark Wielaard, Matthias Klose, Matthias Maennich, Ondrej Oprala,
	Roland McGrath, Sinny Kumari, Slava Barinov
  Cc: libabigail

This script is to replace an SPDX license ID by another one.
I.e, it's to perform an actual re-licensing of a given file.

A way to use the script is this:

    replace-spdx-license.sh  --from LGPL-3.0-or-later \
			      --to  "Apache-2.0 WITH LLVM-exception" \
			      some-file-to-relicense.cc

	* relicensing-scripts/replace-spdx-license.sh: New script.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 relicensing-scripts/replace-spdx-license.sh | 75 +++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100755 relicensing-scripts/replace-spdx-license.sh

diff --git a/relicensing-scripts/replace-spdx-license.sh b/relicensing-scripts/replace-spdx-license.sh
new file mode 100755
index 0000000..5fdbc91
--- /dev/null
+++ b/relicensing-scripts/replace-spdx-license.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# Author: Dodji Seketeli <dodji@redhat.com>
+
+from_license_id=
+to_license_id=
+input_file=
+prog=$0
+
+display_usage()
+{
+    echo "$prog: [options] --from <from-spdx-license-id> --to <to-spdx-license-id> <file>"
+    echo "  where options can be:"
+    echo "   -h|--h		display this help"
+}
+
+main()
+{
+    header=$(head --lines=5 $input_file | grep "SPDX-License-Identifier:")
+    if test "x$header" != x; then
+	license=$(echo "$header" | sed -r "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/")
+    fi
+
+    if test "x$license" != x -a "$license" = "$from_license_id"; then
+	sed -i -r "s/$from_license_id/$to_license_id/" $input_file
+	exit 0
+    fi
+
+    exit 1
+}
+
+# This program takes at least 5 arguments
+if test $# -lt 5; then
+    display_usage
+    exit 1
+fi
+
+# Parse parameters
+while test $# -gt 1; do
+    case "$1" in
+	-h|--h)
+	    display_usage
+	    exit 1
+	    ;;
+
+	-f|--from)
+	    from_license_id=$2
+	    shift
+	    ;;
+
+	-t|--to)
+	    to_license_id=$2
+	    shift
+	    ;;
+
+	-*)
+	    display_usage
+	    exit 1
+	    ;;
+
+	*)
+	    input_file="$1"
+	    ;;
+    esac
+    shift
+done
+
+if test $# -lt 1; then
+    display_usage
+    exit 1
+fi
+
+input_file=$1
+
+main
-- 
1.8.3.1


-- 
		Dodji


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/9] Add replace-spdx-license.sh script
  2020-07-10 14:08 [PATCH 4/9] Add replace-spdx-license.sh script Dodji Seketeli
@ 2020-07-10 17:29 ` Jonathan Wakely
  2020-07-13 11:21   ` Dodji Seketeli
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2020-07-10 17:29 UTC (permalink / raw)
  To: Dodji Seketeli
  Cc: Benjamin Kosnik, Ben Woodard, Chenxiong Qi, Giuliano Procida,
	Jan Engelhardt, Jessica Yu, Mark Wielaard, Matthias Klose,
	Matthias Maennich, Ondrej Oprala, Roland McGrath, Sinny Kumari,
	Slava Barinov, libabigail

On 10/07/20 16:08 +0200, Dodji Seketeli wrote:
>This script is to replace an SPDX license ID by another one.
>I.e, it's to perform an actual re-licensing of a given file.
>
>A way to use the script is this:
>
>    replace-spdx-license.sh  --from LGPL-3.0-or-later \
>			      --to  "Apache-2.0 WITH LLVM-exception" \
>			      some-file-to-relicense.cc
>
>	* relicensing-scripts/replace-spdx-license.sh: New script.
>
>Signed-off-by: Dodji Seketeli <dodji@redhat.com>
>---
> relicensing-scripts/replace-spdx-license.sh | 75 +++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
> create mode 100755 relicensing-scripts/replace-spdx-license.sh
>
>diff --git a/relicensing-scripts/replace-spdx-license.sh b/relicensing-scripts/replace-spdx-license.sh
>new file mode 100755
>index 0000000..5fdbc91
>--- /dev/null
>+++ b/relicensing-scripts/replace-spdx-license.sh
>@@ -0,0 +1,75 @@
>+#!/bin/sh
>+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
>+# Author: Dodji Seketeli <dodji@redhat.com>
>+
>+from_license_id=
>+to_license_id=
>+input_file=
>+prog=$0
>+
>+display_usage()
>+{
>+    echo "$prog: [options] --from <from-spdx-license-id> --to <to-spdx-license-id> <file>"
>+    echo "  where options can be:"
>+    echo "   -h|--h		display this help"
>+}
>+
>+main()
>+{
>+    header=$(head --lines=5 $input_file | grep "SPDX-License-Identifier:")
>+    if test "x$header" != x; then
>+	license=$(echo "$header" | sed -r "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/")
>+    fi
>+
>+    if test "x$license" != x -a "$license" = "$from_license_id"; then
>+	sed -i -r "s/$from_license_id/$to_license_id/" $input_file
>+	exit 0
>+    fi
>+
>+    exit 1
>+}
>+
>+# This program takes at least 5 arguments
>+if test $# -lt 5; then
>+    display_usage
>+    exit 1
>+fi
>+
>+# Parse parameters
>+while test $# -gt 1; do
>+    case "$1" in
>+	-h|--h)
>+	    display_usage
>+	    exit 1

Same comment again. I'd exit 0 for --help, and redirect the
display_usage output to stderr for the other cases where it really is
incorrect usage.

>+	    ;;
>+
>+	-f|--from)
>+	    from_license_id=$2
>+	    shift
>+	    ;;
>+
>+	-t|--to)
>+	    to_license_id=$2
>+	    shift
>+	    ;;
>+
>+	-*)
>+	    display_usage
>+	    exit 1
>+	    ;;
>+
>+	*)
>+	    input_file="$1"
>+	    ;;
>+    esac
>+    shift
>+done
>+
>+if test $# -lt 1; then
>+    display_usage
>+    exit 1
>+fi
>+
>+input_file=$1
>+
>+main
>-- 
>1.8.3.1
>
>
>-- 
>		Dodji
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/9] Add replace-spdx-license.sh script
  2020-07-10 17:29 ` Jonathan Wakely
@ 2020-07-13 11:21   ` Dodji Seketeli
  0 siblings, 0 replies; 3+ messages in thread
From: Dodji Seketeli @ 2020-07-13 11:21 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: Benjamin Kosnik, Ben Woodard, Chenxiong Qi, Giuliano Procida,
	Jan Engelhardt, Jessica Yu, Mark Wielaard, Matthias Klose,
	Matthias Maennich, Ondrej Oprala, Roland McGrath, Sinny Kumari,
	Slava Barinov, libabigail

Jonathan Wakely <jwakely@redhat.com> writes:

[...]


>>+# Parse parameters
>>+while test $# -gt 1; do
>>+    case "$1" in
>>+	-h|--h)
>>+	    display_usage
>>+	    exit 1
>
> Same comment again. I'd exit 0 for --help, and redirect the
> display_usage output to stderr for the other cases where it really is
> incorrect usage.

Fixed.

Here is the updated patch that is going to be part of a v2 series that
I'll send out shortly.

Cheers,

From 67c937cc936a46e0952fd683ff57f50ed605d0ba Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <dodji@redhat.com>
Date: Fri, 29 May 2020 10:45:34 +0200
Subject: [PATCH 4/9] Add replace-spdx-license.sh script

This script is to replace an SPDX license ID by another one.
I.e, it's to perform an actual re-licensing of a given file.

A way to use the script is this:

    replace-spdx-license.sh  --from LGPL-3.0-or-later \
			      --to  "Apache-2.0 WITH LLVM-exception" \
			      some-file-to-relicense.cc

	* relicensing-scripts/replace-spdx-license.sh: New script.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 relicensing-scripts/replace-spdx-license.sh | 75 +++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100755 relicensing-scripts/replace-spdx-license.sh

diff --git a/relicensing-scripts/replace-spdx-license.sh b/relicensing-scripts/replace-spdx-license.sh
new file mode 100755
index 0000000..f634528
--- /dev/null
+++ b/relicensing-scripts/replace-spdx-license.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# Author: Dodji Seketeli <dodji@redhat.com>
+
+from_license_id=
+to_license_id=
+input_file=
+prog=$0
+
+display_usage()
+{
+    echo "$prog: [options] --from <from-spdx-license-id> --to <to-spdx-license-id> <file>"
+    echo "  where options can be:"
+    echo "   -h|--h		display this help"
+}
+
+main()
+{
+    header=$(head --lines=5 $input_file | grep "SPDX-License-Identifier:")
+    if test "x$header" != x; then
+	license=$(echo "$header" | sed -r "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/")
+    fi
+
+    if test "x$license" != x -a "$license" = "$from_license_id"; then
+	sed -i -r "s/$from_license_id/$to_license_id/" $input_file
+	exit 0
+    fi
+
+    exit 1
+}
+
+# This program takes at least 5 arguments
+if test $# -lt 5; then
+    >&2 display_usage
+    exit 1
+fi
+
+# Parse parameters
+while test $# -gt 1; do
+    case "$1" in
+	-h|--h)
+	    display_usage
+	    exit 0
+	    ;;
+
+	-f|--from)
+	    from_license_id=$2
+	    shift
+	    ;;
+
+	-t|--to)
+	    to_license_id=$2
+	    shift
+	    ;;
+
+	-*)
+	    >&2 display_usage
+	    exit 1
+	    ;;
+
+	*)
+	    input_file="$1"
+	    ;;
+    esac
+    shift
+done
+
+if test $# -lt 1; then
+    >&2 display_usage
+    exit 1
+fi
+
+input_file=$1
+
+main
-- 
1.8.3.1


-- 
		Dodji


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-13 11:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 14:08 [PATCH 4/9] Add replace-spdx-license.sh script Dodji Seketeli
2020-07-10 17:29 ` Jonathan Wakely
2020-07-13 11:21   ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).