This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
82 lines (62 loc) · 1.94 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -eu
FORCE_CHECK=0
for arg in "$@"
do
case $arg in
-c|--check)
FORCE_CHECK=1
shift
;;
esac
done
book_name=$1
source_dir=$(mktemp -d -t obp-epub-fixup-src-XXXXXX)
target_dir=$(mktemp -d -t obp-epub-fixup-trg-XXXXXX)
cleanup () {
local rv=$?
rm -rf -- "$source_dir" "$target_dir"
exit $rv
}
trap cleanup EXIT
check_epub () {
epubcheck -q $OUTDIR/${book_name}_new.epub &> $OUTDIR/${book_name}_new.log
local err=$?
if [ $err -ne 0 ]; then
echo "[ERROR] Epubckeck reported errors, ${book_name}_new.log produced"
elif [ $err -eq 0 ] && [ -f ${book_name}_new.log ]; then
echo "[WARNING] Epubcheck issued warning messages, ${book_name}_new.log produced"
fi
}
pack_epub () {
cd ${target_dir}
zip -qX0 ${book_name}_new.epub mimetype
zip -qXr ${book_name}_new.epub META-INF/ \
OEBPS/
}
cd $(dirname $0)
# echo "Unzip epub document"
unzip -q ${book_name}.epub -d ${source_dir}
unzip -q ${book_name}.epub -d ${target_dir}
# echo "Fix toc.xhtml"
python3 src/fix_toc_xhtml.py ${source_dir}/OEBPS/toc.xhtml \
${target_dir}/OEBPS/toc.xhtml
# echo "Fix toc.ncx"
python3 src/fix_toc_ncx.py ${target_dir}/OEBPS/toc.xhtml \
${source_dir}/OEBPS/toc.ncx \
${target_dir}/OEBPS/toc.ncx
# echo "Fix title tags in book sections"
python3 src/fix_title_tag.py ${target_dir}/OEBPS/toc.xhtml \
${source_dir}/OEBPS/ \
${target_dir}/OEBPS/
# echo "Fix contents.xhtml"
python3 src/fix_contents_xhtml.py ${source_dir}/OEBPS/contents.xhtml \
${target_dir}/OEBPS/contents.xhtml
# echo "Create new epub file"
(pack_epub)
# echo "Copy epub file back"
cp ${target_dir}/${book_name}_new.epub $OUTDIR
if [ $FORCE_CHECK -eq 1 ]; then
# echo "Check epub for errors"
check_epub
fi