-
Notifications
You must be signed in to change notification settings - Fork 5
/
run-linux.sh
247 lines (243 loc) · 7.78 KB
/
run-linux.sh
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
#!/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. Install or update dependencies
6. Exit
Enter a number and hit enter. "
read process
##################
# PRINT PDF #
##################
if [ "$process" = "1" ]
then
# Ask user which folder to process
echo -n "Which book folder are we processing? "
read bookfolder
echo "Okay, let's make a print-ready PDF using $bookfolder..."
# 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
# We're going to let users run this over and over by pressing enter
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.print-pdf.yml,$config"
# Navigate into the book's folder in _html output
cd _html/$bookfolder/text
# Let the user know we're now going to make the PDF
echo Creating PDF...
# 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/$bookfolder.pdf
# Navigate back to where we began.
cd ../../..
# 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
# Ask user which folder to process
echo -n "Which book folder are we processing? "
read bookfolder
echo "Okay, let's make a screen PDF using $bookfolder..."
# 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
# We're going to let users run this over and over by pressing enter
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.screen-pdf.yml,$config"
# Navigate into the book's folder in _html output
cd _html/$bookfolder/text
# Let the user know we're now going to make the PDF
echo Creating PDF...
# 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/$bookfolder.pdf
# Navigate back to where we began.
cd ../../..
# 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
# We're going to let users run this over and over by pressing enter
while [ "$repeat" = "" ]
do
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, withour 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
# ...and run Jekyll
bundle exec jekyll serve --config="_config.yml,_configs/_config.web.yml,$config" --baseurl="/$baseurl"
# 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
# Ask user which folder to process
echo -n "Which book folder are we processing? "
read bookfolder
echo -n "What is the first file in your book? usually the cover.
(Don't include the file extension. Default is 0-0-cover.) "
read firstfile
if [ "$firstfile" = "" ]
then
firstfile="0-0-cover"
fi
# Remember the current folder
location=$(pwd)
# 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
echo "Okay, let's make epub-ready files using $bookfolder..."
# We're going to let users run this over and over by pressing enter
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.epub.yml,$config"
# Navigate into the book's folder in _html output
cd _html/$bookfolder/text
# Navigate back to where we began.
cd $location
# Navigate to the _output folder...
cd _output/$bookfolder/text
# and open the first epub file
# Let the user know we're now going to open Sigil
# NOTE: Sigil is not supported on Linux, so many users won't have it.
echo "Opening Sigil..."
sigil "$firstfile.html"
# Navigate back to where we began.
cd $location
# Got into HTML-output folder
cd _html/$bookfolder
# 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
##################
# INSTALL #
##################
elif [ "$process" = 5 ]
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