From 5bfbe3b3fade35f7fb0749f58c0d620eb1e5dd09 Mon Sep 17 00:00:00 2001 From: onryo Date: Mon, 20 Feb 2023 15:38:57 +0100 Subject: [PATCH] cp replace.pl and update-copyrights.sh from hush3 --- util/replace.pl | 42 +++++++++++++++++++++++++++++++++++++++ util/update-copyrights.sh | 14 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 util/replace.pl create mode 100755 util/update-copyrights.sh diff --git a/util/replace.pl b/util/replace.pl new file mode 100755 index 0000000..51ab56d --- /dev/null +++ b/util/replace.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# Copyright (c) 2016-2023 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html + +use strict; +use warnings; +use autodie; +use Data::Dumper; +my ($find,$replace,@files) = @ARGV; + +usage() unless $find && defined $replace; +unless( @files ) { + printf "No files to replace stuff!"; + exit 0; +} + +my $fh; +print "Going to replace $find with $replace in " . scalar(@files) . " files\n"; + +for my $file (@files) { + if (-d $file) { + printf "Skipping directory $file\n"; + next; + } + unless ( -e $file ) { + printf "$file does not exist!\n"; + next; + } + open $fh, '<', $file; + my $content = join('',<$fh>); + $content =~ s/\Q$find\E/$replace/g; + close $fh; + + open $fh, '>', $file; + print $fh $content; + close $fh; +} + +sub usage { + die "$0 stringtofind stringtoreplace file [more files...]\n"; +} diff --git a/util/update-copyrights.sh b/util/update-copyrights.sh new file mode 100755 index 0000000..293602f --- /dev/null +++ b/util/update-copyrights.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Copyright (c) 2016-2023 The Hush developers +# Released under the GPLv3 + +# Usage: update-copyrights.sh 2021 2022 +# TODO: verify $1 and $2 exist +# TODO: verify ack and xargs exist on this system + +# This update comments in source code +ack -l -i "20..-20..*Hush dev" | xargs ./util/replace.pl -$1 -$2 + +# This updates the define which is used by C++ help output +./util/replace.pl "COPYRIGHT_YEAR $1" "COPYRIGHT_YEAR $2" src/clientversion.h +./util/replace.pl "COPYRIGHT_YEAR, $1" "COPYRIGHT_YEAR, $2" configure.ac