From cc8e8c28e4ab88fddf84bc64e2b3fe8aeb7360e7 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Thu, 12 Jun 2025 18:30:24 +0200 Subject: [PATCH] License headers and scripts to apply its --- apply_license_to_vb.sh | 29 +++++++++++++++++++++++++++++ apply_license_to_xml.sh | 39 +++++++++++++++++++++++++++++++++++++++ license_header.vb.txt | 14 ++++++++++++++ license_header.xml.txt | 16 ++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100755 apply_license_to_vb.sh create mode 100755 apply_license_to_xml.sh create mode 100644 license_header.vb.txt create mode 100644 license_header.xml.txt diff --git a/apply_license_to_vb.sh b/apply_license_to_vb.sh new file mode 100755 index 0000000..78ca470 --- /dev/null +++ b/apply_license_to_vb.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Chemin vers le fichier contenant le header +HEADER_FILE="license_header.vb.txt" + +# Vérifie si le fichier contenant le header existe +if [[ ! -f "$HEADER_FILE" ]]; then + echo "Le fichier $HEADER_FILE n'existe pas. Veuillez le créer avant d'exécuter ce script." + exit 1 +fi + +# Lit le contenu du header +HEADER_CONTENT=$(<"$HEADER_FILE") + +# Ajoute le header à tous les fichiers .vb +find . -type f -name "*.vb" | while read -r FILE; do + echo "Ajout du header dans $FILE..." + + # Vérifie si le fichier commence par un BOM + if head -c 3 "$FILE" | grep -q $'\xef\xbb\xbf'; then + # Conserve le BOM et insère le header juste après + (head -c 3 "$FILE"; echo "$HEADER_CONTENT"; tail -c +4 "$FILE") > "$FILE.tmp" && mv "$FILE.tmp" "$FILE" + else + # Insère le header au début du fichier (pas de BOM) + (echo "$HEADER_CONTENT"; cat "$FILE") > "$FILE.tmp" && mv "$FILE.tmp" "$FILE" + fi +done + +echo "Ajout du header terminé." \ No newline at end of file diff --git a/apply_license_to_xml.sh b/apply_license_to_xml.sh new file mode 100755 index 0000000..cb8c1f3 --- /dev/null +++ b/apply_license_to_xml.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Chemin vers le fichier contenant le header de licence +HEADER_FILE="license_header.xml.txt" + +# Vérifie si le fichier contenant le header existe +if [[ ! -f "$HEADER_FILE" ]]; then + echo "Le fichier $HEADER_FILE n'existe pas. Veuillez le créer avant d'exécuter ce script." + exit 1 +fi + +# Lit le contenu du header +HEADER_CONTENT=$(<"$HEADER_FILE") + +# Ajoute le header après la ligne dans tous les fichiers .xsd, .config et .xml +#find . -type f \( -name "*.xsd" -o -name "*.config" -o -name "*.xml" \) | while read -r FILE; do +find . -type f \( -name "*.vbproj" \) | while read -r FILE; do + echo "Ajout du header dans $FILE..." + + # Vérifie si le fichier commence par un BOM + if head -c 3 "$FILE" | grep -q $'\xef\xbb\xbf'; then + # Le fichier contient un BOM + echo "Fichier avec BOM détecté : $FILE" + tail -c +4 "$FILE" > "$FILE.tmp" # Supprime temporairement le BOM + mv "$FILE.tmp" "$FILE" + BOM_PRESENT=true + else + BOM_PRESENT=false + fi + + # Insère le header après la ligne + awk -v header="$HEADER_CONTENT" -v bom="$BOM_PRESENT" ' + BEGIN { if (bom == "true") printf "\xef\xbb\xbf" } # Réinsère le BOM si nécessaire + /^<\?xml/ { print; print header; next } # Insère le header après + { print } + ' "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE" +done + +echo "Ajout du header terminé." diff --git a/license_header.vb.txt b/license_header.vb.txt new file mode 100644 index 0000000..cb83203 --- /dev/null +++ b/license_header.vb.txt @@ -0,0 +1,14 @@ +' Copyright (C) 2025 P4pillon.org +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU Affero 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 Affero General Public License for more details. +' +' You should have received a copy of the GNU Affero General Public License +' along with this program. If not, see . \ No newline at end of file diff --git a/license_header.xml.txt b/license_header.xml.txt new file mode 100644 index 0000000..cccb782 --- /dev/null +++ b/license_header.xml.txt @@ -0,0 +1,16 @@ + \ No newline at end of file