Browse Source

inital commit

Daniel Sheffield 2 years ago
commit
3d88d6e933
5 changed files with 96 additions and 0 deletions
  1. 2 0
      gardening-calendar.fods
  2. 88 0
      gardening-calendar.sh
  3. 2 0
      rainfall.fods
  4. 2 0
      ruled-rainfall.fodt
  5. 2 0
      title.fodt

File diff suppressed because it is too large
+ 2 - 0
gardening-calendar.fods


+ 88 - 0
gardening-calendar.sh

@@ -0,0 +1,88 @@
+#!/bin/bash
+#
+# Depends: mktemp, realpath, pcal, ps2pdf, pdftk
+# Optional: libreoffice
+#
+# Manual steps:
+#   1. Configure spreadsheet for desired year.
+#   2. Prepare PDFs (only when libreoffice unavailable)
+#     Export all sheets (except Config) as PDF
+#     Print ruled page
+#     Print title page
+#
+set -euo pipefail
+#set -x
+usage(){
+    cat <<EOF
+
+  Usage ./${BASH_SOURCE[0]##*/} YEAR BI-WEEKLY-PLANNER TITLE-PAGE RULED-PAGE
+
+  Examples:
+     # generate calendar from prepared pdfs
+     ~/scripts/gardening-calendar.sh 2023 gardening-calendar.pdf title.pdf ruled.pdf
+ 
+     # generate calendar from libreoffice files (requires libreoffice)
+     ~/scripts/gardening-calendar.sh 2023 gardening-calander.ods title.odt ruled.odt
+ 
+     # generate calendar from mix of pdf and libreoffice files (requires libreoffice)
+     ~/scripts/gardening-calendar.sh 2023 gardening-calander.ods title.pdf ruled.odt
+
+EOF
+}
+die(){
+    echo $2 >&2
+    exit $1
+}
+exit_help(){
+    if ! ((1 == 0)); then
+        [ "${2-x}" == "x" ] || echo $2 >&2
+        usage >&2
+    else
+        usage >&1
+    fi
+    exit $1
+}
+
+declare -A FTYPES
+CD="$(pwd)"
+for i in "$@"; do
+    ([ "$i" == "-h" ] || [ "$i" == "--help" ]) && exit_help 0
+done
+YEAR="${1}" || exit_help 1 "Year is not set"
+CAL="$(realpath "${2}")" || exit_help 2 "Bi-weekly planner document not specified"
+TITLE="$(realpath "${3}")" || exit_help 3 "Title document not specified"
+RULE="$(realpath "${4}")" || exit_help 4 "Ruled page document not specified"
+for input in "${RULE}" "${TITLE}" "${CAL}"; do
+    [ -e "${input}" ] || die -1 "File doesn't exist: '${input}'"
+    ftype=$(file -b "${input}")
+    echo "${ftype}" | grep 'OpenDocument\|PDF' >/dev/null || die -1 "Unsupported file type: ${ftype}"
+    FTYPES["${input}"]="${ftype}"
+done
+cat <<EOF >&2
+Generating diary for ${YEAR}
+Bi-weekly planner is ${CAL} (${FTYPES["${CAL}"]})
+Title page is ${TITLE} (${FTYPES["${TITLE}"]})
+Ruled page is ${RULE} (${FTYPES["${RULE}"]})
+EOF
+WD=$(mktemp -d)
+cd ${WD}
+for input in "${RULE}" "${TITLE}" "${CAL}"; do
+    [[ "${FTYPES["${input}"]}" =~ "PDF document" ]] && $(cp "${input}" $(basename "${input}")) || soffice --convert-to pdf:writer_pdf_Export "${input}" 1>&2
+done
+# whatever the original format, we now have pdf in local directory
+RULE="$(basename "${RULE%.*}.pdf")"
+TITLE="$(basename "${TITLE%.*}.pdf")"
+CAL="$(basename "${CAL%.*}.pdf")"
+# generate 12 month calendar with pcal
+pcal -p -P a4 -m -K -g all -s 0:0:0 -T B -t Carlito-Bold/54 -d DejaVuSerifCondensed-Bold/24 -n courier/10 1 2023 12 | ps2pdf - > "${YEAR}-pcal.pdf"
+# generate 12 ruled pages
+pdftk R{A..L}="${RULE}" cat R{A..L}1 output ruled12.pdf
+# extract odd and even page sets
+for pages in odd even; do
+    pdftk S="${CAL}" cat S2-end${pages} output ${pages}.pdf
+done
+# collate month pages, ruled pages, even pages, odd pages
+# NOTE: even pages appear first because of config page in spreadsheet
+pdftk M="${YEAR}-pcal.pdf" R=ruled12.pdf O=odd.pdf E=even.pdf shuffle M R E O output collated.pdf
+# cat title with remaining pages
+pdftk T="${TITLE}" C=collated.pdf cat T C output "${CD}/${YEAR}-${CAL}"

File diff suppressed because it is too large
+ 2 - 0
rainfall.fods


File diff suppressed because it is too large
+ 2 - 0
ruled-rainfall.fodt


File diff suppressed because it is too large
+ 2 - 0
title.fodt


Some files were not shown because too many files changed in this diff