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