fix(scripts/renew_copyright_header): Correctly handle shebangs
This commit is contained in:
parent
3484ead8af
commit
3646e4aee8
|
@ -1,10 +1,31 @@
|
|||
# Copyright (C) 2023 - 2024:
|
||||
# The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
#
|
||||
#
|
||||
# This file is part of the Trixy crate for Trinitrix.
|
||||
#
|
||||
# Trixy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the Lesser GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# and the Lesser GNU General Public License along with this program.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
# Regexes which if matched by a file path will always be excluded from
|
||||
# getting a license header
|
||||
excludes:
|
||||
- .*lock
|
||||
- expected.md
|
||||
- \.git/.*
|
||||
- \.licensure\.yml
|
||||
- LICENSE.spdx
|
||||
- COPYING
|
||||
- COPYING.LESSER
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#(*
|
||||
# Copyright (C) 2023 - 2024:
|
||||
# The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
#
|
||||
#
|
||||
# This file is part of the Trixy crate for Trinitrix.
|
||||
#
|
||||
|
@ -19,7 +21,6 @@
|
|||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
#*)
|
||||
|
||||
|
||||
# (*
|
||||
# Trixy is fully whitespace independent, this means that you can
|
||||
# interleave whitespace in the definitions.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Copyright (C) 2023 - 2024:
|
||||
# The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
#
|
||||
#
|
||||
# This file is part of the Trixy crate for Trinitrix.
|
||||
#
|
||||
|
@ -219,6 +221,9 @@
|
|||
gdb
|
||||
|
||||
ebnf2pdf.outputs.packages."${system}".default
|
||||
|
||||
# for the ./scripts/renew_copyright_header.sh
|
||||
yq
|
||||
];
|
||||
inherit nativeBuildInputs buildInputs;
|
||||
};
|
||||
|
|
|
@ -1,18 +1,37 @@
|
|||
#! /usr/bin/env sh
|
||||
# Copyright (C) 2023 - 2024:
|
||||
# The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
#
|
||||
#
|
||||
# This file is part of the Trixy crate for Trinitrix.
|
||||
#
|
||||
# Trixy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the Lesser GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# and the Lesser GNU General Public License along with this program.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
TEMPLATE_LINE_LENGHT=19
|
||||
|
||||
fd --type file . | while read -r file; do
|
||||
if grep --quiet 'The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>' "$file"; then
|
||||
filename="$(basename -- "$file")"
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
TEMPLATE_LINE_LENGHT=20
|
||||
remove() {
|
||||
extension="$1"
|
||||
file="$2"
|
||||
|
||||
# We need to differentiate, when removing the old copyright header, as some
|
||||
# formatters do weird things to the file
|
||||
case "$extension" in
|
||||
# normal '#' comments (these are 19 lines long)
|
||||
"Makefile" | "toml")
|
||||
# the `config` file is the cargo config at `./example/main/.cargo/config`, which is
|
||||
# toml
|
||||
"Makefile" | "toml" | "envrc" | "config" | "yml")
|
||||
sed --in-place "1,${TEMPLATE_LINE_LENGHT}d" "$file"
|
||||
;;
|
||||
# normal '/* ... */' like comments (these are 21 lines long--'#' + 2)
|
||||
|
@ -30,14 +49,55 @@ fd --type file . | while read -r file; do
|
|||
# remove the 19 lines
|
||||
"sh")
|
||||
sed --in-place "2,${TEMPLATE_LINE_LENGHT}d;" "$file"
|
||||
licensure --in-place "$file"
|
||||
|
||||
TEMPLATE_LINE_LENGHT_NEW="$(($(yq --raw-output '.licenses | map(.template) | join("")' ./.licensure.yml | wc -l) + $(yq '.comments | last | .commenter.trailing_lines' ./.licensure.yml)))"
|
||||
|
||||
# delete the current shebang
|
||||
to="$((TEMPLATE_LINE_LENGHT_NEW + 1))"
|
||||
sed --in-place "${TEMPLATE_LINE_LENGHT_NEW},${to}d;" "$file"
|
||||
|
||||
# add a new one
|
||||
sed --in-place "1i#! /usr/bin/env sh" "$file"
|
||||
;;
|
||||
*)
|
||||
echo "File '$file' with extension '$extension' is not know yet, please add it!"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
list() {
|
||||
echo "$extension -> $file"
|
||||
}
|
||||
|
||||
if [ -f "$1" ]; then
|
||||
file="$(realpath "$1")"
|
||||
filename="$(basename -- "$file")"
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
|
||||
if [ -n "$DRY_RUN" ]; then
|
||||
list "$extension" "$file"
|
||||
else
|
||||
remove "$extension" "$file"
|
||||
fi
|
||||
done
|
||||
else
|
||||
fd --type file --hidden . | while read -r file; do
|
||||
if grep --quiet 'The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>' "$file"; then
|
||||
filename="$(basename -- "$file")"
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
|
||||
nix fmt
|
||||
if [ -n "$DRY_RUN" ]; then
|
||||
list "$extension" "$file"
|
||||
else
|
||||
remove "$extension" "$file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
licensure --in-place --project
|
||||
if [ -z "$DRY_RUN" ]; then
|
||||
licensure --in-place --project
|
||||
nix fmt
|
||||
fi
|
||||
fi
|
||||
|
|
Reference in New Issue