From 4d9dba9a03322011c386ffe6af18f7d25e014005 Mon Sep 17 00:00:00 2001 From: Troy McConaghy Date: Wed, 8 Aug 2018 17:29:50 +0200 Subject: [PATCH 1/2] Problem: No SPDX license info in source files Solution: Write a script to add such info to all source files --- add-spdx | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 add-spdx diff --git a/add-spdx b/add-spdx new file mode 100755 index 00000000..445fdc99 --- /dev/null +++ b/add-spdx @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Add SPDX (license information) lines +# to all source code files and documentation source files +# in this directory and subdirectories (recursively). +# +# To read about SPDX, see https://spdx.org/ +# +# Note that this script might also edit files in your virtualenv, +# but that shouldn't be a problem, +# because Git should be ignoring changes in those files. + +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +# All files named *.py or *.sh or *.bash +find . -type f \( -name "*.py" -o -name "*.sh" -o -name "*.bash" \) | while read fname; do + if [ "`head -c 2 $fname`" = "#!" ]; then + # The file '$fname' begins with a hashbang so add the SPDX lines on lines 2+ + sed -i '2s/^/# Copyright BigchainDB GmbH and BigchainDB contributors\n# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n# Code is Apache-2.0 and docs are CC-BY-4.0\n\n/' $fname + else + # add the SPDX lines on lines 1+ + sed -i '1s/^/# Copyright BigchainDB GmbH and BigchainDB contributors\n# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n# Code is Apache-2.0 and docs are CC-BY-4.0\n\n/' $fname + fi +done + +# All files named *.md (Markdown). +find . -type f -name "*.md" | while read fname; do + sed -i '1s;^;\n\n;' $fname +done + +# All files named *.rst (reStructuredText). +# See http://docutils.sourceforge.net/docs/user/rst/quickref.html#comments +find . -type f -name "*.rst" | while read fname; do + sed -i '1s;^;\n.. Copyright BigchainDB GmbH and BigchainDB contributors\n SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n Code is Apache-2.0 and docs are CC-BY-4.0\n\n;' $fname +done From 4dc60d13ce0c4a19ad4112f42ac76d2571b76a7c Mon Sep 17 00:00:00 2001 From: Troy McConaghy Date: Thu, 9 Aug 2018 15:21:42 +0200 Subject: [PATCH 2/2] Also add license comments in YAML, JS, Go & Java source files --- add-spdx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/add-spdx b/add-spdx index 445fdc99..41282dd1 100755 --- a/add-spdx +++ b/add-spdx @@ -14,8 +14,8 @@ set -euo pipefail IFS=$'\n\t' -# All files named *.py or *.sh or *.bash -find . -type f \( -name "*.py" -o -name "*.sh" -o -name "*.bash" \) | while read fname; do +# All files named *.py or *.sh or *.bash or *.yaml or *.yml +find . -type f \( -name "*.py" -o -name "*.sh" -o -name "*.bash" -o -name "*.yaml" -o -name "*.yml" \) | while read fname; do if [ "`head -c 2 $fname`" = "#!" ]; then # The file '$fname' begins with a hashbang so add the SPDX lines on lines 2+ sed -i '2s/^/# Copyright BigchainDB GmbH and BigchainDB contributors\n# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n# Code is Apache-2.0 and docs are CC-BY-4.0\n\n/' $fname @@ -25,6 +25,28 @@ find . -type f \( -name "*.py" -o -name "*.sh" -o -name "*.bash" \) | while read fi done +# All files named *.js or *.go (JavaScript, Node.js or Golang) +find . -type f \( -name "*.js" -o -name "*.go" \) | while read fname; do + if [ "`head -c 2 $fname`" = "#!" ]; then + # The file '$fname' begins with a hashbang so add the SPDX lines on lines 2+ + sed -i '2s;^;// Copyright BigchainDB GmbH and BigchainDB contributors\n// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n// Code is Apache-2.0 and docs are CC-BY-4.0\n\n;' $fname + else + # add the SPDX lines on lines 1+ + sed -i '1s;^;// Copyright BigchainDB GmbH and BigchainDB contributors\n// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n// Code is Apache-2.0 and docs are CC-BY-4.0\n\n;' $fname + fi +done + +# All files named *.java +find . -type f -name "*.java" | while read fname; do + if [ "`head -c 2 $fname`" = "#!" ]; then + # The file '$fname' begins with a hashbang so add the SPDX lines on lines 2+ + sed -i '2s;^;/*\n * Copyright BigchainDB GmbH and BigchainDB contributors\n * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n * Code is Apache-2.0 and docs are CC-BY-4.0\n */\n;' $fname + else + # add the SPDX lines on lines 1+ + sed -i '1s;^;/*\n * Copyright BigchainDB GmbH and BigchainDB contributors\n * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)\n * Code is Apache-2.0 and docs are CC-BY-4.0\n */\n;' $fname + fi +done + # All files named *.md (Markdown). find . -type f -name "*.md" | while read fname; do sed -i '1s;^;\n\n;' $fname