diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-09-30 17:34:25 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-09-30 17:34:25 +0200 |
commit | 05672f7435cfa419893b4282d49254390181833e (patch) | |
tree | b99ab6849e2f3851c593a593b58d3b7d840ddfcf /build/awk/init | |
parent | build(cog.toml): Format *before* checking the formatting (diff) | |
download | flake-templates-0.7.0.tar.gz flake-templates-0.7.0.zip |
chore(version): v0.7.0 v0.7.0
Diffstat (limited to 'build/awk/init')
-rw-r--r-- | build/awk/init | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/build/awk/init b/build/awk/init index 1ea1603..f8c8bb3 100644 --- a/build/awk/init +++ b/build/awk/init @@ -10,13 +10,18 @@ trap "cleanup; remove_self" EXIT cleanup() { rm "$replacement_file" } +avoid_cleanup="false" remove_self() { - rm "$(realpath "$0")" - rm "$(realpath "$(dirname "$0")")/shell_line_editor.sh" + if [ "$avoid_cleanup" = "false" ]; then + rm "$(realpath "$0")" + rm "$(realpath "$(dirname "$0")")/shell_line_editor.sh" + [ -f "$(realpath "$(dirname "$0")")/init.local" ] && rm "$(realpath "$(dirname "$0")")/init.local" + fi } require() { program="$1" if ! command -v "$program" >/dev/null; then + avoid_cleanup="true" echo "Please install '$program' for this init script to work." 1>&2 exit 1 fi @@ -64,8 +69,6 @@ require mv require sed require chmod -git init - # necessary meta data prompt APPLICATION_NAME "The name of the application" "$(basename "$PWD")" prompt APPLICATION_NAME_STYLIZED "The stylized name of the application (for documentation)" "$(echo "$APPLICATION_NAME" | sed 's/[_-]/ /g' | sed 's/^\(\w\)/\U\1/g' | sed 's/ \(\w\)/ \U\1/g')" @@ -78,7 +81,15 @@ prompt AUTHOR_EMAIL "The email of the author (or authors)" "$(git config --get u # cog change-log variables prompt REMOTE "The remote, this project will be pushed to" "git.vhack.eu" prompt REPOSITORY "The path of the repository on the remote" "$APPLICATION_NAME" -prompt OWNER "The name of owner of the repository" "$AUTHOR_NAME" + +owner1="$(printf "%.1s" "$AUTHOR_NAME")" +owner2="${AUTHOR_NAME#* }" +if [ "$owner2" = "$AUTHOR_NAME" ]; then + owner_build="$(echo "$AUTHOR_NAME" | tr '[:upper:]' '[:lower:]')" +else + owner_build="$(echo "$owner1$owner2" | tr '[:upper:]' '[:lower:]')" +fi +prompt OWNER "The name of owner of the repository" "$owner_build" # nice meta data prompt DESCRIPTION "The description of this project" "" @@ -88,7 +99,12 @@ prompt APPLICATION_SOURCE_CODE_REPOSITORY "The package's source code repository prompt HOME_PAGE "The home page URL of the project" "https://$REPOSITORY.org/" prompt BUG_URL "The URL people should report bugs to" "$APPLICATION_SOURCE_CODE_REPOSITORY/issues" -if [ -e ./lpm.toml ]; then +# git stuff +prompt PUSH_URL "The url used to push this project" "git@$REMOTE:$OWNER/$REPOSITORY.git" +prompt CLONE_URL "The url used to clone this project" "git@$REMOTE:$OWNER/$REPOSITORY.git" +prompt MAIN_BRANCH "The name of the main branch" "$(git config init.defaultbranch)" + +if [ -e ./watch.sh ]; then # Use a different default license in latex projects. init_default_license="CC-BY-SA-4.0" else @@ -105,7 +121,7 @@ fi prompt LICENSE_URL "The url of the license" "$default_license_url" if [ -e ./.reuse/templates/default.jinja2 ]; then - cat <<EOF | fmt --uniform-spacing --width=75 >./.reuse/templates/default.jinja2 + cat <<EOF | fmt --uniform-spacing --width=85 --split-only >./.reuse/templates/default.jinja2 {% for copyright_line in copyright_lines %} {{ copyright_line }} {% endfor %} @@ -120,14 +136,14 @@ This file is part of $APPLICATION_NAME_STYLIZED - $DESCRIPTION. You should have received a copy of the License along with this program. If not, see <$LICENSE_URL>. -<!-- vim: ft=htmldjango --> EOF fi # Allow templates to add template specific prompts [ -e init.local ] && . ./init.local -echo "$DESCRIPTION" >.git/description +git init --initial-branch "$MAIN_BRANCH" --template="./git_template" +rm --recursive ./git_template while read -r var; do var_name="${var%=*}" @@ -148,5 +164,19 @@ done <"$replacement_file" chmod +x scripts/* chmod +x update.sh [ -f ./build.sh ] && chmod +x build.sh +[ -f ./watch.sh ] && chmod +x build.sh + +# Do the first run of reuse annotate +reuse="$(nix build nixpkgs#reuse --no-link --print-out-paths)" +[ "$(echo "$reuse" | wc -l)" -ne 1 ] && die "Something is wrong with the nixpkgs#reuse derivation" + +git add . + +git diff --name-only --cached | + xargs -I {} "$reuse" annotate \ + --copyright "$AUTHOR_NAME <$AUTHOR_EMAIL>" \ + --copyright-style string-c \ + --template default \ + --license "$SPDX_LICENSE_IDENTIFIER" "{}" # vim: ft=sh |