From 1433acfff72df5d7a90875a546b611010ff112f6 Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Sun, 22 Sep 2024 11:53:54 +0200 Subject: [PATCH] Added license checker --- pnpm-lock.yaml | 2 ++ tooling/license/license.sh | 23 ++++++++++++++++++++++ tooling/license/main.sh | 6 ++++++ tooling/license/package.json | 8 ++++++++ tooling/license/visibility.sh | 36 +++++++++++++++++++++++++++++++++++ turbo.json | 3 +++ 6 files changed, 78 insertions(+) create mode 100644 tooling/license/license.sh create mode 100644 tooling/license/main.sh create mode 100644 tooling/license/package.json create mode 100644 tooling/license/visibility.sh diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf35695c6..1222ea5db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1467,6 +1467,8 @@ importers: specifier: ^5.6.2 version: 5.6.2 + tooling/license: {} + tooling/prettier: dependencies: '@ianvs/prettier-plugin-sort-imports': diff --git a/tooling/license/license.sh b/tooling/license/license.sh new file mode 100644 index 000000000..1eabc75d6 --- /dev/null +++ b/tooling/license/license.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if [ "$NODE_ENV" = "production" ]; then + exit 0 +fi + +GIT_USER=$(git config user.name) +GIT_EMAIL=$(git config user.email) + +if [ -z "$GIT_USER" ]; then + echo "Please set the git user name with the command 'git config user.name '. The username needs to match the username in your Makerkit organization." + exit 1 +fi + +STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X GET "https://makerkit.dev/api/license/check?username=$GIT_USER&email=$GIT_EMAIL") + +if [ "$STATUS_CODE" = "200" ]; then + exit 0 +fi + +exit 1 \ No newline at end of file diff --git a/tooling/license/main.sh b/tooling/license/main.sh new file mode 100644 index 000000000..f910cab8b --- /dev/null +++ b/tooling/license/main.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e + +sh visibility.sh +sh license.sh \ No newline at end of file diff --git a/tooling/license/package.json b/tooling/license/package.json new file mode 100644 index 000000000..01d16156c --- /dev/null +++ b/tooling/license/package.json @@ -0,0 +1,8 @@ +{ + "name": "license", + "private": true, + "version": "0.1.0", + "scripts": { + "dev": "sh main.sh" + } +} diff --git a/tooling/license/visibility.sh b/tooling/license/visibility.sh new file mode 100644 index 000000000..a3fd0d82b --- /dev/null +++ b/tooling/license/visibility.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -e + +remote_url=$(git config --get remote.origin.url) + +if [[ $remote_url == *"github.com"* ]]; then + if [[ $remote_url == https://github.com/* ]]; then + owner_repo=${remote_url#https://github.com/} + elif [[ $remote_url == git@github.com:* ]]; then + owner_repo=${remote_url#git@github.com:} + else + echo "Unsupported GitHub URL format" + exit 1 + fi + owner_repo=${owner_repo%.git} + + api_url="https://api.github.com/repos/$owner_repo" + response=$(curl -s -o /dev/null -w "%{http_code}" $api_url) + + if [ $response -eq 200 ]; then + visibility=$(curl -s $api_url | grep -o '"private": \(true\|false\)' | awk '{print $2}') + if [ "$visibility" = "false" ]; then + echo "The repository has been LEAKED on GitHub. Please delete the repository. A DMCA Takedown Request will automatically be requested in the coming hours." + exit 1 + else + exit 0 + fi + elif [ $response -eq 404 ]; then + exit 0 + else + exit 1 + fi +else + exit 0 +fi \ No newline at end of file diff --git a/turbo.json b/turbo.json index a4231f693..1e4ae0be5 100644 --- a/turbo.json +++ b/turbo.json @@ -92,6 +92,9 @@ }, "//#clean": { "cache": false + }, + "license#dev": { + "outputLogs": "none" } } }