From 153a44876ea0877fbdd6d8f5c05f9772e64bb0f2 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 5 Jan 2022 20:36:43 +0100 Subject: [PATCH] chore: add a script to update copyright end-year --- scripts/update-copyright-years.sh | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/update-copyright-years.sh diff --git a/scripts/update-copyright-years.sh b/scripts/update-copyright-years.sh new file mode 100755 index 000000000..3665065db --- /dev/null +++ b/scripts/update-copyright-years.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +## run this script onece a year + +set -euo pipefail + +THIS_YEAR="$(date +'%Y')" + +fix_copyright_year() { + local file="$1" + if [[ $file != *.erl ]] && \ + [[ $file != *.ex ]] && \ + [[ $file != *.hrl ]] && \ + [[ $file != *.proto ]]; then + ## Ignore other file + return 0 + fi + local copyright_line + copyright_line="$(head -2 "$file" | grep -E "Copyright\s\(c\)\s.+\sEMQ" || true)" + local begin_year + begin_year="$(echo "$copyright_line" | sed -E 's#%% Copyright \(c\) (20..).*#\1#g')" + if [ "$begin_year" = "$THIS_YEAR" ]; then + ## new file added this year + return 0 + fi + if [ -z "$copyright_line" ]; then + ## No Copyright info, it is not intended to add one from this script + echo "Ignored $file" + return 0 + fi + sed -E "s#(%% Copyright \(c\) 20..)(-20.. | )(.*)#\1-$THIS_YEAR \3#g" -i "$file" +} + +while read -r file; do + fix_copyright_year "$file" +done < <(git ls-files)