Debian Codegraph @

src/bibtexconv-odt

raw
1 #!/bin/sh
2 # ==========================================================================
3 # ____ _ _ _____ __ ______
4 # | __ )(_) |_|_ _|__\ \/ / ___|___ _ ____ __
5 # | _ \| | '_ \| |/ _ \ / | / _ \| '_ \ \ / /
6 # | |_) | | |_) | | __// \ |__| (_) | | | \ V /
7 # |____/|_|_.__/|_|\___/_/\_\____\___/|_| |_|\_/
8 #
9 # --- BibTeX Converter ---
10 # https://www.nntb.no/~dreibh/bibtexconv/
11 # ==========================================================================
12 #
13 # BibTeX Converter
14 # Copyright (C) 2010-2026 by Thomas Dreibholz
15 #
16 # This program is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 3 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #
29 # Contact: [email protected]
30
31 set -eu
32
33 # ====== Handle arguments ===================================================
34 if [ $# -ne 4 ] ; then
35 echo >&2 "Usage: $0 Template_ODT Output_ODT BibTeX_File Export_Script"
36 exit 1
37 fi
38 TEMPLATE_ODT="$1"
39 OUTPUT_ODT="$2"
40 BIBTEX_FILE="$3"
41 EXPORT_SCRIPT="$4"
42
43 # ====== Prepare temporary directory ========================================
44 TEMP_DIRECTORY="$(mktemp -d)"
45 trap 'rm -rf -- $TEMP_DIRECTORY' EXIT
46
47 # ====== Generate content.xml for ODT file ==================================
48 bibtexconv "$BIBTEX_FILE" --quiet <"$EXPORT_SCRIPT" >"$TEMP_DIRECTORY/content.xml"
49
50 # ====== Generate new ODT from template ODT with generated content.xml ======
51 cp "$TEMPLATE_ODT" "$TEMP_DIRECTORY/template.odt"
52 (
53 cd "$TEMP_DIRECTORY"
54 zip -q template.odt --out output.odt -r content.xml content.xml
55 )
56 mv "$TEMP_DIRECTORY/output.odt" "$OUTPUT_ODT"