From 9304c55a8164d658404ac896e82e821ce707cadc Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Tue, 11 Oct 2022 23:42:03 +0200 Subject: [PATCH] chore: add scripts for license+copyright header and file generation --- add-license-to-all.sh | 14 +++++++ new-file.sh | 93 +++++++++++++++++++++++++++++++++++++++++++ new-file.sh.license | 3 ++ 3 files changed, 110 insertions(+) create mode 100755 add-license-to-all.sh create mode 100755 new-file.sh create mode 100644 new-file.sh.license diff --git a/add-license-to-all.sh b/add-license-to-all.sh new file mode 100755 index 000000000..bc8070574 --- /dev/null +++ b/add-license-to-all.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env zsh + +# SPDX-FileCopyrightText: 2022 Sarah Vaupel +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +for ext in $2; do + for x in `find $1 -type f -name "*.$ext"`; do + ./new-file.sh tmp.$ext $x $3 + echo '' >> tmp.$ext + cat tmp.$ext | cat - $x > temp && mv temp $x + rm tmp.$ext + done +done diff --git a/new-file.sh b/new-file.sh new file mode 100755 index 000000000..0f24496b4 --- /dev/null +++ b/new-file.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env zsh + +# Copyright notice +COPYRIGHT_TIME=2022 +CURRENT_YEAR=`date +'%Y'` +if [ $CURRENT_YEAR -gt $COPYRIGHT_TIME ]; then + COPYRIGHT_TIME="$COPYRIGHT_TIME-$CURRENT_YEAR" +fi +COPYRIGHT_USERS="`git config user.name` <`git config user.email`>" +if [ ! -z "$2" ]; then + COPYRIGHT_USERS=`git blame $2 --line-porcelain | grep -e "^author " -e "^author-mail " | sed -e "s/^author //" -e "s/^author-mail //" | sed -e ':a;N;$!ba;s/\n $2.license + exit 0 +fi + + +case "$1" in + *.hs) + COMMENT='--' + ;; + routes) + COMMENT='--' + ;; + *.model) + COMMENT='--' + ;; + *.hamlet) + COMMENT='$#' + ;; + *.msg) + COMMENT='#' + ;; + *.js) + COMMENT='//' + ;; + *.sass) + COMMENT='//' + ;; + *.nix) + COMMENT='#' + ;; + *.sh) + COMMENT='#' + ;; + *.pl) + COMMENT='#' + ;; + *.pm) + COMMENT='#' + ;; + *.yaml) + COMMENT='#' + ;; + *.yml) + COMMENT='#' + ;; + *.md) + COMMENT='[comment]: # (' + COMMENT_END=' )' + ;; + *.txt) + COMMENT='#' + ;; + *) + echo 'Unsupported file extension' + exit 1 +esac + +case "$1" in + *.hamlet) + echo "\$newline never\n" > $1 + echo "$COMMENT $COPYRIGHT_NOTICE$COMMENT_END\n$COMMENT$COMMENT_END" >> $1 + ;; + *.sh) + echo "#!/usr/bin/env bash\n" > $1 + echo "$COMMENT $COPYRIGHT_NOTICE$COMMENT_END\n$COMMENT$COMMENT_END" >> $1 + ;; + *) + echo "$COMMENT $COPYRIGHT_NOTICE$COMMENT_END\n$COMMENT$COMMENT_END" > $1 + ;; +esac + +while IFS= read -r line +do + echo "$COMMENT $line$COMMENT_END" >> $1 +done < <(printf '%s\n' "$LICENSE_NOTICE") diff --git a/new-file.sh.license b/new-file.sh.license new file mode 100644 index 000000000..550c564a4 --- /dev/null +++ b/new-file.sh.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2022 Sarah Vaupel + +SPDX-License-Identifier: AGPL-3.0-or-later