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