-
Notifications
You must be signed in to change notification settings - Fork 35
/
h-get
executable file
·371 lines (320 loc) · 7.36 KB
/
h-get
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
#!/usr/bin/env bash
__PWD="$PWD"
__version="0.9" #TODO: to be automatic
__author='Rhiokim <[email protected]>'
__process_header="Haroopress $__version $__author"
__pid=$$
__instance="haroopress[$__pid]"
__LOCKFILE="${PWD}/.h-get.lock"
# prefix(__) is removed for compatibility
SOURCE_DIR="${PWD}/source/public"
DEPLOY_DIR="${PWD}/_deploy"
PUBLIC_DIR="${PWD}/_public"
declare -i __arguments_length=$#
declare -i __pre_requisite_not_found=0
__HCMD=$1
trap "{ __cleanup; }" SIGINT SIGTERM SIGHUP SIGQUIT
# for secure processing, multiple process is not allowed.
[ -f $__LOCKFILE ] && echo "another h-get process is running. quit" && exit 0
touch $__LOCKFILE
__cleanup ()
{
echo ${__instance} -- got an Interrupt.
__remove_lock
exit 0
}
__remove_lock ()
{
rm -f $__LOCKFILE
}
# showing copyright first of all
echo $__process_header
echo
__usage ()
{
echo "./h-get [<cmd>]"
echo " cmd:"
echo " help"
echo " gen -- generate static page"
echo " preivew -- preview a post"
echo " new-post | a-post -- writing a new post"
echo " new-page | a-page -- writing a new page"
echo " new-slide | a-page -- writing a new slide"
echo " init | install -- setup Haroopress"
echo " clear"
echo "------------------------------------------------------"
__guide
echo
}
__log ()
{
echo " --------------- $*"
}
__stop ()
{
if [ "$*" != "0" ]; then
__log "[ STOP! ]"
__remove_lock; exit 0
fi
}
__guide ()
{
cat ${__PWD}/lib/haroopress/QUICK.markdown
}
__initialize ()
{
if [ -e "${__PWD}/.init.done" ]; then
echo " -- init process is already done"
return
fi
__log "start: initilizing"
cd $__PWD; ./bin/init.js
__stop $?
touch ${__PWD}/.init.done
__log "end: initilizing"
}
__init_update_git_submodules ()
{
if [ -e "${__PWD}/.init-git-submodules.done" ]; then
echo " -- git submodule update is already done"
return
fi
__log "start: updating git submodules"
cd $__PWD; git submodule update --init --recursive
__stop $?
touch ${__PWD}/.init-git-submodules.done
__log "end: updating git submodules"
}
__init_install_locally ()
{
if [ -e "${__PWD}/.init-install-locally.done" ]; then
echo " -- locally installation is already done"
return
fi
__log "start: updating locally"
cd $__PWD; cd ./node_modules/locally/; npm install
__stop $?
touch ${__PWD}/.init-install-locally.done
__log "end: updating locally"
}
__init_install_python_modules ()
{
if [ -e "${__PWD}/.init-install-python-modules.done" ]; then
echo " -- python modules installation is already done"
return
fi
__log "start: updating python modules"
cd $__PWD; python ./lib/highlight.js/tools/build.py
__stop $?
touch ${__PWD}/.init-install-python-modules.done
__log "end: updating python modules"
}
__rebuild_node_modules ()
{
if [ -e "${__PWD}/.init-rebuild-node-modules.done" ]; then
echo " -- updating node modules is already done"
return
fi
__log "start: updating node modules"
cd $__PWD/node_modules/robotskirt/
node-gyp rebuild
__stop $?
touch ${__PWD}/.init-rebuild-node-modules.done
__log "end: updating node modules"
}
__setup ()
{
if [ -e "${__PWD}/.setup.done" ]; then
echo " -- setup procedure is already done"
return
fi
cd $__PWD; ./bin/setup.js
__stop $?
touch ${__PWD}/.setup.done
}
__clear ()
{
__log "clear"
cd $__PWD; ./bin/clear.js
}
__gh_pages ()
{
if [ -e "${__PWD}/.gh-pages.done" ]; then
echo " -- gh-pages process is already done"
return
fi
__log "start: gh-pages"
__clear
cd $__PWD/bin; ./gh-pages.js
__stop $?
touch ${__PWD}/.gh-pages.done
__log "end: gh-pages"
}
__assert ()
{
__expr__="$*"
`${__expr__} > /dev/null 2>&1`
if [ $? -ne 0 ]; then
__pre_requisite_not_found=$(( __pre_requisite_not_found + 1))
return 1
fi
return 0
}
__guide_install_nodejs ()
{
__log "[ NodeJS ] missing"
__log "Ubuntu: sudo apt-get install nodejs nodejs-dev"
__log "Mac OS: brew install nodejs"
echo
}
__guide_install_nodegyp ()
{
__log "[ node-gyp ] missing"
__log "Ubuntu \& Mac OS: npm install node-gyp -g"
echo
}
__guide_install_python ()
{
__log "[ python ] missing"
}
__guide_install_java ()
{
__log "[ java ] missing"
}
__guide_install_git ()
{
__log "[ git ] missing"
__log "Ubuntu: sudo apt-get install git-core"
__log "Mac OS: brew install git"
echo
}
__guide_install_gpp ()
{
__log "[ g++ or gcc ] missing"
__log "Ubuntu: sudo apt-get install build-essentail"
__log "Mac OS: Install XCode and commandline tools"
echo
}
__chk_pre_requisites ()
{
__assert node -v || __guide_install_nodejs
__assert node-gyp -v || __guide_install_nodegyp
__assert python --version || __guide_install_python
__assert java -version || __guide_install_java
__assert git --version || __guide_install_git
__assert g++ -v || __guide_install_gpp
__assert gcc -v || __guide_install_gpp
if [ $__pre_requisite_not_found -gt 0 ]; then
echo
echo "[STOP] You need to install $__pre_requisite_not_found package(s) first! (See INSTALL.pre-requisites)"
echo
__remove_lock; exit 0
fi
#TODO: robotskirt gyp module, PGP key for pushing at github
}
__gen ()
{
__log "start: gen"
__clear
cd $__PWD; ./bin/gen.js
mkdir -p ${PUBLIC_DIR}/slides/@asserts
cp -R ./lib/shower/themes ${PUBLIC_DIR}/slides/@asserts
cp -R ./lib/shower/scripts ${PUBLIC_DIR}/slides/@asserts
mkdir -p ${PUBLIC_DIR}/css/code
cp -R ./lib/highlight.js/src/styles/* ${PUBLIC_DIR}/css/code
cp -R ./lib/highlight.js/build/* ${PUBLIC_DIR}/js
cp -R ./lib/bootstrap/* ${PUBLIC_DIR}
__log "end: gen"
}
__preview ()
{
__log "start: preview"
cd $__PWD; ./bin/preview.js
__log "end: preview"
}
__deploy ()
{
__log "start: deploy"
cd $__PWD/bin; ./deploy.js "${msg}" # where is comes from ?
__log "end: deploy"
}
__main ()
{
if [ $__arguments_length -le 0 ]; then
__usage
return;
fi
if [[ "$__HCMD" == "guide" ]] || [[ "$__HCMD" == "help" ]]; then
__guide
return
fi
if [[ "$__HCMD" == "setup" ]]; then
__chk_pre_requisites
__setup
return;
fi
if [[ "$__HCMD" == "clear" ]]; then
__clear
return;
fi
if [[ "$__HCMD" == "gh-pages" ]]; then
__chk_pre_requisites
__gh_pages
return;
fi
if [[ "$__HCMD" == "new-post" ]] || [[ "$__HCMD" == "a-post" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-post.js
return;
fi
if [[ "$__HCMD" == "new-page" ]] || [[ "$__HCMD" == "a-page" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-page.js
return;
fi
if [[ "$__HCMD" == "new-slide" ]] || [[ "$__HCMD" == "a-slide" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-slide.js
return;
fi
if [[ "$__HCMD" == "octopress" ]] || [[ "$__HCMD" == "convert" ]]; then
__chk_pre_requisites
cd $__PWD/bin/convert; ./octopress.js
return;
fi
if [[ "$__HCMD" == "init" ]] || [[ "$__HCMD" == "install" ]]; then
__chk_pre_requisites
__init_update_git_submodules
__init_install_locally
__init_install_python_modules
__rebuild_node_modules
__setup
__gh_pages
__initialize
return;
fi
if [[ "$__HCMD" == "check" ]]; then
__chk_pre_requisites
echo " [ OK ] -- You're good to go"
echo
fi
if [[ "$__HCMD" == "gen" ]]; then
__chk_pre_requisites
__gen
return
fi
if [[ "$__HCMD" == "preview" ]]; then
__chk_pre_requisites
__gen
__preview
return
fi
if [[ "$__HCMD" == "deploy" ]]; then
__chk_pre_requisites
__gen
__deploy
return
fi
}
__main "$*"
__remove_lock; exit 0