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