forked from openstack-archive/fuel-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docs.sh
executable file
·233 lines (201 loc) · 3.94 KB
/
build_docs.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
#!/bin/sh
# config
VENV='fuel-web-venv'
VIEW='0'
NOINSTALL='0'
HTML='docs/_build/html/index.html'
SINGLEHTML='docs/_build/singlehtml/index.html'
EPUB='docs/_build/epub/Fuel.epub'
LATEXPDF='docs/_build/latex/fuel.pdf'
PDF='docs/_build/pdf/Fuel.pdf'
# functions
check_if_debian() {
test -f '/etc/debian_version'
return $?
}
check_if_redhat() {
test -f '/etc/redhat-release'
return $?
}
check_java_present() {
which java 1>/dev/null 2>/dev/null
return $?
}
check_latex_present() {
which pdflatex 1>/dev/null 2>/dev/null
return $?
}
cd_to_dir() {
FILE="${0}"
DIR=`dirname "${FILE}"`
cd "${DIR}"
if [ $? -gt 0 ]; then
echo "Cannot cd to dir ${DIR}!"
exit 1
fi
}
redhat_prepare_packages() {
# prepare postgresql utils and dev packages
# required to build psycopg Python pgsql library
sudo yum -y install postgresql postgresql-devel
# prepare python tools
sudo yum -y install python-devel make python-pip python-virtualenv
}
debian_prepare_packages() {
# prepare postgresql utils and dev packages
# required to build psycopg Python pgsql library
sudo apt-get -y install postgresql postgresql-server-dev-all
# prepare python tools
sudo apt-get -y install python-dev python-pip make python-virtualenv
}
install_java() {
if check_if_debian; then
sudo apt-get -y install default-jre
elif check_if_redhat; then
sudo yum -y install java
else
echo 'OS is not supported!'
exit 1
fi
}
prepare_packages() {
if check_if_debian; then
debian_prepare_packages
elif check_if_redhat; then
redhat_prepare_packages
else
echo 'OS is not supported!'
exit 1
fi
}
prepare_venv() {
# activate venv
virtualenv "${VENV}" # you can use any name instead of 'fuel'
. "${VENV}/bin/activate" # command selects the particular environment
# install dependencies
pip install ./shotgun # this fuel project is listed in setup.py requirements
pip install -r 'nailgun/test-requirements.txt'
}
download_plantuml() {
if ! [ -f 'docs/plantuml.jar' ]; then
wget 'http://downloads.sourceforge.net/project/plantuml/plantuml.jar' -O 'docs/plantuml.jar'
fi
}
view_file() {
if [ "`uname`" = "Darwin" ]; then
open "${1}"
elif [ "`uname`" = "Linux" ]; then
xdg-open "${1}"
else
echo 'OS is not supported!'
exit 1
fi
}
build_html() {
make -C docs html
if [ "${VIEW}" = '1' ]; then
view_file "${HTML}"
fi
}
build_singlehtml() {
make -C docs singlehtml
if [ "${VIEW}" = '1' ]; then
view_file "${SINGLEHTML}"
fi
}
build_latexpdf() {
check_latex_present
if [ $? -gt 0 ]; then
echo 'You need to install LaTeX if you want to build PDF!'
exit 1
fi
make -C docs latexpdf
if [ "${VIEW}" = '1' ]; then
view_file "${LATEXPDF}"
fi
}
build_epub() {
make -C docs epub
if [ "${VIEW}" = '1' ]; then
view_file "${EPUB}"
fi
}
build_pdf() {
make -C docs pdf
if [ "${VIEW}" = '1' ]; then
view_file "${PDF}"
fi
}
clear_build() {
make -C docs clean
}
show_help() {
cat <<EOF
Documentation build helper
-o - Open generated documentation after build
-c - Clear the build directory
-n - Don't try to install any packages
-f - Documentation format [html,signlehtml,pdf,latexpdf,epub]
EOF
}
# MAIN
while getopts ":onhcf:" opt; do
case $opt in
o)
VIEW='1'
;;
n)
NOINSTALL='1'
;;
h)
show_help
exit 0
;;
c)
clear_build
exit 0
;;
f)
FORMAT="${OPTARG}"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
show_help
exit 1
;;
esac
done
cd_to_dir
check_java_present
if [ $? -gt 0 ]; then
install_java
fi
if [ "${NOINSTALL}" = '0' ]; then
prepare_packages
fi
prepare_venv
download_plantuml
if [ "${FORMAT}" = '' ]; then
FORMAT='html'
fi
case "${FORMAT}" in
html)
build_html
;;
singlehtml)
build_singlehtml
;;
pdf)
build_pdf
;;
latexpdf)
build_latexpdf
;;
epub)
build_epub
;;
*)
echo "Format ${FORMAT} is not supported!"
exit 1
;;
esac