1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#!/bin/bash
# Copyright 2017-2019, Paul Johnson (paul@pjcj.net)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
set -euo pipefail
script=$(basename "$0")
srcdir=$(readlink -f "$(dirname "$0")")
readonly LOG_FILE="/tmp/$script.log"
_p() { l=$1; shift; echo "$l $script: $*" | tee -a "$LOG_FILE" >&2; }
pt() { _p "[TRACE] " "$*"; }
pd() { _p "[DEBUG] " "$*"; }
pi() { _p "[INFO] " "$*"; }
pw() { _p "[WARNING]" "$*"; }
pe() { _p "[ERROR] " "$*"; }
pf() { _p "[FATAL] " "$*"; exit 1; }
usage() {
cat <<EOT
$script --help
$script --trace --verbose
$script update-copyright
EOT
exit 0
}
cleanup() {
declare -r res=$?
((verbose)) && pi "Cleaning up"
exit $res
}
PATH="$srcdir:$PATH"
verbose=0
force=0
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
shift
;;
-t|--trace)
set -x
shift
;;
-v|--verbose)
verbose=1
shift
;;
-f|--force)
force=1
shift
;;
*)
break
;;
esac
done
gcdir=$(readlink -f "$srcdir/..")
main() {
((verbose)) && pi "Running $*"
[ -z "${1:-}" ] && pf "Missing argument"
case "$1" in
update-copyright)
from="${2:-$(date +'%Y' --date='last year')}"
to="${3:-$(date +'%Y')}"
pi "Updating copyright from $from to $to"
me="Paul Johnson"
files=$(git ls-files)
# shellcheck disable=SC2086
perl -pi -e "s/Copyright \\d+-\\K$from(, $me)/$to\$1/i" $files
# shellcheck disable=SC2086
perl -pi -e "s/Copyright $from\\K(, $me)/-$to\$1/i" $files
;;
install_dependencies)
cpanm --notest \
Date::Manip Parse::RecDescent Roman Text::Soundex \
Pod::Markdown Test::Pod
;;
all_versions)
shift
./utils/all_versions "$@"
;;
__xx__)
shift
echo $force "$gcdir"
;;
options)
perl -nE 'say $1 =~ s/"//gr =~ s/\s*\|\s*/\n/gr' \
-E 'if /^ {8}"?([a-zA-Z0-9_ "|\\-]+)"?(?:\)|\s*\|\s*\\)$/' \
-E '&& $1 !~ /^_/' < "$0"
;;
*)
pf "Unknown option: $1"
;;
esac
}
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
trap cleanup EXIT INT
main "$@"
fi
|