fix(unitproc/bkshuf):Make executable
[BK-2020-03.git] / user / mw_create_year_journal.sh
CommitLineData
b1ce1fa2
SBS
1#!/usr/bin/env bash
2# Desc: Prints mediawiki code for a journal year in the bk4 wiki.
3# Usage: /bin/bash mw_create_year_journal.sh [int year]
4# Input: arg1: year
5# Example: /bin/bash mw_create_year_journal.sh 2023 > output.txt
424bda7b 6# Version: 0.1.0
b1ce1fa2
SBS
7
8yyyy="$1";
9
10yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
11die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
12must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
13
14# Check input
15## Check arg count
16if [[ $# -ne 1 ]]; then die "FATAL:Invalid arg count:$#"; fi;
17## Strip leading zeros
18yyyy="$((10#${yyyy}))";
19
20## Check year
21re="[0-9]+";
22if [[ ! $yyyy =~ $re ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
23if [[ ! $yyyy -ge 1582 ]]; then die "FATAL:Invalid year string:$yyyy"; fi;
24
25# Calc working vars
26## Years
27yyyy_prev="$((yyyy - 1))";
28yyyy_next="$((yyyy + 1))";
29
30# Form and print header
31printf "{{bk journal header year}}\n";
32printf "[[Journal]] for the year [[%d]]. " "$yyyy";
33printf "Preceded by [[%d]]. " "$yyyy_prev";
34printf "Followed by [[%d]]. " "$yyyy_next";
35printf "\n\n";
36
37printf "==Events==\n";
38printf "\n";
39
40# Form and print body
41for (( mm=1; mm <= 12; mm++ )); do
42 printf "==[[%4d-%02d]]==\n" "$yyyy" "$mm";
43done;
44printf "\n";
45
46# Form and print footer
47s1="==References==";
48s2="<references>";
49s3="</references>";
50printf "%s\n%s\n%s\n" "$s1" "$s2" "$s3";
51printf "\n";
52
53printf "==See Also==\n";
424bda7b 54printf "* [[Summary of months of {{PAGENAME}}]]\n"
b1ce1fa2
SBS
55printf "\n";
56
57printf "==Ext. Links==\n";
58printf "\n";
59
60printf "{{bk journal footer year}}\n";
61
62s1="[[Category:Journals by year]]";
63printf "%s\n" "$s1";
64printf "\n";