author | František Kučera <franta-hg@frantovo.cz> |
Mon, 11 Nov 2019 14:42:13 +0100 | |
branch | v_0 |
changeset 28 | 9172bd97ae99 |
permissions | -rwxr-xr-x |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#!/bin/bash |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
# Relational pipes |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
# |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
# This program is free software: you can redistribute it and/or modify |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
# it under the terms of the GNU General Public License as published by |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
# the Free Software Foundation, version 3 of the License. |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
# |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
# This program is distributed in the hope that it will be useful, |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
# GNU General Public License for more details. |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
# |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
# You should have received a copy of the GNU General Public License |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
# Quite dirty hack to get some information about given PDF file |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
# TODO: better field names, more stable API |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
# TODO: call a PDF library rather than parse output of a commandline tool with human readable output |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
if [[ $# == 0 ]]; then |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
echo "1"; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
if [[ "x$field" == "xPages" ]]; then echo "integer"; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
elif [[ -z "${field+x}" ]]; then echo "boolean"; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
else echo "string"; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
fi |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
elif [[ -f "$1" || -d "$1" ]]; then |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
info="`pdfinfo -isodates "$1"`"; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
valid=$?; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
if [[ "x$field" == "xPages" ]]; then |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
if [[ $valid == 0 ]]; then |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
echo "$info" | grep "^$field:" | sed -E 's/[^:]+:\s+(.*)/\1/g' | tr -d '\n'; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
else |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
printf 0; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
# exit 40; # TODO: null |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
fi |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
elif [[ -z "${field+x}" ]]; then |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
if [[ $valid == 0 ]]; then printf "true"; else printf "false"; fi |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
else |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
echo "$info" | grep "^$field:" | sed -E 's/[^:]+:\s+(.*)/\1/g' | tr -d '\n'; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
fi |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
else |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
exit 40; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
fi |