Skip to content

Commit

Permalink
feat: Restrict available licenses
Browse files Browse the repository at this point in the history
Use one most common license for:
- preserving authorship only,
- preserving access to the source code,
- releasing work to the public doman.
  • Loading branch information
macie committed Feb 22, 2024
1 parent bac3fe0 commit ff64651
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<hash>`),
- 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

Expand Down
16 changes: 9 additions & 7 deletions shinit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT
# <https://github.com/macie/shinit>

SHINIT_VERSION="2024.02-prerelease"
SHINIT_VERSION="2024.02"

# DEFAULTS
SHINIT_GIT_BIN=$(git -v)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff64651

Please sign in to comment.