Repository navigation
Expand file tree
/
Copy pathrun-linux.sh
More file actions
executable file
·447 lines (442 loc) · 14.3 KB
/
Copy pathrun-linux.sh
File metadata and controls
executable file
·447 lines (442 loc) · 14.3 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#!/bin/bash
# That tells Linux to use a Bourne shell interpreter.
# Don't echo these commands:
set +v
# Set initial variables.
process=0
bookfolder="book"
config=""
repeat=""
baseurl=""
location=""
firstfile=""
# Keep some options open for the user.
while [ "$process" = "0" ]
do
echo -n "
Electric Book options
---------------------
1. Create a print PDF
2. Create a screen PDF
3. Run as a website
4. Create EPUB-ready files
5. Export to Word
6. Install or update dependencies
7. Exit
Enter a number and hit enter. "
read process
##################
# PRINT PDF #
##################
if [ "$process" = "1" ]
then
# Remember the current folder
location=$(pwd)
# Ask user which folder to process
echo -n "Which book folder are we processing? (Hit enter for default 'book'.) "
read bookfolder
if [ "$bookfolder" = "" ]
then
bookfolder="book"
fi
echo "Okay, let's make a print-ready PDF using $bookfolder..."
# Ask if we're outputting the files from a subdirectory (e.g. a translation)
echo "If you're outputting files in a subdirectory (e.g. a translation), type its name. Otherwise, hit enter. "
read printpdfsubdirectory
# Ask the user to add any extra Jekyll config files, e.g. _config.pdf-ebook.yml
echo -n "
Any extra config files?
Enter filenames (including any relative path), comma separated, no spaces. E.g.
_configs/_config.myconfig.yml
If not, just hit return."
read config
# Ask whether we're processing MathJax, to know whether to send the HTML via PhantomJS
echo "Does this book use MathJax? If no, hit enter. If yes, type any key then enter."
read printpdfmathjax
# We're going to let users run this over and over by pressing enter
repeat=""
while [ "$repeat" = "" ]
do
# let the user know we're on it!
echo "Generating HTML..."
# ...and run Jekyll to build new HTML
# with MathJax enabled if necessary
if [ "$printpdfmathjax" = "" ]
then
bundle exec jekyll build --config="_config.yml,_configs/_config.print-pdf.yml,$config"
else
bundle exec jekyll build --config="_config.yml,_configs/_config.print-pdf.yml,_configs/_config.mathjax-enabled.yml,$config"
fi
# If using, MathJax, let PhantomJS render the HTML
if [ "$printpdfmathjax" = "" ]
then
echo "No MathJax, skipping PhantomJS."
else
echo "Rendering MathJax in HTML with PhantomJS. If you get an error, check that PhantomJS is installed."
# We have to go to the folder for Phantom to work
cd _site/assets/js
phantomjs render-mathjax.js
cd "$location"
fi
# Navigate into the book's folder in _site output
cd _site/$bookfolder/text/$printpdfsubdirectory
# Let the user know we're now going to make the PDF
echo Creating PDF...
# Set the PDF's filename
if [ "$printpdfsubdirectory"="" ]
then
printpdffilename="$bookfolder"
else
printpdffilename="$bookfolder-$printpdfsubdirectory.pdf"
fi
# Run prince, showing progress (-v), printing the docs in file-list
# and saving the resulting PDF to the _output folder
prince -v -l file-list -o ../../../_output/$printpdffilename.pdf
# Navigate back to where we began.
cd "$location"
# Tell the user we're done
echo Done! Opening PDF...
# Navigate to the _output folder...
cd _output
# and open the PDF we just created
# (for OSX, this will need to be open, not xdg-open)
xdg-open $bookfolder.pdf
# Navigate back to where we began.
cd ../
# Ask the user if they want to refresh the PDF by running Jekyll and Prince again
repeat=""
echo "Enter to run again, or any other key and enter to stop."
read repeat
done
# Head back to the Electric Book options
process=0
##################
# SCREEN PDF #
##################
elif [ "$process" = 2 ]
then
# Remember the current folder
location=$(pwd)
# Ask user which folder to process
echo -n "Which book folder are we processing? (Hit enter for default 'book'.) "
read bookfolder
if [ "$bookfolder" = "" ]
then
bookfolder="book"
fi
echo "Okay, let's make a screen PDF using $bookfolder..."
# Ask if we're outputting the files from a subdirectory (e.g. a translation)
echo "If you're outputting files in a subdirectory (e.g. a translation), type its name. Otherwise, hit enter. "
read screenpdfsubdirectory
# Ask the user to add any extra Jekyll config files, e.g. _config.pdf-ebook.yml
echo -n "
Any extra config files?
Enter filenames (including any relative path), comma separated, no spaces. E.g.
_configs/_config.myconfig.yml
If not, just hit return."
read config
# Ask whether we're processing MathJax, to know whether to send the HTML via PhantomJS
echo "Does this book use MathJax? If no, hit enter. If yes, type any key then enter."
read screenpdfmathjax
# We're going to let users run this over and over by pressing enter
repeat=""
while [ "$repeat" = "" ]
do
# let the user know we're on it!
echo "Generating HTML..."
# ...and run Jekyll to build new HTML
# with MathJax enabled if necessary
if [ "$screenpdfmathjax" = "" ]
then
bundle exec jekyll build --config="_config.yml,_configs/_config.screen-pdf.yml,$config"
else
bundle exec jekyll build --config="_config.yml,_configs/_config.screen-pdf.yml,_configs/_config.mathjax-enabled.yml,$config"
fi
# If using, MathJax, let PhantomJS render the HTML
if [ "$screenpdfmathjax" = "" ]
then
echo "No MathJax, skipping PhantomJS."
else
echo "Rendering MathJax in HTML with PhantomJS. If you get an error, check that PhantomJS is installed."
# We have to go to the folder for Phantom to work
cd _site/assets/js
phantomjs render-mathjax.js
cd "$location"
fi
# Navigate into the book's folder in _site output
cd _site/$bookfolder/text/$screenpdfsubdirectory
# Let the user know we're now going to make the PDF
echo Creating PDF...
# Set the PDF's filename
if [ "$screenpdfsubdirectory"="" ]
then
screenpdffilename="$bookfolder"
else
screenpdffilename="$bookfolder-$screenpdfsubdirectory.pdf"
fi
# Run prince, showing progress (-v), printing the docs in file-list
# and saving the resulting PDF to the _output folder
prince -v -l file-list -o ../../../_output/$screenpdffilename.pdf
# Navigate back to where we began.
cd "$location"
# Tell the user we're done
echo Done! Opening PDF...
# Navigate to the _output folder...
cd _output
# and open the PDF we just created
# (for OSX, this will need to be open, not xdg-open)
xdg-open $bookfolder.pdf
# Navigate back to where we began.
cd ../
# Ask the user if they want to refresh the PDF by running Jekyll and Prince again
repeat=""
echo "Enter to run again, or any other key and enter to stop."
read repeat
done
# Head back to the Electric Book options
process=0
##################
# WEBSITE #
##################
elif [ "$process" = 3 ]
then
echo "Okay, let's make a website..."
# Ask the user to add any extra Jekyll config files, e.g. _config.pdf-ebook.yml
echo -n "
Any extra config files?
Enter filenames (including any relative path), comma separated, no spaces. E.g.
_configs/_config.myconfig.yml
If not, just hit return."
read config
# Ask the user to set a baseurl if needed
echo -n "Do you need a baseurl?
If yes, enter it with no slashes at the start or end, e.g.
my/base
"
read baseurl
# let the user know we're on it!
echo "Getting your site ready...
You may need to reload the web page once this server is running."
# Open the web browser, without or, then, with the baseurl
# (This is before jekyll s, because jekyll s pauses the script.)
if [ "$baseurl" = "" ]
then
xdg-open "http://127.0.0.1:4000/"
else
xdg-open "http://127.0.0.1:4000/$baseurl/"
fi
# We're going to let users run this over and over by pressing enter
repeat=""
while [ "$repeat" = "" ]
do
# ...and run Jekyll
if [ "$baseurl" = "" ]
then
bundle exec jekyll serve --config="_config.yml,_configs/_config.web.yml,$config" --baseurl=""
else
bundle exec jekyll serve --config="_config.yml,_configs/_config.web.yml,$config" --baseurl="/$baseurl"
fi
# Ask the user if they want to rebuild the site
# TO DO: Not sure this works because Jekyll owns the terminal and Ctrl+C will kill it entirely?
repeat=""
echo "Enter to run again, or any other key and enter to stop."
read repeat
done
# Head back to the Electric Book options
process=0
##################
# EPUB #
##################
elif [ "$process" = 4 ]
then
# Remember the current folder
location=$(pwd)
# Ask user which folder to process
echo -n "Which book folder are we processing? (Hit enter for default 'book'.) "
read bookfolder
if [ "$bookfolder" = "" ]
then
bookfolder="book"
fi
echo "Okay, let's make epub-ready files using $bookfolder..."
# Ask if we're outputting the files from a subdirectory (e.g. a translation)
echo "If you're outputting files in a subdirectory (e.g. a translation), type its name. Otherwise, hit enter. "
read epubsubdirectory
echo -n "What is the first file in your book? Usually the cover.
(Don't include the file extension. Hit enter for the default '0-0-cover'.) "
read firstfile
if [ "$firstfile" = "" ]
then
firstfile="0-0-cover"
fi
# Ask the user to add any extra Jekyll config files, e.g. _config.myconfig.yml
echo -n "
Any extra config files?
Enter filenames (including any relative path), comma separated, no spaces. E.g.
_configs/_config.myconfig.yml
If not, just hit return."
read config
# Ask whether we're processing MathJax, to know whether to send the HTML via PhantomJS
echo "Does this book use MathJax? If no, hit enter. If yes, type any key then enter."
read epubmathjax
# We're going to let users run this over and over by pressing enter
repeat=""
while [ "$repeat" = "" ]
do
# let the user know we're on it!
echo "Generating HTML..."
# ...and run Jekyll to build new HTML, enabling MathJax if necessary
if [ "$epubmathjax" = "" ]
then
bundle exec jekyll build --config="_config.yml,_configs/_config.epub.yml,$config"
else
bundle exec jekyll build --config="_config.yml,_configs/_config.epub.yml,_configs/_config.mathjax-enabled.yml,$config"
fi
# Navigate to the relevant text folder...
if [ "$epubsubdirectory" = "" ]
then
cd _site/$bookfolder/text
else
cd _site/$bookfolder/text/$epubsubdirectory
fi
# ...and open the first epub file there.
# Let the user know we're now going to open Sigil.
# NOTE: Sigil is not well supported on Linux, so many users won't have it.
echo "Opening Sigil..."
sigil "$firstfile.html"
# Open file browser to see epub-ready HTML files
xdg-open .
# Navigate back to where we started
cd "$location"
# Ask the user if they want to refresh the PDF by running Jekyll and Prince again
repeat=""
echo "Enter to run again, or any other key and enter to stop."
read repeat
done
# Head back to the Electric Book options
process=0
##################
# EXPORT TO WORD #
##################
elif [ "$process" = 5 ]
then
echo "Okay, let's export to Word. You must have Pandoc installed for this to work."
# Remember current location
location=$(pwd)
# Ask user which folder to process
echo -n "Which book folder are we processing? (Hit enter for default 'book'.) "
read bookfolder
if [ "$bookfolder" = "" ]
then
bookfolder="book"
fi
echo "Okay, let's make Word files for $bookfolder..."
# Ask user which output format to work from
echo "Which format are we converting from? Enter a number or hit enter for the default 'print-pdf'. "
echo -n "
1. Print PDF (default)
2. Screen PDF
3. Web
4. Epub
Enter a number and/or hit enter. "
read fromformat
# Turn that choice into a variable named for the format
wordformatchoice=""
while [ "$wordformatchoice" = "" ]
do
if [ "$fromformat" = "" ]
then
fromformat="print-pdf"
wordformatchoice="1"
elif [ "$fromformat" = "1" ]
then
fromformat="print-pdf"
wordformatchoice="1"
elif [ "$fromformat" = "2" ]
then
fromformat="screen-pdf"
wordformatchoice="1"
elif [ "$fromformat" = "3" ]
then
fromformat="web"
wordformatchoice="1"
elif [ "$fromformat" = "4" ]
then
fromformat="epub"
wordformatchoice="1"
else
wordformatchoice=""
fi
done
# Ask the user to add any extra Jekyll config files, e.g. _config.myconfig.yml
echo -n "
Any extra config files?
Enter filenames (including any relative path), comma separated, no spaces. E.g.
_configs/_config.myconfig.yml
If not, just hit return."
read config
# We're going to let users run this over and over by pressing enter
repeat=""
while [ "$repeat" = "" ]
do
# let the user know we're on it!
echo "Generating HTML..."
# ...and run Jekyll to build new HTML
bundle exec jekyll build --config="_config.yml,_configs/_config.$fromformat.yml,$config"
# Navigate into the book's folder in _site output
cd _site/$bookfolder/text
# Update user
echo "Converting $bookfolder HTML to Word..."
# Loop through the list of files in file-list
# and convert them each from .html to .docx.
# We end up with the same filenames,
# with .docx extensions appended.
# [Two loop methods to try here. This one:]
while read -r file
do
pandoc "$file" -f html -t docx -s -o $file.docx
done < file-list
# [And this one:]
# for file in file-list
# do
# pandoc "$file" -f html -t docx -s -o $file.docx
# done
# Now we fix those file extensions
echo "Fixing file extensions..."
for file in *.html.docx
do
mv "${file}" "${file/.html.docx/.docx}"
done
# Tell the user we're done
echo Done! Opening file explorer...
# Open file explorer to show the docx files
xdg-open .
# Navigate back to where we began.
cd "$location"
# Ask the user if they want to run that again
repeat=""
echo "Enter to run again, or any other key and enter to stop."
read repeat
done
# Head back to the Electric Book options
process=0
##################
# INSTALL #
##################
elif [ "$process" = 6 ]
then
echo "Running Bundler to update and install dependencies.
If Bundler is not already installed, exit and run
gem install bundler
from the command line."
# Update gems
bundle update
# Install gems
bundler install
# Head back to the Electric Book options
process=0
##################
# EXIT #
##################
fi
done