|
| 1 | +#!/bin/bash |
| 2 | +# This file is part of the pgRouting project. |
| 3 | +# Copyright (c) 2026-2026 pgRouting developers |
| 4 | +# License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE |
| 5 | + |
| 6 | +# run from top of repository |
| 7 | +DIR=$(git rev-parse --show-toplevel) |
| 8 | +pushd "${DIR}" > /dev/null || exit 1 |
| 9 | + |
| 10 | +BASE="upstream/develop" |
| 11 | +if [ -n "$1" ]; then |
| 12 | + BASE="$1" |
| 13 | +fi |
| 14 | + |
| 15 | +ALLFILES=$(git diff-tree --no-commit-id --diff-filter=d --name-only -r "${BASE}" HEAD) |
| 16 | +CURRENT_YEAR=$(date +%Y) |
| 17 | + |
| 18 | +function update { |
| 19 | + if [ -z "$4" ]; then return; fi |
| 20 | + PREFIX="$1" |
| 21 | + SUFFIX="$2" |
| 22 | + LICENSE="$3" |
| 23 | + FILE="$4" |
| 24 | + CONTROL=$5 |
| 25 | + mapfile -t FILES <<< "$FILE" |
| 26 | + for file in "${FILES[@]}" ; do |
| 27 | + name=$(basename "${file}") |
| 28 | + year=$(git log --follow --format=%as --date default "${file}" | tail -1 | awk -F- '{print $1}') |
| 29 | + license=${LICENSE/years/${year}-${CURRENT_YEAR}} |
| 30 | + prefix="$PREFIX" |
| 31 | + if [ "$CONTROL" = "4" ] ; then |
| 32 | + prefix=$(head -1 "${file}")"\n${PREFIX}" |
| 33 | + fi |
| 34 | + perl -i -ne "print if $. > ${CONTROL}" "${file}" |
| 35 | + echo -e "${prefix}${license}${SUFFIX}" | cat - "${file}" > tmp.tmp && cp tmp.tmp "${file}" |
| 36 | + done |
| 37 | +} |
| 38 | + |
| 39 | +function update_gnu { |
| 40 | + if [ -z "$1" ]; then return; fi |
| 41 | + STARTMARK="PGR-GNU$(printf '*%.0s' {1..65})\n" |
| 42 | + ENDMARK=" $(printf '*%.0s' {1..68})PGR-GNU" |
| 43 | + FILE=$1 |
| 44 | + mapfile -t FILES <<< "$FILE" |
| 45 | + for file in "${FILES[@]}" ; do |
| 46 | + name=$(basename "${file}") |
| 47 | + year=$(git log --follow --format=%as --date default "${file}" | tail -1 | awk -F- '{print $1}') |
| 48 | + perl -pi -e "BEGIN{undef $/;} s|PGR-GNU.*\nFile.*\n|${STARTMARK}File: ${name}\n|" "${file}" |
| 49 | + perl -pi -e "BEGIN{undef $/;} s|This program(.*)PGR-GNU|${GPL2}\n\n${ENDMARK}|smg" "${file}" |
| 50 | + perl -pi -e "s/Copyright(.*)pgRouting developers/Copyright (c) ${year}-${CURRENT_YEAR} pgRouting developers/" "${file}" |
| 51 | + done |
| 52 | +} |
| 53 | + |
| 54 | +# -------------------------------------- |
| 55 | +# Creative commons |
| 56 | +# - doc: .rst |
| 57 | +# - docqueries: .pg .result |
| 58 | +# - pgtap: .pg |
| 59 | +# -------------------------------------- |
| 60 | + |
| 61 | +CCBYASA=":file: This file is part of the pgRouting project. |
| 62 | +:copyright: Copyright (c) years pgRouting developers |
| 63 | +:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0" |
| 64 | + |
| 65 | +GPL3LINES="# This file is part of the pgRouting project. |
| 66 | +# Copyright (c) years pgRouting developers |
| 67 | +# License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE" |
| 68 | + |
| 69 | +GPL2="This program is free software; you can redistribute it and\/or modify |
| 70 | +it under the terms of the GNU General Public License as published by |
| 71 | +the Free Software Foundation; either version 2 of the License, or |
| 72 | +(at your option) any later version. |
| 73 | +
|
| 74 | +This program is distributed in the hope that it will be useful, |
| 75 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 76 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 77 | +GNU General Public License for more details. |
| 78 | +
|
| 79 | +You should have received a copy of the GNU General Public License |
| 80 | +along with this program; if not, write to the Free Software |
| 81 | +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA." |
| 82 | + |
| 83 | + |
| 84 | +# CCBYASA |
| 85 | +FILE=$(grep '\.rst' <<< "${ALLFILES}") |
| 86 | +update "" "" "${CCBYASA}" "${FILE}" 3 |
| 87 | + |
| 88 | +FILE=$(grep -E '\.pg$' <<< "${ALLFILES}") |
| 89 | +update "/* " " */" "${CCBYASA}" "${FILE}" 3 |
| 90 | + |
| 91 | + |
| 92 | +# GPL3LINES |
| 93 | +FIND=("CMakeLists" "cmake\/pgr") |
| 94 | +for ext in "${FIND[@]}" ; do |
| 95 | + FILE=$(grep "$ext" <<< "${ALLFILES}") |
| 96 | + update "" "" "${GPL3LINES}" "${FILE}" 3 |
| 97 | +done |
| 98 | + |
| 99 | +FIND=("\.sh" "test\.conf" "\.yml") |
| 100 | +for ext in "${FIND[@]}" ; do |
| 101 | + FILE=$(grep "$ext" <<< "${ALLFILES}") |
| 102 | + update "" "" "${GPL3LINES}" "${FILE}" 4 |
| 103 | +done |
| 104 | + |
| 105 | +# GPL-2 |
| 106 | +FIND=("\.pl$" "\.cpp$" "\.c$" "\.h$" "\.hpp" "\.sql") |
| 107 | +for ext in "${FIND[@]}" ; do |
| 108 | + FILE=$(grep "$ext" <<< "${ALLFILES}") |
| 109 | + update_gnu "${FILE}" |
| 110 | +done |
| 111 | + |
| 112 | +# ignore symlinks |
| 113 | +git restore docqueries/pickDeliver/lc101.pg |
| 114 | +git restore docqueries/src/sampledata.pg |
| 115 | +git restore docqueries/pickDeliver/oneDepotData.pg |
0 commit comments