-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild
executable file
·126 lines (106 loc) · 4.13 KB
/
build
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
substitute_intro()
{
sed "s/@TEMPLATE=INTRO@/$3/g" $1 >> $2
}
copy_contents()
{
cat $1 >> $2
}
add_comment()
{
comment="\
<!---\n\
****************************************************************************\n\
* *\n\
* Automatically generated file. Do not edit. Edit template file instead. *\n\
* *\n\
****************************************************************************\n\
--->"
echo -e "$comment" > $1
}
remove_links()
{
sed -i "s/\[\([^]]*\)\]([^)]*)/\1/g" $1
}
md_to_odt()
{
pandoc -s $1 -t odt -o $2
}
zip_to_dir()
{
rm -rf workdir
unzip -q $1 -d workdir
cd workdir
}
dir_to_zip()
{
rm -f ../$1
zip -q -r ../$1 .
cd ..
rm -rf workdir
}
move_result()
{
mkdir -p $1
mv $2 $1/
mv $3 $1/
}
modify_slave_content()
{
# Remove bullets
xmlstarlet edit -L -d './/*/text:list-level-style-bullet' content.xml
xmlstarlet edit -L -s './/*/text:list-style' -t elem -n 'text:list-level-style-bullet text:level="1" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="-"' content.xml
xmlstarlet edit -L -s './/*/text:list-level-style-bullet' -t elem -n 'style:list-level-properties text:space-before="0in" text:min-label-width="0.25in"' content.xml
# Remove number of abbreviation list
xmlstarlet edit -L -s './/*/office:automatic-styles' -t elem -n 'style:style style:name="Heading_No_Numbers" style:family="paragraph" style:parent-style-name="Heading_20_1" style:list-style-name=""' content.xml
xmlstarlet edit -L -s './/*/style:style[@style:name="Heading_No_Numbers"]' -t elem -n 'style:paragraph-properties style:writing-mode="page"' content.xml
xmlstarlet edit -L -u './/*/text:h[text() = "Перечень сокращений"]/@text:style-name' -v 'Heading_No_Numbers' content.xml
}
modify_master_content()
{
xmlstarlet edit -L -u './/*/text:variable-set[@text:name="Децимальныйномер"]' -v "${DN}" content.xml
xmlstarlet edit -L -u './/*/text:variable-get[@text:name="Децимальныйномер"]' -v "${DN}" content.xml
xmlstarlet edit -L -u './/*/text:variable-set[@text:name="Имя1"]' -v "${NAME1^^}" content.xml
xmlstarlet edit -L -u './/*/text:variable-set[@text:name="Имя2"]' -v "${NAME2^^}" content.xml
xmlstarlet edit -L -u './/*/text:variable-set[@text:name="ИмяВГенитиве"]' -v "${NAMEOF}" content.xml
}
echo "Creating Git Markdown manual..."
. reimu-git.conf
add_comment $OUTPUTFILE
substitute_intro $INPUTFILE $OUTPUTFILE "$NAME1 $NAME2 $DESIGNEDTO"
echo "Creating Git Markdown integration manual..."
. integration-git.conf
add_comment $OUTPUTFILE
copy_contents $INPUTFILE $OUTPUTFILE
echo "Creating Git Markdown build manual..."
. build-git.conf
add_comment $OUTPUTFILE
copy_contents $INPUTFILE $OUTPUTFILE
for product in 306 308 dacn
do
for document in reimu build
do
echo "Creating $document-$product ESPD Markdown intermediate..."
. $document-espd.conf.$product
add_comment $MARKDOWNFILE
substitute_intro $INPUTFILE $MARKDOWNFILE "$NAME1 $NAME2 $DESIGNEDTO"
echo "Removing links from Markdown intermediate..."
remove_links $MARKDOWNFILE
echo "Creating $document-$product ESPD slave document..."
md_to_odt $MARKDOWNFILE $INTERMEDIATE
echo "Altering styles for $document-$product ESPD slave OpenDocument..."
zip_to_dir $INTERMEDIATE
modify_slave_content
dir_to_zip $OUTPUTDATAFILE
echo "Setting variables for $document-$product ESPD master OpenDocument..."
zip_to_dir $ROOTTEMPLATE
modify_master_content
dir_to_zip $OUTPUTROOTFILE
echo "Moving master and slave documents to output directory $OUTPUTDIR"
move_result $OUTPUTDIR $OUTPUTROOTFILE $OUTPUTDATAFILE
done
done
echo
echo "All documents are ready. Now you could export .odm to final .odt."
echo "More info of how to do this: https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Writer_Guide/Creating_one_file_from_a_master_document"