fix voids of CF transactions, RT#16050
[freeside.git] / Makefile
1 #!/usr/bin/make
2
3 #solaris and perhaps other very weirdass /bin/sh
4 #SHELL="/bin/ksh"
5
6 DB_TYPE = Pg
7 #DB_TYPE = mysql
8
9 DB_USER = freeside
10 DB_PASSWORD=
11
12 DATASOURCE = DBI:${DB_TYPE}:dbname=freeside
13
14 #changable now (some things which should go to the others still go to CONF)
15 FREESIDE_CONF = /usr/local/etc/freeside
16 FREESIDE_LOG = /usr/local/etc/freeside
17 FREESIDE_LOCK = /usr/local/etc/freeside
18 FREESIDE_CACHE = /usr/local/etc/freeside
19 FREESIDE_EXPORT = /usr/local/etc/freeside
20
21 MASON_HANDLER = ${FREESIDE_CONF}/handler.pl
22 MASONDATA = ${FREESIDE_CACHE}/masondata
23
24 #where to put the default configuraiton used by freeside-setup to initialize
25 #a new database (not used after that).  primarily of interest to distro
26 #package maintainers
27 DIST_CONF = ${FREESIDE_CONF}/default_conf
28
29 #deb
30 FREESIDE_DOCUMENT_ROOT = /var/www/freeside
31 #redhat, fedora, mandrake
32 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
33 #freebsd
34 #FREESIDE_DOCUMENT_ROOT = /usr/local/www/data/freeside
35 #openbsd
36 #FREESIDE_DOCUMENT_ROOT = /var/www/htdocs/freeside
37 #suse
38 #FREESIDE_DOCUMENT_ROOT = /srv/www/htdocs/freeside
39 #apache
40 #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside
41
42 #deb, redhat, fedora, mandrake, suse, others?
43 INIT_FILE = /etc/init.d/freeside
44 #freebsd
45 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
46
47 #deb
48 INIT_INSTALL = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside defaults 23 01
49 #redhat, fedora
50 #INIT_INSTALL = /sbin/chkconfig freeside on
51 #not necessary (freebsd)
52 #INIT_INSTALL = /usr/bin/true
53
54 #deb, suse
55 #HTTPD_RESTART = /etc/init.d/apache restart
56 #deb w/apache2
57 HTTPD_RESTART = /etc/init.d/apache2 restart
58 #redhat, fedora, mandrake
59 #HTTPD_RESTART = /etc/init.d/httpd restart
60 #freebsd
61 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop || true; sleep 10; /usr/local/etc/rc.d/apache.sh start
62 #openbsd
63 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 10; /usr/sbin/httpd -u -DSSL
64 #apache
65 #HTTPD_RESTART = /usr/local/apache/bin/apachectl stop; sleep 10; /usr/local/apache/bin/apachectl startssl
66
67 #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf)
68 #deb (3.1+), apache2
69 APACHE_CONF = /etc/apache2/conf.d
70
71 FREESIDE_RESTART = ${INIT_FILE} restart
72
73 #deb, redhat, fedora, mandrake, suse, others?
74 INSTALLGROUP = root
75 #freebsd, openbsd
76 #INSTALLGROUP = wheel
77
78 #edit the stuff below to have the daemons start
79
80 QUEUED_USER=fs_queue
81
82 SELFSERVICE_USER = fs_selfservice
83 #never run on the same machine in production!!!
84 SELFSERVICE_MACHINES = 
85 # SELFSERVICE_MACHINES = www.example.com
86 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
87
88 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
89 #installation.
90 SELFSERVICE_INSTALL_USER = ivan
91 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
92 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
93
94 #RT_ENABLED = 0
95 RT_ENABLED = 1
96 RT_DOMAIN = example.com
97 RT_TIMEZONE = US/Pacific
98 #RT_TIMEZONE = US/Eastern
99 FREESIDE_URL = "http://localhost/freeside/"
100
101 #for now, same db as specified in DATASOURCE... eventually, otherwise?
102 RT_DB_DATABASE = freeside
103
104 TORRUS_ENABLED = 0
105
106 # for cvs-upgrade-deploy target, the username who checked out the CVS copy.
107 CVS_USER = ivan
108
109 # for auto-version updates, so we can "make release" more things automatically
110 RPM_SPECFILE = rpm/freeside.spec
111
112 #---
113
114 #rt/config.layout.in
115 RT_PATH = /opt/rt3
116
117 #only used for dev kludge now, not a big deal
118 FREESIDE_PATH = `pwd`
119 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.10.1/
120
121 VERSION=2.3.1cvs
122 TAG=freeside_2_3_1
123
124 DEBVERSION = `echo ${VERSION} | perl -pe 's/(\d)([a-z])/\1~\2/'`-1
125
126 TEXMFHOME := "\$$TEXMFHOME"
127
128 help:
129         @echo "supported targets:"
130         @echo "                   create-database create-config"
131         @echo "                   install deploy"
132         @echo "                   cvs-upgrade-deploy"
133         @echo "                   configure-rt create-rt"
134         @echo "                   clean help"
135         @echo
136         @echo "                   install-docs install-perl-modules"
137         @echo "                   install-init install-apache"
138         @echo "                   install-rt install-texmf"
139         @echo "                   install-selfservice update-selfservice"
140         @echo
141         @echo "                   dev dev-docs dev-perl-modules"
142         @echo
143         @echo "                   masondocs alldocs docs"
144         @echo "                   wikiman"
145         @echo "                   perl-modules"
146         #@echo
147         #@echo "                   upload-docs release"
148
149
150 masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
151         rm -rf masondocs
152         cp -pr httemplate masondocs
153         touch masondocs
154
155 alldocs: masondocs
156
157 docs:
158         make masondocs
159
160 wikiman:
161         chmod a+rx ./bin/pod2x
162         ./bin/pod2x
163
164 install-docs: check-conflicts docs
165         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
166         cp -r masondocs ${FREESIDE_DOCUMENT_ROOT}
167         chown -R freeside:freeside ${FREESIDE_DOCUMENT_ROOT}
168         cp htetc/handler.pl ${MASON_HANDLER}
169         cp htetc/htpasswd.logout ${FREESIDE_CONF}
170         [ ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
171         chown -R freeside ${MASONDATA}
172
173 dev-docs:
174         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
175         ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
176         cp htetc/handler.pl ${MASON_HANDLER}
177         perl -p -i -e "\
178           s'###use Module::Refresh;###'use Module::Refresh;'; \
179           s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
180         " ${MASON_HANDLER} || true
181
182 perl-modules:
183         cd FS; \
184         [ -e Makefile ] || perl Makefile.PL; \
185         make; \
186         perl -p -i -e "\
187           s/%%%VERSION%%%/${VERSION}/g;\
188         " blib/lib/FS.pm;\
189         perl -p -i -e "\
190           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
191           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
192           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
193           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
194           s'%%%RT_PATH%%%'${RT_PATH}'g; \
195           s'%%%MASONDATA%%%'${MASONDATA}'g;\
196           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
197         " blib/lib/FS/*.pm;\
198         perl -p -i -e "\
199           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
200           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
201           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
202         " blib/lib/FS/Cron/*.pm;\
203         perl -p -i -e "\
204           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
205           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
206           s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
207         " blib/lib/FS/part_export/*.pm;\
208         perl -p -i -e "\
209           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
210         " blib/lib/FS/cust_main/*.pm blib/lib/FS/cust_pkg/*.pm;\
211         perl -p -i -e "\
212           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
213           s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
214           s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
215           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
216           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
217           s|%%%DIST_CONF%%%|${DIST_CONF}|g;\
218         " blib/script/*
219
220 install-perl-modules: check-conflicts perl-modules install-rt-initialdata
221         [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
222           && rm ${PERL_INC_DEV_KLUDGE}/FS \
223           && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
224           || true
225         cd FS; \
226         make install UNINST=1
227         #install this for freeside-setup
228         install -d $(DIST_CONF)
229         #install conf/[a-z]* $(DEFAULT_CONF)
230         #CVS is not [a-z]
231         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
232
233 dev-perl-modules: perl-modules
234         [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
235           && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
236           || true
237
238         rm -rf ${PERL_INC_DEV_KLUDGE}/FS
239         ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
240
241 install-texmf:  
242         install -D -o freeside -m 444 etc/fslongtable.sty \
243           `kpsewhich -expand-var \\\$$TEXMFLOCAL`/tex/generic/fslongtable.sty
244         texhash `kpsewhich -expand-var \\\$$TEXMFLOCAL`
245
246 install-init:
247         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
248         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
249         perl -p -i -e "\
250           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
251           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
252           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
253         " ${INIT_FILE}
254         ${INIT_INSTALL}
255
256 install-apache:
257         [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
258         [ -d ${APACHE_CONF} ] && \
259           ( install -o root -m 755 htetc/freeside-base2.conf ${APACHE_CONF} && \
260             ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
261             ( [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-torrus.conf ${APACHE_CONF} || true ) && \
262             perl -p -i -e "\
263               s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
264               s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
265               s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
266             " ${APACHE_CONF}/freeside-*.conf \
267           ) || true
268
269 install-selfservice:
270         [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
271         [ -e ~freeside/.ssh/id_dsa.pub ] || [ -e ~freeside/.ssh/id_rsa.pub ] || su - freeside -c 'ssh-keygen -t dsa'
272         for MACHINE in ${SELFSERVICE_MACHINES}; do \
273           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
274           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
275           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
276           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
277           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -d -o freeside -m 600 ~freeside/.ssh/; sudo install -o freeside -m 600 ./id_dsa.pub ~freeside/.ssh/authorized_keys" ;\
278            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
279         done
280
281 update-selfservice:
282         for MACHINE in ${SELFSERVICE_MACHINES}; do \
283           RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
284           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; make clean; perl Makefile.PL && make" ;\
285           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
286         done
287
288 install-chown:
289         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
290         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
291         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
292
293 install: install-perl-modules install-docs install-init install-apache install-rt install-torrus install-texmf install-chown
294
295 deploy: install
296         ${HTTPD_RESTART}
297         ${FREESIDE_RESTART}
298
299 cvs-upgrade-deploy:
300         su ${CVS_USER} -c 'cvs update -d -P'
301         make install-perl-modules
302         su freeside -c "freeside-upgrade ${CVS_USER}" #not really the same user
303         make deploy
304
305 dev: dev-perl-modules dev-docs
306
307 create-database:
308         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
309
310 create-config: install-perl-modules
311         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
312         install -d -o freeside ${FREESIDE_CONF}
313
314         touch ${FREESIDE_CONF}/secrets
315         chown freeside ${FREESIDE_CONF}/secrets
316         chmod 600 ${FREESIDE_CONF}/secrets
317
318         /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
319         chmod 600 ${FREESIDE_CONF}/secrets
320         chown freeside ${FREESIDE_CONF}/secrets
321
322         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
323         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
324
325         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
326         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
327
328         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
329         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
330
331         #install this for freeside-setup
332         install -d $(DIST_CONF)
333         #install conf/[a-z]* $(DEFAULT_CONF)
334         #CVS is not [a-z]
335         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
336
337
338 configure-rt:
339         cd rt; \
340         cp config.layout.in config.layout; \
341         perl -p -i -e "\
342           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
343           s'%%%MASONDATA%%%'${MASONDATA}'g;\
344         " config.layout; \
345         ./configure --enable-layout=Freeside\
346                     --with-db-type=${DB_TYPE} \
347                     --with-db-dba=${DB_USER} \
348                     --with-db-database=${RT_DB_DATABASE} \
349                     --with-db-rt-user=${DB_USER} \
350                     --with-db-rt-pass=${DB_PASSWORD} \
351                     --with-web-user=freeside \
352                     --with-web-group=freeside \
353                     --with-rt-group=freeside \
354                     --with-web-handler=modperl2
355
356 create-rt: configure-rt
357         [ -d /opt           ] || mkdir /opt           #doh
358         [ -d /opt/rt3       ] || mkdir /opt/rt3       #
359         [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
360         cd rt; make install
361         rt/sbin/rt-setup-database --dba '${DB_USER}' \
362                                   --dba-password '${DB_PASSWORD}' \
363                                   --action schema \
364          || true
365         rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
366                                   --action coredata \
367         && rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
368                                      --action insert \
369                                      --datafile ${RT_PATH}/etc/initialdata \
370         || true
371
372 install-rt: check-conflicts
373         if [ ${RT_ENABLED} -eq 1 ]; then ( cd rt; make install ); fi
374         if [ ${RT_ENABLED} -eq 1 ]; then perl -p -i -e "\
375           s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
376           s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
377           s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
378         " ${RT_PATH}/etc/RT_SiteConfig.pm; fi
379         if [ ${RT_ENABLED} -eq 1 ]; then \
380           chown -R freeside:freeside ${RT_PATH}/etc; fi
381
382 install-rt-initialdata:
383         if [ ${RT_ENABLED} -eq 1 ] && [ -d ${RT_PATH} ]; then \
384           chown -R freeside:freeside ${RT_PATH}/etc; \
385           install -D -o freeside -g freeside -m 0440 rt/etc/initialdata \
386           ${RT_PATH}/etc/initialdata; fi
387
388 configure-torrus:
389         cd torrus; \
390         torrus_user=freeside var_user=freeside var_group=freeside ./configure
391
392 install-torrus:
393         if [ ${TORRUS_ENABLED} -eq 1 ]; then ( cd torrus; \
394           make; \
395           make install; \
396           perl -p -i -e "\
397             s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
398           " /usr/local/etc/torrus/conf/torrus-siteconfig.pl; \
399           torrus clearcache \
400         );fi
401
402 clean:
403         rm -rf masondocs
404         rm -rf httemplate/docs/man
405         rm -rf pod2htmi.tmp
406         rm -rf pod2htmd.tmp
407         -cd FS; \
408         make clean
409         -cd fs_selfservice/FS-SelfService; \
410         make clean
411
412 check-conflicts:
413         ! grep -r --exclude='*config.log*' '--exclude=*config.status*' --exclude=gnupg_details_on_output_formats '--exclude=*mason_handler*' '^=======$$' .
414
415 #these are probably only useful if you're me...
416
417 #release: upload-docs
418 .PHONY: release
419 release:
420         # Update the changelog
421         ./bin/cvs2cl
422         cvs commit -m "Updated for ${VERSION}" ChangeLog
423
424         # Update the RPM specfile
425         cvs edit ${RPM_SPECFILE}
426         perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
427         perl -p -i -e "s/\d+[^\}]+/1/ if /%define\s+release\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
428         cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
429
430         # Update the Debian changelog
431         cvs edit debian/changelog
432         dch -v ${DEBVERSION} -p "New upstream release"
433         cvs commit -m "Updated for ${VERSION}" debian/changelog
434
435         # Make sure other people's changes are pulled in!
436         cvs update -d -P || true #it exits 1...
437
438         # Tag the release
439         #cvs tag ${TAG}
440         cvs tag -F ${TAG}
441
442         #cd /home/ivan
443         cvs export -r ${TAG} -d freeside-${VERSION} freeside
444         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
445
446         scp freeside-${VERSION}.tar.gz ivan@420.am:/var/www/www.sisd.com/freeside/
447         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
448
449         #these things failing should not make release target fail, so: "|| true"
450
451         #kick off vmware update
452         #./BUILD_VMWARE_APPLIANCE ${$TAG} || true
453
454         #kick off deb package update
455
456         #kick off rpm package update too?
457
458         #update web demo?
459
460         #update web demo self-service?
461