Line # Revision Author
1 8 ahitrov@rambler.ru ##############################################################################
2 # $HeadURL$
3 # $Id$
4 ###############################################################################
5
6 # installation settings
7 include ../../config.mk
8
9 # local defines
10 SOURCES = ${ROOT_DIR}/src
11 CORE_SRC = ${SOURCES}/core
12 PLUG_SRC = ${SOURCES}/plugins
13 PROJ_SRC = ${SOURCES}/projects
14
15 CORE_USR = ${ROOT_DIR}/usr/core
16 PLUG_USR = ${ROOT_DIR}/usr/plugins
17 PROJ_USR = ${ROOT_DIR}/usr/projects
18 PROJ_TMP = ${ROOT_DIR}/tmp/projects
19 PROJ_VAR = ${ROOT_DIR}/var/projects
20
21 PORTSDIR = ${CORE_SRC}/ports
22 LOCAL = ${ROOT_DIR}/usr/local
23 PORTSWRK = ${ROOT_DIR}/var/ports
24
25 CORE_VERSION = ${shell svnversion ${CORE_SRC}}
26
27 PAGER ?= ${shell which less || which more}
28 RSYNC_COMMAND = ${shell which rsync}
29
30 HOSTNAME = ${shell hostname}
31
32 PROJECT_LC = ${shell echo "${PROJECT}" | tr '[:upper:]' '[:lower:]'}
33
34 # core settings
35 include ${CORE_SRC}/config.mk
36
37 # perl settings
38 include ${CORE_SRC}/ports/etc/perl.mk
39
40 # project settings
41 ifdef PROJECT
42 ifneq (${shell test -f ${PROJ_SRC}/${PROJECT}/config.mk && echo 1},1)
43 ${error ERROR: no source ${PROJECT}/config.mk found, are you checked out project '${PROJECT}'?}
44 endif
45 -include /usr/local/etc/contenido.mk
46 RSYNC_SERVERS ?= ${addsuffix ::${PROJECT_LC}, ${FRONTENDS}}
47 include ${PROJ_SRC}/${PROJECT}/config.mk
48 include ${CORE_SRC}/project-default.mk
49
50 ifeq (${shell test -f ${PROJ_SRC}/${PROJECT}/GNUmakefile && echo 1},1)
51 include ${PROJ_SRC}/${PROJECT}/GNUmakefile
52 $(warning Use of GNUmakefile in project dir is deprecated, rename it to GNUmakefile.in)
53 endif
54 -include ${PROJ_SRC}/${PROJECT}/GNUmakefile.in
55
56 PROJECT_VERSION = ${shell svnversion ${PROJ_SRC}/${PROJECT}}
57 endif
58
59 .PHONY: \
60 local_clean realclean \
61 local_build build \
62 local_install install \
63 local_preview preview \
64 \
65 core_status cst \
66 core_update cup \
67 core_commit cci \
68 core_install cin \
69 core_info cinfo \
70 614 ahitrov core_rsync crs \
71 8 ahitrov@rambler.ru \
72 project_status pst \
73 project_update pup \
74 project_commit pci \
75 project_install pin \
76 project_conf conf \
77 project_rsync prs \
78 project_start start \
79 project_stop stop \
80 project_create create \
81 project_import import \
82 project_info pinfo \
83 project_reload reload \
84 project_fullreload full \
85 project_rewind rewind nano \
86 project_refresh refresh \
87 project_deinstall pdi \
88 project_user user \
89 project_switch switch swi \
90 project_backup backup \
91 \
92 plugin_create plc \
93 plugins_commit plci \
94 plugins_install plin \
95 plugins_status plst \
96 plugins_update plup \
97 plugins_deinstall pldi \
98 \
99 pgsql_init \
100 pgsql_start \
101 pgsql_stop \
102 pgsql_psql psql \
103 pgsql_dump dump \
104 pgsql_dumpz dumpz \
105 \
106 apache_access_log alog \
107 apache_pager_access_log palog \
108 apache_error_log elog \
109 apache_pager_error_log pelog \
110 apache_start \
111 apache_stop \
112 \
113 check_conf_installed \
114 check_core_installed \
115 check_owner \
116 check_project \
117 check_project_installed \
118 check_user \
119
120 #################
121 # local_* targets
122 #################
123
124 # build all required ports (core & project)
125 build: local_build ;
126 local_build: check_user
127 @for P in ${CORE_REQUIRED} ${PROJECT_REQUIRED}; do \
128 ${MAKE} -s port_build PORT=$${P} \
129 || exit 1; \
130 done;
131 @echo $@ done
132
133 # install all required ports (core & project)
134 install: local_install ;
135 local_install: check_user
136 @for P in ${CORE_REQUIRED} ${PROJECT_REQUIRED}; do \
137 ${MAKE} -s port_install PORT=$${P} \
138 || exit 1; \
139 done;
140 ifeq (${DB_TYPE},SINGLE)
141 @${MAKE} -s pgsql_init
142 endif
143 @echo $@ done
144
145 # preview of install all required ports (core & project)
146 preview: local_preview ;
147 @for P in ${CORE_REQUIRED} ${PROJECT_REQUIRED}; do \
148 ${MAKE} -s port_install PORT=$${P} DRY_RUN=yes \
149 || exit 1; \
150 done;
151
152
153
154 ################
155 # core_* targets
156 ################
157
158 # check core sources via repository
159 cst: core_status ;
160 core_status: check_user
161 @svn st -u ${CORE_SRC}
162 @echo $@ done
163
164 # update core sources from repository
165 cup: core_update ;
166 core_update: check_user
167 ifdef REV
168 @svn up -r ${REV} ${CORE_SRC}
169 else
170 @svn up ${CORE_SRC}
171 endif
172 @echo $@ done
173
174 # commit core changes to repository
175 cci: core_commit ;
176 core_commit: check_user
177 @svn ci ${CORE_SRC}
178 @echo $@ done
179 #
180 # pretty formatted core info
181 cinfo: core_info ;
182 core_info:
183 @REPOS=`svn info ${CORE_SRC} | grep -E '^URL' | sed -E 's/URL: //'`; \
184 RL=$$(($${#REPOS}+2)); \
185 DEVEL=`perl -e 'print "".(lc "${DEVELOPMENT}" eq "yes" ? "YES" : "NO");'`; \
186 DEBUG=`perl -e 'print "".(lc "${DEBUG}" eq "yes" ? "YES" : "NO");'`; \
187 printf "%-$${RL}s %-12s %-7s %-7s %-6s\n" REPOSITORY REVISION DEVEL DEBUG PORT; \
188 printf "%-$${RL}s %-12s %-7s %-7s %-6s\n" $${REPOS} ${CORE_VERSION} $${DEVEL} \
189 $${DEBUG} ${HTTPD_PORT}
190 @echo $@ done
191
192
193 # install core into work directory
194 cin: core_install ;
195 ifeq (${DB_TYPE},SINGLE)
196 core_install: check_user pgsql_init
197 else
198 core_install: check_user
199 endif
200 @if [ -d ${CORE_USR} ]; then \
201 chmod -R u+w ${CORE_USR} \
202 && rm -Rf ${CORE_USR}; \
203 fi;
204
205 @mkdir ${CORE_USR} \
206 && cp -Rp ${CORE_SRC}/comps ${CORE_SRC}/lib ${CORE_SRC}/services ${CORE_USR}/ \
207 && find ${CORE_USR}/ -depth -type d -name .svn -exec rm -Rf {} \; \
208 && find ${CORE_USR}/ -depth -type f -name '*.proto' -exec rm -f {} \;
209
210 @for PROJ in `ls -1A ${PROJ_USR}/`; do \
211 ln -s ${PROJ_USR}/$${PROJ}/lib/$${PROJ} ${CORE_USR}/lib/$${PROJ}; \
212 done;
213
214 @chmod -R a-w ${CORE_USR}
215
216 ifeq (${DB_TYPE},SINGLE)
217 @rm -f ${LOCAL}/pgsql/data/pg_hba.conf \
218 && rm -f ${LOCAL}/pgsql/data/pg_ident.conf \
219 && cp ${CORE_SRC}/conf/pgsql/pg_hba.conf ${LOCAL}/pgsql/data/ \
220 && touch ${LOCAL}/pgsql/data/pg_ident.conf
221
222 @${call rewrite,${CORE_SRC}/conf/pgsql/postgresql.conf.proto, \
223 ${LOCAL}/pgsql/data/postgresql.conf}
224 endif
225
226 @echo $@ done
227
228
229 ###################
230 # project_* targets
231 ###################
232
233 # check project sources via repository
234 pst: project_status ;
235 project_status:: check_project
236 @svn st -u ${PROJ_SRC}/${PROJECT}
237 @echo $@ done
238
239 # pretty formatted project info
240 pinfo: project_info ;
241 project_info:: check_project
242 @REPOS=`svn info ${PROJ_SRC}/${PROJECT} | grep -E '^URL' | sed -E 's/URL: //'`; \
243 PL=$$(($${#PROJECT}+2)); [ $${PL} -lt 9 ] && PL=9; RL=$$(($${#REPOS}+2)); \
244 printf "%-$${PL}s %-$${RL}s %-10s %s\n" PROJECT REPOSITORY REVISION PLUGINS; \
245 printf "%-$${PL}s %-$${RL}s %-10s ${PLUGINS}\n" ${PROJECT} $${REPOS} ${PROJECT_VERSION}
246 @echo $@ done
247
248 # update project sources from repository
249 pup: project_update ;
250 project_update:: check_project
251 ifdef REV
252 @svn up -r ${REV} ${PROJ_SRC}/${PROJECT}
253 else
254 @svn up ${PROJ_SRC}/${PROJECT}
255 endif
256 @echo $@ done
257
258 # commit project changes to repository
259 pci: project_commit ;
260 project_commit:: check_project
261 @svn ci ${PROJ_SRC}/${PROJECT}
262 @echo $@ done
263
264 # install project into work directory
265 pin: project_install ;
266 project_install:: check_core_installed check_project
267 @for PORT in ${PROJECT_REQUIRED}; do \
268 ${MAKE} -s port_install PORT=$${PORT} \
269 || exit 1; \
270 done;
271
272 @if [ -d ${PROJ_USR}/${PROJECT} ]; then \
273 chmod -R u+w ${PROJ_USR}/${PROJECT}; \
274 fi;
275
276 @if [ -n "${RSYNC_COMMAND}" ]; then \
277 ${RSYNC_COMMAND} -a --delete --delete-excluded --include='tags' --include '*.exe' --cvs-exclude --exclude '*.proto' ${PROJ_SRC}/${PROJECT}/* ${PROJ_USR}/${PROJECT}; \
278 else \
279 if [ -d ${PROJ_USR}/${PROJECT} ]; then \
280 rm -Rf ${PROJ_USR}/${PROJECT}; \
281 fi; \
282 cp -R ${PROJ_SRC}/${PROJECT} ${PROJ_USR}/${PROJECT} \
283 && find ${PROJ_USR}/${PROJECT}/ -depth -type d -name .svn -exec rm -Rf {} \; \
284 && find ${PROJ_USR}/${PROJECT}/ -depth -type f -name '*.proto' -exec rm -f {} \; ; \
285 fi
286
287 @if [ \! -e ${PROJ_USR}/${PROJECT}/lib/Contenido ]; then \
288 mkdir ${PROJ_USR}/${PROJECT}/lib/Contenido; \
289 fi;
290
291 @test -d ${PROJ_USR}/${PROJECT}/conf \
292 && rm -Rf ${PROJ_USR}/${PROJECT}/conf \
293 || true
294
295 @if [ \! -e ${CORE_USR}/lib/${PROJECT} ]; then \
296 chmod u+w ${CORE_USR}/lib \
297 && ln -s ${PROJ_USR}/${PROJECT}/lib/${PROJECT} \
298 ${CORE_USR}/lib/${PROJECT} \
299 && chmod u-w ${CORE_USR}/lib; \
300 fi;
301
302 @chmod -R a-w ${PROJ_USR}/${PROJECT}
303
304 @for D in ${PROJ_TMP}/${PROJECT} \
305 ${PROJ_VAR}/${PROJECT}/log \
306 ${PROJ_VAR}/${PROJECT}/mason \
307 ${PROJ_VAR}/${PROJECT}/run; do \
308 test -d $${D} || mkdir -p $${D}; \
309 done;
310
311 @echo $@ done
312
313 # deinstall project from work directory
314 pdi: project_deinstall ;
315 project_deinstall:: check_project_installed project_stop
316 @if [ -d ${PROJ_USR}/${PROJECT} ]; then \
317 chmod -R u+w ${PROJ_USR}/${PROJECT} \
318 && rm -Rf ${PROJ_USR}/${PROJECT}; \
319 fi;
320 @if [ -d ${PROJ_TMP}/${PROJECT} ]; then \
321 rm -Rf ${PROJ_TMP}/${PROJECT}; \
322 fi
323 @if [ -d ${PROJ_VAR}/${PROJECT} ]; then \
324 rm -Rf ${PROJ_VAR}/${PROJECT}; \
325 fi
326 @echo $@ done
327
328 # commit plugins changes
329 plci: plugins_commit ;
330 plugins_commit:
331 ifdef PLUGIN
332 @${MAKE} -s plugin_commit_${PLUGIN}
333 else
334 @for P in ${PLUGINS}; do \
335 ${MAKE} -s plugin_commit_$${P}; \
336 done;
337 endif
338 @echo $@ done
339
340 # commit plugin changes
341 plugin_commit_%:
342 @svn ci ${PLUG_SRC}/${*}
343 @echo $@ done
344
345 # status of plugins sources via repository
346 plst: plugins_status ;
347 plugins_status:
348 ifdef PLUGIN
349 @${MAKE} -s plugin_status_${PLUGIN}
350 else
351 @for P in ${PLUGINS}; do \
352 ${MAKE} -s plugin_status_$${P}; \
353 done;
354 endif
355 @echo $@ done
356
357 # status of plugin sources from repository
358 plugin_status_%:
359 @svn st -u ${PLUG_SRC}/${*}
360 @echo $@ done
361
362 # update plugins sources from repository
363 plup: plugins_update ;
364 plugins_update:
365 ifdef PLUGIN
366 @${MAKE} -s plugin_update_${PLUGIN}
367 else
368 @for P in ${PLUGINS}; do \
369 ${MAKE} -s plugin_update_$${P}; \
370 done;
371 endif
372 @echo $@ done
373
374 # update plugin sources from repository
375 plugin_update_%:
376 @svn up ${PLUG_SRC}/${*}
377 @echo $@ done
378
379 # install plugins into work directory
380 plin: plugins_install ;
381 plugins_install: check_project_installed
382 #XXX It's workaround only (for old instalaltions - without usr/plugins)
383 @test -d ${PLUG_USR} || mkdir ${PLUG_USR}
384 @for P in ${PLUGINS}; do \
385 ${MAKE} -s plugin_install_$${P}; \
386 done;
387 @echo $@ done
388
389 # install plugin
390 plugin_install_%:
391 @if [ -d ${PLUG_USR}/${*} ]; then \
392 chmod -R u+w ${PLUG_USR}/${*}; \
393 fi;
394 @if [ -n "${RSYNC_COMMAND}" ]; then \
395 ${RSYNC_COMMAND} -a --delete --delete-excluded \
396 --cvs-exclude --exclude '*.proto' \
397 ${PLUG_SRC}/${*}/ ${PLUG_USR}/${*}/; \
398 else \
399 if [ -d ${PLUG_USR}/${*} ]; then \
400 rm -Rf ${PLUG_USR}/${*}; \
401 fi; \
402 cp -R ${PLUG_SRC}/${*} ${PLUG_USR}/${*} \
403 && find ${PLUG_USR}/${*}/ -depth -type d -name .svn \
404 -exec rm -Rf {} \; \
405 && find ${PLUG_USR}/${*}/ -depth -type f -name '*.proto' \
406 -exec rm -f {} \; ; \
407 fi;
408 @chmod -R a-w ${PLUG_USR}/${*}
409 @echo $@ done
410
411 # deinstall plugins from work directory
412 pldi: plugins_deinstall ;
413 plugins_deinstall:
414 @for P in ${PLUGINS}; do \
415 ${MAKE} -s plugin_deinstall_$${P}; \
416 done;
417 @echo $@ done
418
419 # deinstall plugin
420 plugin_deinstall_%:
421 @if [ -d ${PLUG_USR}/${*} ]; then \
422 chmod -R u+w ${PLUG_USR}/${*} \
423 && rm -Rf ${PLUG_USR}/${*}; \
424 fi;
425 @echo $@ done
426
427 # create new plugin
428 plc: plugin_create ;
429 plugin_create: check_user
430 @if [ -z "${NAME}" ]; then \
431 echo "ERROR: NAME not defined"; \
432 echo "HINT: use 'make cmd NAME=xxx'"; \
433 exit 1; \
434 fi;
435 @if [ -e ${PLUG_SRC}/${NAME} ]; then \
436 echo "ERROR: plugin ${NAME} already exists in src/plugins"; \
437 echo "HINT: select other name for new plugin"; \
438 exit 1; \
439 fi;
440 @if [ -e ${PLUG_USR}/${NAME} ]; then \
441 echo "ERROR: plugin ${NAME} already exists in usr/plugins"; \
442 echo "HINT: select other name for new plugin"; \
443 exit 1; \
444 fi;
445
446 @mkdir -p ${PLUG_SRC} \
447 && cp -Rp ${CORE_SRC}/skel/plugin ${PLUG_SRC}/${NAME} \
448 && find ${PLUG_SRC}/${NAME}/ -depth -type d -name .svn -exec rm -Rf {} \; \
449 && find ${PLUG_SRC}/${NAME}/ -depth -type f -name '*.proto' -and \
450 \! -path '*/conf/*' -exec rm -f {} \;
451
452 @${call rewrite_skel,${CORE_SRC}/skel/plugin/lib/plugin/Apache.pm.proto, \
453 ${PLUG_SRC}/${NAME}/lib/plugin/Apache.pm}
454 @${call rewrite_skel,${CORE_SRC}/skel/plugin/lib/plugin/Init.pm.proto, \
455 ${PLUG_SRC}/${NAME}/lib/plugin/Init.pm}
456 @${call rewrite_skel,${CORE_SRC}/skel/plugin/lib/plugin/Keeper.pm.proto, \
457 ${PLUG_SRC}/${NAME}/lib/plugin/Keeper.pm}
458 @${call rewrite_skel,${CORE_SRC}/skel/plugin/lib/plugin/State.pm.proto, \
459 ${PLUG_SRC}/${NAME}/lib/plugin/State.pm.proto}
460 @${call rewrite_skel,${CORE_SRC}/skel/plugin/comps/contenido/plugin/dhandler, \
461 ${PLUG_SRC}/${NAME}/comps/contenido/plugin/dhandler}
462 @${call rewrite_skel,${CORE_SRC}/skel/plugin/comps/contenido/plugin/index.html, \
463 ${PLUG_SRC}/${NAME}/comps/contenido/plugin/index.html}
464
465 @mv ${PLUG_SRC}/${NAME}/lib/plugin ${PLUG_SRC}/${NAME}/lib/${NAME}
466 @mv ${PLUG_SRC}/${NAME}/comps/contenido/plugin ${PLUG_SRC}/${NAME}/comps/contenido/${NAME}
467
468 @echo $@ done
469
470
471 # install configs into work directory
472 conf: project_conf ;
473 project_conf:: check_plugins_installed
474 @chmod -R u+w ${PROJ_USR}/${PROJECT}
475
476 @if [ -d ${PROJ_USR}/${PROJECT}/conf ]; then \
477 rm -Rf ${PROJ_USR}/${PROJECT}/conf; \
478 fi
479 @mkdir -p ${PROJ_USR}/${PROJECT}/conf/apache \
480 && mkdir -p ${PROJ_USR}/${PROJECT}/conf/etc \
481 && mkdir -p ${PROJ_USR}/${PROJECT}/conf/mason \
482 && mkdir -p ${PROJ_USR}/${PROJECT}/conf/mod_perl
483
484 @cp ${CORE_SRC}/conf/apache/mime.conf \
485 ${CORE_SRC}/conf/apache/mime.types \
486 ${PROJ_USR}/${PROJECT}/conf/apache/
487
488 @${call rewrite,${CORE_SRC}/conf/apache/httpd.conf.proto, \
489 ${PROJ_USR}/${PROJECT}/conf/apache/httpd.conf}
490 @${call rewrite,${PROJ_SRC}/${PROJECT}/conf/apache/httpd.conf.proto, \
491 ${PROJ_USR}/${PROJECT}/conf/apache/httpd_project.conf}
492
493 ifeq (${CRON_ENABLE},YES)
494 @if [ -d ${PROJ_SRC}/${PROJECT}/conf/etc ]; then \
495 cd ${PROJ_SRC}/${PROJECT}/conf/etc && \
496 for CTPROTO in crontab.`hostname`.proto crontab.proto; do \
497 if [ -f $$CTPROTO ]; then \
498 ${call rewrite,$$CTPROTO, \
499 ${PROJ_USR}/${PROJECT}/conf/etc/crontab}; \
500 break; \
501 fi; \
502 done; \
503 fi
504 endif
505
506 @${call rewrite,${CORE_SRC}/conf/mason/handler.pl.proto, \
507 ${PROJ_USR}/${PROJECT}/conf/mason/handler.pl}
508 @${call rewrite,${PROJ_SRC}/${PROJECT}/conf/mason/handler.pl.proto, \
509 ${PROJ_USR}/${PROJECT}/conf/mason/handler_project.pl}
510
511 @${call rewrite,${CORE_SRC}/conf/mod_perl/startup.pl.proto, \
512 ${PROJ_USR}/${PROJECT}/conf/mod_perl/startup.pl}
513 @${call rewrite,${PROJ_SRC}/${PROJECT}/conf/mod_perl/startup.pl.proto, \
514 ${PROJ_USR}/${PROJECT}/conf/mod_perl/startup_project.pl}
515
516 @${call rewrite,${CORE_SRC}/conf/mason/Config.pm.proto, \
517 ${PROJ_USR}/${PROJECT}/conf/mason/Config.pm}
518 @${call rewrite,${CORE_SRC}/lib/Contenido/State.pm.proto, \
519 ${PROJ_USR}/${PROJECT}/lib/Contenido/State.pm}
520 @${call rewrite,${CORE_SRC}/lib/Modules.pm.proto, \
521 ${PROJ_USR}/${PROJECT}/lib/Modules.pm}
522
523 @${call rewrite,${PROJ_SRC}/${PROJECT}/lib/${PROJECT}/State.pm.proto, \
524 ${PROJ_USR}/${PROJECT}/lib/${PROJECT}/State.pm}
525
526 @chmod -R u+w ${CORE_USR}/lib ${CORE_USR}/services
527
528 @${call rewrite,${CORE_SRC}/services/inc.pl.proto, \
529 ${CORE_USR}/services/inc.pl}
530
531 @chmod -R a-w ${CORE_USR}/lib ${CORE_USR}/services
532
533 @for P in ${PLUGINS}; do \
534 chmod -R u+w ${PLUG_USR}/$${P}; \
535 ${call rewrite,${PLUG_SRC}/$${P}/lib/$${P}/State.pm.proto, \
536 ${PLUG_USR}/$${P}/lib/$${P}/State.pm}; \
537 chmod -R u-w ${PLUG_USR}/$${P}; \
538 done;
539
540 @if [ $$((`perl -e 'print "".(lc "${DEVELOPMENT}" eq "yes" ? 1 : 0);'`)) -ne 1 ]; then \
541 ${CORE_USR}/services/pregen \
542 ${PROJ_SRC} ${PROJ_USR} ${PROJECT} '${PREGEN_GLOB}' ${PREGEN_LIST}; \
543 fi
544
545 @chmod -R a-w ${PROJ_USR}/${PROJECT}
546
547
548 ifeq (${DISABLE},YES)
549 @crontab -l | sed 's/^#*/#/' | crontab -; \
550 echo "Disabled crontab"
551 else
552 @if [ -f ${PROJ_USR}/${PROJECT}/conf/etc/crontab ]; then \
553 crontab ${PROJ_USR}/${PROJECT}/conf/etc/crontab; \
554 echo "Installed crontab from: ${PROJ_USR}/${PROJECT}/conf/etc/crontab"; \
555 fi
556 endif
557
558 @echo $@ done
559
560 # rsync project static files directly to frontend
561 prs: project_rsync ;
562 project_rsync:: check_project
563 @for D in ${RSYNC_DIRS}; do \
564 if [ -d ${RSYNC_ROOT}/$${D} ]; then \
565 D=$${D}/; \
566 elif [ \! -f ${RSYNC_ROOT}/$${D} ]; then \
567 echo "ERROR: no such dir or file: ${RSYNC_ROOT}/$${D}"; \
568 exit 1; \
569 fi; \
570 for S in ${RSYNC_SERVERS}; do \
571 echo "#######################################"; \
572 echo "# rsync $${D} to $${S}"; \
573 echo "#######################################"; \
574 cd ${RSYNC_ROOT} && ${RSYNC} -rtRv \
575 --delete --delete-excluded --exclude .svn --chmod=u+w \
576 $${D} $${S}; \
577 echo -e "done\n"; \
578 done; \
579 done;
580 @echo $@ done
581
582 614 ahitrov # rsync core static files directly to frontend
583 crs: core_rsync ;
584 core_rsync:: check_core_installed
585 @for D in ${RSYNC_CORE_DIRS}; do \
586 if [ -d ${RSYNC_CORE_ROOT}/$${D} ]; then \
587 D=$${D}/; \
588 elif [ \! -f ${RSYNC_CORE_ROOT}/$${D} ]; then \
589 echo "ERROR: no such dir or file: ${RSYNC_CORE_ROOT}/$${D}"; \
590 exit 1; \
591 fi; \
592 for S in ${RSYNC_SERVERS}; do \
593 echo "#######################################"; \
594 echo "# rsync $${D} to $${S}"; \
595 echo "#######################################"; \
596 cd ${RSYNC_CORE_ROOT} && ${RSYNC} -rtRv \
597 --delete --delete-excluded --exclude .svn --chmod=u+w \
598 $${D} $${S}; \
599 echo -e "done\n"; \
600 done; \
601 done;
602 @echo $@ done
603
604 assets: project_assets ;
605 project_assets:: check_project
606 @rm -rf ${ASSETS_ROOT}/assets;
607 @cd ${PROJ_SRC}/${PROJECT} && echo ${PROJ_SRC}/${PROJECT} && \
608 npm install;
609 @cd ${PROJ_SRC}/${PROJECT} && npm run build;
610 @if [ -d ${ASSETS_ROOT}/assets ]; then \
611 echo "Assets generated in ${ASSETS_ROOT}/assets"; \
612 fi;
613 @echo $@ done
614
615 assdev: project_assets_dev ;
616 project_assets_dev:: check_project
617 @rm -rf ${ASSETS_ROOT}/assets;
618 @cd ${PROJ_SRC}/${PROJECT} && echo ${PROJ_SRC}/${PROJECT} && \
619 npm install;
620 @cd ${PROJ_SRC}/${PROJECT} && npm run dev;
621
622 # rsync project assets directly to frontend
623 ars: project_assets_rsync ;
624 project_assets_rsync:: check_project
625 @if [ -d ${ASSETS_ROOT}/assets ]; then \
626 echo "Found assets in ${ASSETS_ROOT}/assets"; \
627 for S in ${RSYNC_SERVERS}; do \
628 echo "#######################################################"; \
629 echo "# rsync ${ASSETS_ROOT}/assets to $${S}"; \
630 echo "#######################################################"; \
631 cd ${ASSETS_ROOT} && ${RSYNC} -rtRv \
632 --delete --delete-excluded --exclude .svn --chmod=u+w \
633 assets $${S}; \
634 echo -e "done\n"; \
635 done; \
636 elif [ \! -f ${ASSETS_ROOT} ]; then \
637 echo "ERROR: no such dir or file: ${ASSETS_ROOT}"; \
638 exit 1; \
639 fi;
640 @echo $@ done
641
642 8 ahitrov@rambler.ru # start project
643 start: project_start ;
644 ifneq (${DISABLE},YES)
645 ifeq (${DB_TYPE},SINGLE)
646 project_start:: pgsql_start apache_start
647 @echo $@ done
648 else
649 project_start:: apache_start
650 @echo $@ done
651 endif
652 else
653 project_start::
654 @for M in `cd ${PROJ_VAR}/${PROJECT} && ls -d mason.* 2>/dev/null`; do \
655 echo "cleaning old mason files: $$M"; \
656 rm -Rf ${PROJ_VAR}/${PROJECT}/$$M; \
657 done;
658 @echo $@ disabled
659 endif
660
661 # stop project
662 stop: project_stop ;
663 project_stop:: apache_stop
664 @echo $@ done
665
666 # full reinstall & restart core & project
667 full: project_fullreload ;
668 project_fullreload:: project_stop mason_clean core_update core_install \
669 project_update project_install plugins_update plugins_install \
670 project_conf project_start
671 @echo $@ done
672
673 # full reinstall & restart project
674 reload: project_reload ;
675 project_reload:: project_stop mason_clean project_update project_install \
676 plugins_update plugins_install project_conf project_start
677 @echo $@ done
678
679 # restart project without svn update
680 nano: project_rewind ;
681 rewind: project_rewind ;
682 project_rewind:: project_stop mason_clean project_install plugins_install \
683 project_conf project_start
684 @echo $@ done
685
686 # clean all mason temporaries & restart project
687 refresh: project_refresh ;
688 project_refresh:: project_stop mason_clean project_start
689 @echo $@ done
690
691 # create new project
692 create: project_create ;
693 project_create: check_user
694 @if [ -z "${NAME}" ]; then \
695 echo "ERROR: NAME not defined"; \
696 echo "HINT: use 'make cmd NAME=xxx'"; \
697 exit 1; \
698 fi;
699 @if [ -e ${PROJ_SRC}/${NAME} ]; then \
700 echo "ERROR: project ${NAME} already exists in src/projects"; \
701 echo "HINT: select other name for new project"; \
702 exit 1; \
703 fi;
704 @if [ -e ${PROJ_USR}/${NAME} ]; then \
705 echo "ERROR: project ${NAME} already exists in usr/projects"; \
706 echo "HINT: select other name for new project"; \
707 exit 1; \
708 fi;
709
710 @cp -Rp ${CORE_SRC}/skel/project ${PROJ_SRC}/${NAME} \
711 && find ${PROJ_SRC}/${NAME}/ -depth -type d -name .svn -exec rm -Rf {} \; \
712 && find ${PROJ_SRC}/${NAME}/ -depth -type f -name '*.proto' -and \
713 \! -path '*/conf/*' -exec rm -f {} \;
714
715 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/Apache.pm.proto, \
716 ${PROJ_SRC}/${NAME}/lib/project/Apache.pm}
717 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/Init.pm.proto, \
718 ${PROJ_SRC}/${NAME}/lib/project/Init.pm}
719 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/Keeper.pm.proto, \
720 ${PROJ_SRC}/${NAME}/lib/project/Keeper.pm}
721 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/SampleCustomDocument.pm.proto, \
722 ${PROJ_SRC}/${NAME}/lib/project/SampleCustomDocument.pm}
723 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/SampleDefaultDocument.pm.proto, \
724 ${PROJ_SRC}/${NAME}/lib/project/SampleDefaultDocument.pm}
725 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/State.pm.proto, \
726 ${PROJ_SRC}/${NAME}/lib/project/State.pm.proto}
727 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/SQL/SampleTable.pm.proto, \
728 ${PROJ_SRC}/${NAME}/lib/project/SQL/SampleTable.pm}
729 @${call rewrite_skel,${CORE_SRC}/skel/project/lib/project/SQL/SampleTable.pm.proto, \
730 ${PROJ_SRC}/${NAME}/lib/project/SQL/SampleTable.pm}
731 @${call rewrite_skel,${CORE_SRC}/skel/project/comps/www/index.html.proto, \
732 ${PROJ_SRC}/${NAME}/comps/www/index.html}
733 @${call rewrite_skel,${CORE_SRC}/skel/project/conf/etc/crontab.tmpl.proto, \
734 ${PROJ_SRC}/${NAME}/conf/etc/crontab.tmpl.proto}
735 @${call rewrite_skel,${CORE_SRC}/skel/project/config.mk.proto, \
736 ${PROJ_SRC}/${NAME}/config.mk}
737
738 @mv ${PROJ_SRC}/${NAME}/lib/project ${PROJ_SRC}/${NAME}/lib/${NAME}
739
740 @echo $@ done
741
742
743 # change active project
744 swi: project_switch ;
745 switch: project_switch ;
746 project_switch:
747 @if [ -z "${NAME}" ]; then \
748 echo "ERROR: NAME not defined"; \
749 echo "HINT: use 'make cmd NAME=xxx'"; \
750 exit 1; \
751 fi;
752 @if [ "${NAME}" = "${PROJECT}" ]; then \
753 echo "ERROR: project ${NAME} is already active"; \
754 exit 1; \
755 fi;
756 @if [ \! -d ${PROJ_SRC}/${NAME} ]; then \
757 echo "ERROR: project ${NAME} doesn't exists in src/projects"; \
758 echo "HINT: checkout sources for project ${NAME}"; \
759 exit 1; \
760 fi;
761 @${MAKE} -s project_stop
762 @perl -pi.orig -e 's|^([[:space:]]*PROJECT[[:space:]]*\?*\=[[:space:]]*)[^[:space:]]+([[:space:]]*)$$|$$1${NAME}$$2|' ${ROOT_DIR}/config.mk
763 @${MAKE} -s project_reload PROJECT=${NAME}
764
765 @echo $@ done
766
767 # backing-up project sources
768 backup: project_backup ;
769 project_backup:: check_project
770 @echo "compressing ${PROJECT} sources => ${PROJ_VAR}/${PROJECT}/${PROJECT}.src.tgz"
771 @tar -czf ${PROJ_VAR}/${PROJECT}/${PROJECT}.src.tgz -C ${PROJ_SRC} ${PROJECT}
772 @echo $@ done
773
774 # import project sources into repository
775 import: project_import ;
776 project_import: check_project
777 @if [ $$((`find ${PROJ_SRC}/${PROJECT} -type d -name .svn | wc -l`)) -ne 0 ]; then \
778 echo "ERROR: project '${PROJECT}' seems as already imported"; \
779 exit 1; \
780 fi
781 @if ! svn ls ${SVN_REPOSITORY}/${PROJECT}/trunk >&- 2>&-; then \
782 echo "ERROR: no repository for project '${PROJECT}' found"; \
783 echo "HINT: contact with respository administrators."; \
784 exit 1; \
785 fi
786 @if [ $$((`svn ls ${SVN_REPOSITORY}/${PROJECT}/trunk | wc -l`)) -ne 0 ]; then \
787 echo "ERROR: repository for project '${PROJECT}' isn't empty"; \
788 echo "Please contact with respository administrators."; \
789 exit 1; \
790 fi
791 @if svn import ${PROJ_SRC}/${PROJECT} ${SVN_REPOSITORY}/${PROJECT}/trunk \
792 && mv ${PROJ_SRC}/${PROJECT} ${PROJ_SRC}/${PROJECT}.before-import \
793 && svn checkout ${SVN_REPOSITORY}/${PROJECT}/trunk ${PROJ_SRC}/${PROJECT}; then \
794 echo "Your project directory moved to '${PROJ_SRC}/${PROJECT}.before-import'"; \
795 echo "Directory '${PROJ_SRC}/${PROJECT}' is now working copy"; \
796 else \
797 echo "ERROR: some errors occured during import/checkout project '${PROJECT}'"; \
798 echo "HINT: contact with respository administrators."; \
799 exit 1; \
800 fi
801 @echo $@ done
802
803 # create user (editors)
804 user: project_user ;
805 project_user: check_core_installed pgsql_template
806 @export PGPASSWORD=${BASE_PASSWD} && ${CORE_USR}/services/createuser | \
807 ${PSQL} -h '${BASE_HOST}' -p ${PGSQL_PORT} -U ${BASE_USER} ${PGSQL_BASE}
808 @echo $@ done
809
810 ##################
811 # apache_* targets
812 ##################
813
814 286 ahitrov # _exp=`perl -e 'print $1 if "${LIMIT_VMEMORY_HTTPD}" =~ /.*(.)$/;'`;
815 # _exp=`perl -e 'my $$e = ("${LIMIT_VMEMORY_HTTPD}"=~/.*(.)/)[0]; print $$e;'`; \
816 # echo _exp=$${_exp}; \
817
818 8 ahitrov@rambler.ru apache_start: check_conf_installed
819 @${call is_alive,${PROJ_VAR}/${PROJECT}/run/httpd.pid}; \
820 FLAGS=`perl -e 'print " -DDEVELOPMENT" if lc "${DEVELOPMENT}" eq "yes";'`; \
821 FLAGS=$$FLAGS`perl -e ' \
822 if (lc "${RSYSLOG_ENABLE}" eq "yes") { print " -DRSYSLOG"; } \
823 elsif (lc "${CRONOLOG_ENABLE}" eq "yes") { print " -DCRONOLOG"; } \
824 else { print " -DFILELOG"; }'`; \
825 if [ "${LIMIT_VMEMORY_HTTPD}" ]; then \
826 286 ahitrov if [ x`uname` = x"FreeBSD" ]; then \
827 LIMITS="${LIMIT_CMD} -v ${LIMIT_VMEMORY_HTTPD}"; \
828 else \
829 # echo "LIMIT_VMEMORY_HTTPD=${LIMIT_VMEMORY_HTTPD}"; \
830 _exp=`expr "${LIMIT_VMEMORY_HTTPD}" : '.*\(.\)'`; \
831 # echo _exp=$${_exp}; \
832 _value=`expr "${LIMIT_VMEMORY_HTTPD}" : '\(.*\).'`; \
833 # echo _value=$${_value}; \
834 if [ "$${_exp}" = "m" ]; then \
835 _value=`expr $$_value \* 1024 `; \
836 fi; \
837 # echo _value=$${_value}; \
838 LIMITS="ulimit -S -v $${_value}"; \
839 echo "DEBUG: running on Linux, LIMITS='$${LIMITS}'"; \
840 fi; \
841 8 ahitrov@rambler.ru fi; \
842 if [ "$${ALIVE}" = "YES" ]; then \
843 echo "WARNING: apache for project '${PROJECT}' already running"; \
844 else \
845 286 ahitrov [ x`uname` = x"Linux" ] && $${LIMITS} && LIMITS=""; \
846 8 ahitrov@rambler.ru if $${LIMITS} ${LOCAL}/apache/bin/httpd $${FLAGS} \
847 -d ${PROJ_USR}/${PROJECT}/ \
848 -f ${PROJ_USR}/${PROJECT}/conf/apache/httpd.conf; then \
849 echo -n "apache for project '${PROJECT}' started"; \
850 if [ "${LIMIT_VMEMORY_HTTPD}" ]; then \
851 echo " (with vmem limit: ${LIMIT_VMEMORY_HTTPD})"; \
852 else \
853 echo; \
854 fi; \
855 else \
856 echo "ERROR: can't start apache for project '${PROJECT}'"; \
857 exit 1; \
858 fi; \
859 fi;
860 @for M in `cd ${PROJ_VAR}/${PROJECT} && ls -d mason.*`; do \
861 echo "cleaning old mason files: $$M"; \
862 rm -Rf ${PROJ_VAR}/${PROJECT}/$$M; \
863 done;
864 @echo $@ done
865
866 apache_stop: check_conf_installed
867 @${call is_alive,${PROJ_VAR}/${PROJECT}/run/httpd.pid}; \
868 if [ "$${ALIVE}" = "YES" ]; then \
869 kill `head -n 1 ${PROJ_VAR}/${PROJECT}/run/httpd.pid`; \
870 ${call wait_stop,${PROJ_VAR}/${PROJECT}/run/httpd.pid,apache}; \
871 if [ $${STOPPED} != 'YES' ]; then \
872 echo "ERROR: can't stop apache for project '${PROJECT}'"; \
873 exit 1; \
874 else \
875 echo "apache for project '${PROJECT}' stopped"; \
876 fi; \
877 else \
878 echo "WARNING: apache for project '${PROJECT}' isn't running"; \
879 fi;
880 @echo $@ done
881
882 alog: apache_access_log ;
883 apache_access_log:
884 @test -e ${PROJECT_LOG}/access_log || touch ${PROJECT_LOG}/access_log
885 @tail -F ${PROJECT_LOG}/access_log
886
887 palog: apache_pager_access_log ;
888 apache_pager_access_log:
889 @test -e ${PROJECT_LOG}/access_log || touch ${PROJECT_LOG}/access_log
890 @${PAGER} ${PROJECT_LOG}/access_log
891
892 elog: apache_error_log ;
893 apache_error_log:
894 @test -e ${PROJECT_LOG}/error_log || touch ${PROJECT_LOG}/error_log
895 @tail -F ${PROJECT_LOG}/error_log
896
897 pelog: apache_pager_error_log ;
898 apache_pager_error_log:
899 @test -e ${PROJECT_LOG}/error_log || touch ${PROJECT_LOG}/error_log
900 @${PAGER} ${PROJECT_LOG}/error_log
901
902 #################
903 # pgsql_* targets
904 #################
905
906 ifeq (${DB_TYPE},SINGLE)
907
908 pgsql_init: check_user
909 @cd ${PORTSDIR}/all/postgresql \
910 && ${MAKE} -s initdb PREFIX=${LOCAL} PORTSWRK=${PORTSWRK}
911 @echo $@ done
912
913 pgsql_start: pgsql_init
914 @${call is_alive,${LOCAL}/pgsql/data/postmaster.pid}; \
915 if [ "$${ALIVE}" = "YES" ]; then \
916 echo "WARNING: postgresql already running"; \
917 else \
918 if ${LOCAL}/pgsql/bin/pg_ctl -w -D ${LOCAL}/pgsql/data start; then \
919 echo "postgresql started"; \
920 else \
921 echo "ERROR: can't start postgresql"; \
922 exit 1; \
923 fi; \
924 fi;
925 @echo $@ done
926
927 pgsql_stop: check_user
928 @${call is_alive,${LOCAL}/pgsql/data/postmaster.pid}; \
929 if [ "$${ALIVE}" = "YES" ]; then \
930 ${LOCAL}/pgsql/bin/pg_ctl -w -m fast -D ${LOCAL}/pgsql/data stop; \
931 ${call wait_stop,${LOCAL}/pgsql/data/postmaster.pid,postgresql}; \
932 if [ $${STOPPED} != 'YES' ]; then \
933 echo "ERROR: can't stop postgresql"; \
934 exit 1; \
935 else \
936 echo "postgresql stopped"; \
937 fi; \
938 else \
939 echo "WARNING: postgresql isn't running"; \
940 fi;
941 @echo $@ done
942
943 pgsql_create: pgsql_start
944 @if [ $$((`${PSQL} -p ${PGSQL_PORT} -l | \
945 perl -ne 'print $$_ if /^\s*${PGSQL_BASE}/' | wc -l`)) -eq 0 ]; then \
946 ${LOCAL}/pgsql/bin/createuser -SdR -p ${PGSQL_PORT} ${BASE_USER} \
947 || true; \
948 ${LOCAL}/pgsql/bin/createdb -p ${PGSQL_PORT} -O ${BASE_USER} \
949 ${PGSQL_BASE}; \
950 echo "ALTER USER ${BASE_USER} PASSWORD '${BASE_PASSWD}';" | \
951 ${PSQL} -p ${PGSQL_PORT} ${PGSQL_BASE}; \
952 ${PSQL} -p ${PGSQL_PORT} ${PGSQL_BASE} < ${LOCAL}/pgsql/share/contrib/_int.sql; \
953 else \
954 echo "WARNING: database ${PGSQL_BASE} already exists"; \
955 fi;
956 @echo $@ done
957
958
959 else
960
961 pgsql_init \
962 pgsql_start \
963 pgsql_stop \
964 pgsql_create:
965 @echo "ERROR: $@ not implemented for DB_TYPE: ${DB_TYPE}"; \
966 echo "HINT: use 'make cmd DB_TYPE=xxx' or edit ${ROOT_DIR}/config.mk"; \
967 exit 1
968
969 endif
970
971 ifeq (${DB_TYPE},SINGLE)
972 pgsql_template: pgsql_create
973 else
974 pgsql_template: check_project
975 endif
976 @if [ $$((`export PGPASSWORD=${BASE_PASSWD} && ${PSQL} -h '${BASE_HOST}' \
977 -p ${PGSQL_PORT} -U ${BASE_USER} -c '\d' ${PGSQL_BASE} | \
978 grep documents | wc -l`)) -lt 1 ]; then \
979 export PGPASSWORD=${BASE_PASSWD} && ${PSQL} -h '${BASE_HOST}' \
980 -p ${PGSQL_PORT} -U ${BASE_USER} ${PGSQL_BASE} < \
981 ${CORE_SRC}/sql/${STORE_METHOD}/contenido.sql; \
982 else \
983 echo "WARNING: template already loaded into database ${PGSQL_BASE}"; \
984 fi;
985
986 @echo $@ done
987
988 psql: pgsql_psql ;
989 ifeq (${DB_TYPE},SINGLE)
990 pgsql_psql: pgsql_create
991 else
992 pgsql_psql: check_project
993 endif
994 @(export PGPASSWORD=${BASE_PASSWD} && cd ../.. && ${PSQL} -h '${BASE_HOST}' -p ${PGSQL_PORT} \
995 -U ${BASE_USER} ${PGSQL_BASE})
996
997 # dump project database
998 dump: pgsql_dump ;
999 ifeq (${DB_TYPE},NONE)
1000 pgsql_dump:
1001 @echo "project ${PROJECT} hasn't database"; exit 1
1002 else
1003 ifeq (${DB_TYPE},SINGLE)
1004 pgsql_dump: pgsql_create
1005 else
1006 pgsql_dump: check_project
1007 endif
1008 @echo "dumping ${BASE_HOST}:${PGSQL_PORT}/${PGSQL_BASE} => ${PROJ_VAR}/${PROJECT}/${PGSQL_BASE}.sql"
1009 @export PGPASSWORD=${BASE_PASSWD} && ${PGDUMP} -Ox -h '${BASE_HOST}' -p ${PGSQL_PORT} \
1010 -U ${BASE_USER} ${PGSQL_BASE} > ${PROJ_VAR}/${PROJECT}/${PGSQL_BASE}.sql
1011 @echo $@ done
1012 endif
1013
1014 # dump project database (gzip)
1015 dumpz: pgsql_dumpz ;
1016 ifeq (${DB_TYPE},NONE)
1017 pgsql_dumpz:
1018 @echo "project ${PROJECT} hasn't database"; exit 1
1019 else
1020 ifeq (${DB_TYPE},SINGLE)
1021 pgsql_dumpz: pgsql_create
1022 else
1023 pgsql_dumpz: check_project
1024 endif
1025 @echo "dumping ${BASE_HOST}:${PGSQL_PORT}/${PGSQL_BASE} => ${PROJ_VAR}/${PROJECT}/${PGSQL_BASE}.sql.gz"
1026 @export PGPASSWORD=${BASE_PASSWD} && ${PGDUMP} -Ox -h '${BASE_HOST}' -p ${PGSQL_PORT} \
1027 -U ${BASE_USER} ${PGSQL_BASE} | gzip > ${PROJ_VAR}/${PROJECT}/${PGSQL_BASE}.sql.gz
1028 @echo $@ done
1029 endif
1030
1031
1032 ########################
1033 # internal targets
1034 # (not for direct usage)
1035 ########################
1036
1037 mason_clean:
1038 @mv -f ${PROJ_VAR}/${PROJECT}/mason \
1039 ${PROJ_VAR}/${PROJECT}/mason.`date +%Y-%m-%d.%H:%M:%S` \
1040 && mkdir ${PROJ_VAR}/${PROJECT}/mason;
1041 @echo $@ done
1042
1043
1044 #################
1045 # check_* targets
1046 #################
1047
1048 # it's required
1049 check_user: check_owner ;
1050
1051 # if user is installation owner?
1052 check_owner:
1053 @if [ `whoami` != ${OWNER} ]; then \
1054 echo "ERROR: please run as OWNER: ${OWNER}"; \
1055 echo "HINT: use 'sudo -u ${OWNER} -H bash' or 'sudo -i -u ${OWNER}'"; \
1056 exit 1; \
1057 fi;
1058
1059 # check if core installed
1060 check_core_installed: check_user
1061 @if [ $$((`ls -1A ${CORE_USR}/ | wc -l`)) -eq 0 ]; then \
1062 echo "ERROR: core not installed"; \
1063 echo "HINT: use 'make core_install' or 'make cin'"; \
1064 exit 1; \
1065 fi;
1066
1067 # check for existing project (see include near line ~30)
1068 check_project: check_user
1069 @if [ -z "${PROJECT}" ]; then \
1070 echo "ERROR: project not defined"; \
1071 echo "HINT: use 'make cmd PROJECT=xxx' or edit ${ROOT_DIR}/config.mk"; \
1072 exit 1; \
1073 fi;
1074
1075 # check if project installed
1076 check_project_installed: check_project
1077 @if [ \! -d ${PROJ_USR}/${PROJECT} ]; then \
1078 echo "ERROR: project '${PROJECT}' not installed"; \
1079 echo "HINT: use 'make project_install' or 'make pin'"; \
1080 exit 1; \
1081 fi;
1082 @if [ $$((`ls -1A ${PROJ_USR}/${PROJECT} | wc -l`)) -eq 0 ]; then \
1083 echo "ERROR: project '${PROJECT}' not installed"; \
1084 echo "HINT: use 'make project_install' or 'make pin'"; \
1085 exit 1; \
1086 fi;
1087
1088 # check if plugins installed
1089 check_plugins_installed: check_project_installed
1090 @for P in ${PLUGINS}; do \
1091 if [ \! -d ${PLUG_USR}/$${P} ]; then \
1092 echo "ERROR: plugin '$${P}' not installed"; \
1093 echo "HINT: use 'make plugins_install' or 'make plin'"; \
1094 exit 1; \
1095 fi; \
1096 done;
1097
1098 # check if configs installed
1099 check_conf_installed: check_project_installed
1100 @if [ \! -d ${PROJ_USR}/${PROJECT}/conf ]; then \
1101 echo "ERROR: configs for project '${PROJECT}' not installed"; \
1102 echo "HINT: use 'make project_conf' or 'make conf'"; \
1103 exit 1; \
1104 fi;
1105
1106
1107 ##########################
1108 # port_* & ports_* targets
1109 ##########################
1110
1111 # single port sub-commands
1112 port_%: check_user
1113 ifdef PORT
1114 @cd ${PORTSDIR}/all/${PORT} \
1115 && ${MAKE} -s $* PREFIX=${LOCAL} PORTSWRK=${PORTSWRK}
1116 ifndef DRY_RUN
1117 @echo $@ done
1118 endif
1119 else
1120 @echo "ERROR: no PORT defined"; \
1121 echo "HINT: use 'make cmd PORT=name'"; \
1122 exit 1;
1123 endif
1124
1125 # multiple ports sub-commands
1126 ports_%: check_user
1127 @cd ${PORTSDIR} \
1128 && ${MAKE} -s $* PREFIX=${LOCAL} PORTSWRK=${PORTSWRK}
1129 @echo $@ done
1130
1131
1132 ########
1133 # macros
1134 ########
1135 define is_alive
1136 if [ \! -f ${1} ]; then \
1137 ALIVE='NO'; \
1138 else \
1139 if kill -0 `head -n 1 ${1}` 2>/dev/null; then \
1140 ALIVE='YES'; \
1141 else \
1142 rm -f ${1}; \
1143 ALIVE='NO'; \
1144 fi; \
1145 fi
1146 endef
1147
1148 define wait_stop
1149 TRYMAX=`test -z "${3}" && echo 10 || echo ${3}`; \
1150 TRYCUR=1; \
1151 STOPPED='NO'; \
1152 echo -n "Waiting for ${2} stopped, tries: $${TRYCUR}"; \
1153 ${call is_alive,${1}}; \
1154 while [ "$${ALIVE}" = "YES" -a $$(($${TRYCUR})) -lt $$(($${TRYMAX})) ]; do \
1155 sleep 1; \
1156 TRYCUR=$$(($${TRYCUR}+1)); \
1157 echo -n " $${TRYCUR}"; \
1158 ${call is_alive,${1}}; \
1159 done; \
1160 echo ""; \
1161 if [ "$${ALIVE}" = "NO" ]; then \
1162 STOPPED='YES'; \
1163 fi
1164 endef
1165
1166 ifeq (${USE_MTT},YES)
1167 define rewrite
1168 $(foreach R, ${REWRITE}, MTT_${R}="${${R}}") \
1169 ${CORE_SRC}/services/mttbfr > ${PROJ_TMP}/${PROJECT}/mtt.conf && \
1170 ${CORE_SRC}/services/mttcomp < ${1} | \
1171 ${LOCAL}/bin/mtt -b ${PROJ_TMP}/${PROJECT}/mtt.conf - ${2} \
1172 && echo "created ${2} (mtt)"
1173 endef
1174 else
1175 define rewrite
1176 $(foreach R, ${REWRITE}, ${R}="${${R}}") \
1177 perl -pe 's/@([A-Z_]+)@/$$ENV{$$1}/ge' < ${1} > ${2} \
1178 && echo "created ${2} (rewrite)"
1179 endef
1180 endif
1181
1182 define rewrite_skel
1183 NAME=${NAME} \
1184 LOCAL=@LOCAL@ \
1185 CORE_USR=@CORE_USR@ \
1186 PROJ_USR=@PROJ_USR@ \
1187 PROJECT_VAR=@PROJECT_VAR@ \
1188 perl -pe 's/@([A-Z_]+)@/$$ENV{$$1}/ge' < ${1} > ${2} \
1189 && echo "created ${2}"
1190 endef
1191
1192 # rewrites values
1193 PREFIX = ${LOCAL}
1194 ROOT_LOG = ${ROOT_DIR}/var/log
1195 PGSQL_REDIRECT = ${shell perl -e 'print lc("${PGSQL_LOGGING}") eq "yes" && "on" || "off"'}
1196 ifdef PROJECT
1197 PROJECT_USR = ${PROJ_USR}/${PROJECT}
1198 PROJECT_TMP = ${PROJ_TMP}/${PROJECT}
1199 PROJECT_VAR = ${PROJ_VAR}/${PROJECT}
1200 PROJECT_LOG = ${PROJ_VAR}/${PROJECT}/log
1201 PROJECT_RUN = ${PROJ_VAR}/${PROJECT}/run
1202 endif
1203
1204 # rewrites definitions
1205 REWRITE += \
1206 AUTH_COOKIE \
1207 AUTH_MEMCACHED_BUSY_LOCK \
1208 AUTH_MEMCACHED_ENABLE \
1209 AUTH_MEMCACHED_SERVERS \
1210 BASE_HOST \
1211 BASE_PASSWD \
1212 BASE_USER \
1213 BINARY \
1214 CASCADE \
1215 COMP_CACHE_ENABLED \
1216 COMP_TIMINGS_DISABLE \
1217 365 ahitrov COMPOSITE \
1218 8 ahitrov@rambler.ru CONF \
1219 CONTENIDO_VERSION \
1220 CONVERT \
1221 CORE_COMP \
1222 CORE_SRC \
1223 CORE_VERSION \
1224 CORE_USR \
1225 CRONOLOG_ENABLE \
1226 CRONOLOG_FORMAT \
1227 CROSSLINKS \
1228 DB_TYPE \
1229 DEBUG_FORMAT \
1230 DEBUG_MIN_LEVEL \
1231 DEBUG_MAX_LEVEL \
1232 DEBUG_STACK_TRACE \
1233 DEBUG \
1234 DEBUG_CORE \
1235 DEBUG_SQL \
1236 DEBUG_WORKTIME \
1237 DEFAULT_ESCAPE_FLAGS \
1238 DEFAULT_HANDLER \
1239 DEVELOPMENT \
1240 ERROR_MODE \
1241 FILES \
1242 203 ahitrov FILE_WEB_STORAGE \
1243 8 ahitrov@rambler.ru HOSTNAME \
1244 HTTPD_DOCS \
1245 HTTPD_ELOG_LEVEL \
1246 HTTPD_PORT \
1247 HTTPD_SERVER \
1248 IMAGES \
1249 LISTEN_BACK_LOG \
1250 LOCAL \
1251 LOCALE \
1252 LOGGER \
1253 MASON_CACHE_ENABLED \
1254 MASON_COMP \
1255 MASON_MEMCACHED_BACKEND \
1256 MASON_MEMCACHED_DEBUG \
1257 MASON_MEMCACHED_ENABLED \
1258 MASON_MEMCACHED_NAMESPACE \
1259 MASON_MEMCACHED_SERVERS \
1260 MASTER_BASE_HOST \
1261 MASTER_BASE_NAME \
1262 MASTER_BASE_PASSWD \
1263 MASTER_BASE_PORT \
1264 MASTER_BASE_USER \
1265 MAX_CLIENTS \
1266 MAX_PROCESS_SIZE \
1267 MAX_REQUESTS_PER_CHILD \
1268 MAX_SPARE_SERVERS \
1269 MEMCACHED_BACKEND \
1270 MEMCACHED_DELAYED \
1271 MEMCACHED_ENABLE \
1272 MEMCACHED_ENABLE_COMPRESS \
1273 MEMCACHED_SELECT_TIMEOUT \
1274 MEMCACHED_SERVERS \
1275 MEMCACHED_SET_MODE \
1276 MIN_SPARE_SERVERS \
1277 MODULES \
1278 MULTIDOMAIN \
1279 OPTIONS_EXPIRE \
1280 PERL_LEVEL \
1281 PERL_LIB \
1282 PERSISTENT_CONN \
1283 PGSQL_BASE \
1284 PGSQL_CLIENT_ENCODING \
1285 PGSQL_PORT \
1286 PGSQL_REAL_PREPARE \
1287 PGSQL_REDIRECT \
1288 PGSQL_CLIENT_ENCODING \
1289 PGSQL_ENCODE_DATA \
1290 PGSQL_DECODE_DATA \
1291 PGSQL_ENABLE_UTF \
1292 217 ahitrov SERIALIZE_WITH \
1293 8 ahitrov@rambler.ru PLUG_SRC \
1294 PLUGINS \
1295 PLUGIN_COMP \
1296 PREAMBLE_HANDLER \
1297 PREAMBLE_HANDLER_PATH \
1298 PREFIX \
1299 PRELOADS \
1300 PREVIEW \
1301 PROFILING_DBI \
1302 PROJECT \
1303 PROJECT_HOME \
1304 PROJECT_LC \
1305 PROJECT_NAME \
1306 PROJECT_LOG \
1307 PROJECT_RUN \
1308 PROJECT_TMP \
1309 PROJECT_USR \
1310 PROJECT_VAR \
1311 PROJECT_VERSION \
1312 PROJ_SRC \
1313 PROJ_USR \
1314 ROOT_LOG \
1315 READONLY \
1316 RSYSLOG_ENABLE \
1317 RSYSLOG_HOST \
1318 SERVER_ADMIN \
1319 SESSIONS \
1320 SPARE_REAPER_DELAY \
1321 SPARE_REAPER_DELAY_FAKEMOD \
1322 START_SERVERS \
1323 STATIC_SOURCE_ENABLE \
1324 STATIC_SOURCE_TOUCH_FILE \
1325 STORE_METHOD \
1326
1327 #TODO: ElTexto compatibility only
1328 REWRITE += \
1329 COMMENTS_ON_PAGE \
1330 ELTEXTO_VERSION \
1331 MEMCACHED_EXPIRE \
1332 SYNC_WITH_GROUPS \
1333 TEXTS_ON_PAGE \
1334 TEXT_IDS_IN_CACHE \
1335
1336 #TODO: Rate compatibility only
1337 REWRITE += \
1338 RATE_CLASSES \
1339 RATE_COOKIE \
1340
1341 #TODO: Search plugin compatibility only
1342 REWRITE += \
1343 SEARCH_SERVER \
1344
1345 #TODO: Util Proxy image
1346 REWRITE += \
1347 PROXY_IMAGE_LOCATION \
1348 PROXY_IMAGE_SECRET \
1349