やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

【lish】LICENSEファイルを生成する

 12種類のライセンスに対応!

成果物

$$l$lish$lish-a$lish-a'First$lish-a'FirstLast'$lish-a'FirstLast'm$lsLICENSE$cat$catLICENSEMITLicenseCopyright(c)2020FirstLastPermissionisherebygranted,freeofcharge,toanypersonobtainingacopyofthissoftwareandassociateddocumentationfiles(the"Software"),todealintheSoftwarewithoutrestriction,includingwithoutlimitationtherightstouse,copy,modify,merge,publish,distribute,sublicense,and/orsellcopiesoftheSoftware,andtopermitpersonstowhomtheSoftwareisfurnishedtodoso,subjecttothefollowingconditions:TheabovecopyrightnoticeandthispermissionnoticeshallbeincludedinallcopiesorsubstantialportionsoftheSoftware.THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE.$li$lis$lish-$lish-a'$lish-a'F$lish-a'Fi$lish-a'Fir$lish-a'Firs$lish-a'FirstL$lish-a'FirstLa$lish-a'FirstLas$lish-a'FirstLast$c$ca$catLOUTOFORINCONNECTIONWI

特徴

対応ライセンス一覧

系列 ライセンス
コピーレフト AGPL(+), GPL(+), LGPL(+), CC-BY-SA-4.0
パーミッシブ Apache-2.0, MIT, BSD(2,3,3-clear), CC-BY-4.0
パブリックドメイン CC0, Unlicense

承認

type FSF OSI License
copyleft AGPL
copyleft GPL
copyleft LGPL
copyleft CC-BY-SA-4.0
permissive Apache-2.0
permissive MIT
permissive BSD-2-Clause
permissive BSD-3-Clause
permissive BSD-3-Clause-Clear
permissive CC-BY-4.0
public-domain CC0-1.0
public-domain Unlicense

実行

sudo apt install -y jq
sudo apt install -y ruby bundler cmake pkg-config git libssl-dev
sudo gem install licensee
git clone https://github.com/ytyaru/lish
cd ./lish/src
./lish.sh -h

使い方

PATHに通す

ln -s ./lish.sh /usr/bin/lish

ヘルプ表示

 ヘルプ

lish -h

ヘルプ

Create a LICENSE file.     0.0.1
Usage: lish [-a AUTHOR -y YEAR -r REPO_NAME -i -s] LICENSE_ID
Options:
  -a Author name
  -y Copyright year
  -r Repository name
  -i Add LICENSE_ID to file name suffix
  -s Output standard-license-header
  Other options display help.
LICENSE_ID:
  ignore case. Searches for a prefix match.
  Groups:
    p public-domain : CC0-1.0
    l copyleft      : AGPL-3.0
    c copycenter    : Apache-2.0
  Shortcut and Alias:
    p pd  cc0   : CC0-1.0
    c ap  apa   : Apache-2.0
    l ag  agpl  : AGPL-3.0-only
      ag+ agpl+ : AGPL-3.0-or-later
       g   gpl  :  GPL-3.0-only
       g+  gpl+ :  GPL-3.0-or-later
      lg  lgpl  : LGPL-3.0-only
      lg+ lgpl+ : LGPL-3.0-or-later
      b2  bsd2  : BSD-2-Clause
      b3  bsd3  : BSD-3-Clause
      b3c bsd3c : BSD-3-Clause-Clear
    m           : MIT
    u           : Unlicense
          ccb   : CC-BY-4.0
          ccbs  : CC-BY-SA-4.0
  Supported aliases:
    ./lish/res/ids/alias.txt
  Add licenses:
    Reference: https://spdx.org/licenses/
    File: ./lish/res/ids/spdx.txt
          ./lish/res/templates/
AUTHOR:
  Default value is 'git config --local user.name'
  Only when a '.git/config' file exists.
YEAR: 
  Default value is 'date +%Y'
REPO_NAME:
  Default value is current directory name.
Common mistakes:
  Placing optional arguments after positional arguments will fail.
  $ lish mit -a A
  ERROR: MIT requires an author name. Add '-a' option.
Examples:
  lish l
  lish c
  lish p
  lish m
  lish AGPL
  lish -a AuthorName m
  lish -a AuthorName -y 1999 m
  lish -s l
  lish -s -a AuthorName -y 1999 l
  lish -s -a 'First Last' -y 1999 -r 'MyRepo' l

ライセンスファイル出力

 ライセンスはエイリアスで指定できる。

lish p # public-domain CC0-1.0
lish l # copyleft      AGPL-3.0
lish c # copycenter    Apache-2.0

 LICENSEファイルを現在のディレクトリに出力する。

ファイル名に接尾辞を追加 -i

 ライセンスIDをファイル名のサフィックスに追加する。

lish -i GPL

 上記の場合、出力ファイル名はLICENSE-GPL-3.0-onlyである。

 デュアルライセンス(マルチライセンス)にするとき使う。

著作権表示オプション

著者名 -a

 MITBSDには著者名が必要。

lish -a 'First Last' MIT

 ./git/configファイルがある場合、git config --local user.nameの値を使用する。

著作権発行年 -y

 オプションで、著作権の発行年を指定できる。

lish -a A -y 1999 MIT

 指定しない場合は、実行時の年を使用する。

ライセンス選択 select

lish select
1) CC0        3) AGPL       5) LGPL       7) CC-BY-SA       9) MIT       11) BSD-3
2) Unlicense   4) GPL    6) CC-BY      8) Apache        10) BSD-2         12) BSD-3-Clear

MITBSDでは著者名の入力を求めることがある。

Author name: 

ライセンス検出

licenseeを使用して、 LICENSEファイルからライセンスIDを返す。

lish detect

 以下、複数のライセンスがある場合の例。 LICENSEファイル名を変更して出力し併存させ、検出する。

$ lish -i l
$ lish -i c
$ lish detect
Apache-2.0
GPL-3.0

標準ライセンスヘッダ出力 -h

 ターゲットはGPL,AGPL,CC0,Apacheheaders. 情報源はSPDX v3.7 2019-10-22

lish -s GPL

 標準出力stdoutに出力する。

リポジトリ-r

lish -s -r 'My Repo' GPL

テンプレート値

 たとえばGPLは次のとおり。

{{REPO_NAME}}
Copyright (C) {{YEAR}} {{AUTHOR}}

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
テンプレート
{{REPO_NAME}} -rオプションの値。または現在のディレクトリ名
{{YEAR}} -yオプションの値。 または実行時の年
{{AUTHOR}} -aオプションの値。 または git config --local user.name

整形

行の折返し

 80文字以外の単語で行を折り返す。Linuxではfoldコマンドを使う。

cat ./res/headers/gpl-3.0-only.txt | fold -s -w 80
{{REPO_NAME}}
Copyright (C) {{YEAR}} {{AUTHOR}}

This program is free software: you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software 
Foundation, version 3.

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 General Public License for more details.

You should have received a copy of the GNU General Public License along with 
this program. If not, see <https://www.gnu.org/licenses/>.

 Apache-2.0の標準ライセンスヘッダは行の折り返しが不要。既にされている。

インデント

cat ./res/headers/gpl-3.0-only.txt | sed -e 's/^/  /g'

依存

 本ツールは以下に依存している。

依存ツール 使用箇所 補足
jq get_license_files.sh WEBからライセンスファイルを取得する。すでにテンプレートファイルがあるので基本的に使わないはず。念の為にある。
licensee lish detect ライセンス検出するときのみ使う

所感

 これでLICENSEファイルをサクッと作れる。以下のような課題があるがlishの範囲外。

  • READMEに追記したい
    • ロゴ
    • URLリンク(日本語/英語/多言語)
    • 文章
      • 標準ライセンスヘッダ(日本語/英語/多言語)
      • 標準ライセンスヘッダがないライセンスの文章
      • コピーライト文言

対象環境

$ uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux