diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/lesson-dist | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/scripts/lesson-dist b/scripts/lesson-dist index 15ca2368..52184484 100755 --- a/scripts/lesson-dist +++ b/scripts/lesson-dist @@ -1,15 +1,16 @@ -#!/bin/sh +#!/bin/bash # Create a distributable archive for my lesson material -ARCHIVE="$(basename "$PWD").zip" -zip "${ARCHIVE}" $(find . -mindepth 1 -not -path './.*' -printf '%p ') +archive="$(basename "$PWD").zip" +readarray -t files < <(find . -mindepth 1 -not -path './.*' -printf '%p\n') +zip "${archive}" "${files[@]}" # TODO: replace hardcoded base dir -BASEDIR=/home/muhq/Documents/MyDocuments/Work/Schule/Unterricht +basedir=/home/muhq/Documents/MyDocuments/Work/Schule/Unterricht add_to_archive() { python3 <<EOF import zipfile -with zipfile.ZipFile("${ARCHIVE}", "a") as zf: +with zipfile.ZipFile("${archive}", "a") as zf: zf.write("$1", "$2") EOF } @@ -17,47 +18,47 @@ EOF add_custom_latex_to_archive() { for path in "$@" do - path_in_arc="$(echo "${path}" | sed -e "s%${BASEDIR}/%%")" + # trim the basedir from the file path + path_in_arc="${path//"$basedir"//}" add_to_archive "${path}" "${path_in_arc}" done } # Include license -add_custom_latex_to_archive "${BASEDIR}"/COPYING +add_custom_latex_to_archive "${basedir}"/COPYING # Include common latex code -add_custom_latex_to_archive "${BASEDIR}"/latex/common.tex \ - "${BASEDIR}"/latex/common_packages.tex \ - "${BASEDIR}"/latex/common_options.tex +add_custom_latex_to_archive "${basedir}"/latex/common.tex \ + "${basedir}"/latex/common_packages.tex \ + "${basedir}"/latex/common_options.tex # Include common images -add_custom_latex_to_archive "${BASEDIR}"/latex/images/** +add_custom_latex_to_archive "${basedir}"/latex/images/** # Include the needed latex classes if grep -Pzrq '(?s)documentclass.+test\}' .; then - add_custom_latex_to_archive "${BASEDIR}"/latex/test.cls + add_custom_latex_to_archive "${basedir}"/latex/test.cls fi if grep -Pzrq '(?s)documentclass.+arbeitsauftrag\}' .; then - add_custom_latex_to_archive "${BASEDIR}"/latex/arbeitsauftrag.cls + add_custom_latex_to_archive "${basedir}"/latex/arbeitsauftrag.cls fi if grep -Pzrq '(?s)documentclass.+handout\}' .; then - add_custom_latex_to_archive "${BASEDIR}"/latex/handout.cls + add_custom_latex_to_archive "${basedir}"/latex/handout.cls fi include_planning= if grep -Pzrq '(?s)documentclass.+map\}' .; then - add_custom_latex_to_archive "${BASEDIR}"/latex/map.cls + add_custom_latex_to_archive "${basedir}"/latex/map.cls include_planning=true fi if grep -Pzrq '(?s)documentclass.+sequence\}' .; then - add_custom_latex_to_archive "${BASEDIR}"/latex/sequence.cls + add_custom_latex_to_archive "${basedir}"/latex/sequence.cls include_planning=true fi if [ -n "${include_planning}" ]; then - add_custom_latex_to_archive "${BASEDIR}"/latex/common_planning*.tex + add_custom_latex_to_archive "${basedir}"/latex/common_planning*.tex fi - |
