From ff646514431554b23f3545cb4d9984f56bcda2e9 Mon Sep 17 00:00:00 2001 From: macie Date: Thu, 22 Feb 2024 15:25:24 +0100 Subject: [PATCH] feat: Restrict available licenses Use one most common license for: - preserving authorship only, - preserving access to the source code, - releasing work to the public doman. --- README.md | 25 +++++++++++++++++++++---- shinit | 16 +++++++++------- tests/test_init.sh | 14 ++++++++++++++ tests/test_regression.sh | 2 +- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8d5302d..a677656 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,28 @@ [![Quality check status](https://github.com/macie/shinit/actions/workflows/check.yml/badge.svg)](https://github.com/macie/shinit/actions/workflows/check.yml) [![License](https://img.shields.io/github/license/macie/smallstache.sh)](https://tldrlegal.com/license/mit-license) -**shinit** interactively creates empty Bourne shell script in new directory with: - -- `README.md` and `LICENSE` files +**shinit** interactively initializes empty project for a Bourne shell script. + +`shinit` asks user for: +- project name (by default: `sh-`), +- author name (by default: user from git config or current OS user), +- license ID from corporate-safe selection: + - [MIT](https://choosealicense.com/licenses/mit/) (default) - to maximize + chance of mass adoption by preserving authorship information only, + - [GPL-3.0-only](https://choosealicense.com/licenses/gpl-3.0/) - to secure + access to the source code at the cost of adoption across for-profit + organizations, + - [MIT-0](https://choosealicense.com/licenses/mit-0/) - to release the + source code into the public domain, even in jurisdictions without + the public domain. + +Based on answers, `shinit` creates a new directory with: + +- initialized Git repository and `.gitignore` allow list +- shell script with executable permissions - `Makefile` with configured development targets -- configured Git repository. +- `LICENSE` file +- `README.md` with basic info. ## Usage diff --git a/shinit b/shinit index cac510a..84829ae 100755 --- a/shinit +++ b/shinit @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # -SHINIT_VERSION="2024.02-prerelease" +SHINIT_VERSION="2024.02" # DEFAULTS SHINIT_GIT_BIN=$(git -v) @@ -44,11 +44,13 @@ shinit_prompt() { SHINIT_AUTHOR="${SHINIT_AUTHOR_DEFAULT}" fi - printf ' - license [%s]: ' "${SHINIT_LICENSE_DEFAULT}" - read -r SHINIT_LICENSE - if [ -z "${SHINIT_LICENSE}" ]; then - SHINIT_LICENSE="${SHINIT_LICENSE_DEFAULT}" - fi + while ! echo "${SHINIT_LICENSE}" | grep -q -E '^MIT|GPL-3.0-only|MIT-0'; do + printf ' - license (MIT, GPL-3.0-only, MIT-0) [%s]: ' "${SHINIT_LICENSE_DEFAULT}" + read -r SHINIT_LICENSE + if [ -z "${SHINIT_LICENSE}" ]; then + SHINIT_LICENSE="${SHINIT_LICENSE_DEFAULT}" + fi + done } # Generate project files. @@ -222,7 +224,7 @@ EOF # Prepare documentation files. shinit_markdown() { # shellcheck disable=SC2018,SC2019 - LICENSE_SRC='https://raw.githubusercontent.com/github/choosealicense.com/gh-pages/_licenses/'$(echo "${SHINIT_LICENSE}" | tr 'A-Z' 'a-z')'.txt' + LICENSE_SRC='https://raw.githubusercontent.com/github/choosealicense.com/gh-pages/_licenses/'$(echo "${SHINIT_LICENSE}" | tr 'A-Z' 'a-z' | sed 's/-only//g')'.txt' printf ' - LICENSE (from %s)\n' "${LICENSE_SRC}" curl -fL "${LICENSE_SRC}" | sed -e '/---/,/---/d' -e '/./,$!d' -e "s/\[year\]/$(date +%Y)/g" -e "s/\[fullname\]/$SHINIT_AUTHOR/g" >LICENSE diff --git a/tests/test_init.sh b/tests/test_init.sh index c23cffd..f4f1b9f 100644 --- a/tests/test_init.sh +++ b/tests/test_init.sh @@ -23,6 +23,20 @@ test_default() { test "$(ls -a "${TEST_PROJ_DIR}" | tr '\n' ' ')" = ". .. .git .gitignore LICENSE Makefile README.md ${TEST_PROJ_SCRIPT} " } +test_name() { + echo 'cool_script' | ./shinit "${TEST_ROOT_DIR}" 2>/dev/null >&2 + test $? -eq 0 + + test -f "${TEST_ROOT_DIR}/cool_script/cool_script" +} + +test_license_invalid() { + printf 'some_proj\ninvalid\nMIT-0\n' | ./shinit "${TEST_ROOT_DIR}" 2>/dev/null >&2 + test $? -eq 0 + + grep -q 'MIT No Attribution' "${TEST_ROOT_DIR}/some_proj/LICENSE" +} + test_repo_path_local() { echo '/valid.url/is/here/local_test.git' | ./shinit "${TEST_ROOT_DIR}" 2>/dev/null >&2 test $? -eq 0 diff --git a/tests/test_regression.sh b/tests/test_regression.sh index e21ab45..4e1711f 100644 --- a/tests/test_regression.sh +++ b/tests/test_regression.sh @@ -4,7 +4,7 @@ beforeAll() { TEST_ROOT_DIR=$(mktemp -d -t 'shinit_testXXXXXX') MOCK_DIR=$(mktemp -d -t 'shinit_mockXXXXXX') - USED_CMDS='cat cd chmod curl date hexdump id ls mkdir printf sed tr' + USED_CMDS='cat cd chmod curl date grep hexdump id ls mkdir printf sed tr' for MOCKED_CMD in $USED_CMDS; do echo '#!/bin/sh' >"${MOCK_DIR}/${MOCKED_CMD}" if type "$MOCKED_CMD" | grep -q 'builtin'; then