fix net sales amount (credits were being applied in wrong month), RT#7502
[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 #mod_perl v1
25 #APACHE_VERSION = 1
26 #mod_perl v2 prereleases up to and including 1.999_21
27 #APACHE_VERSON = 1.99
28 #mod_perl v2 proper and prereleases 1.999_22 and after
29 APACHE_VERSION = 2
30
31 #deb
32 FREESIDE_DOCUMENT_ROOT = /var/www/freeside
33 #redhat, fedora, mandrake
34 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
35 #freebsd
36 #FREESIDE_DOCUMENT_ROOT = /usr/local/www/data/freeside
37 #openbsd
38 #FREESIDE_DOCUMENT_ROOT = /var/www/htdocs/freeside
39 #suse
40 #FREESIDE_DOCUMENT_ROOT = /srv/www/htdocs/freeside
41 #apache
42 #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside
43
44 #deb, redhat, fedora, mandrake, suse, others?
45 INIT_FILE = /etc/init.d/freeside
46 #freebsd
47 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
48
49 #deb
50 INIT_INSTALL = /usr/sbin/update-rc.d freeside defaults 21 20
51 #redhat, fedora
52 #INIT_INSTALL = /sbin/chkconfig freeside on
53 #not necessary (freebsd)
54 #INIT_INSTALL = /usr/bin/true
55
56 #deb, suse
57 #HTTPD_RESTART = /etc/init.d/apache restart
58 #deb w/apache2
59 HTTPD_RESTART = /etc/init.d/apache2 restart
60 #redhat, fedora, mandrake
61 #HTTPD_RESTART = /etc/init.d/httpd restart
62 #freebsd
63 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop || true; sleep 10; /usr/local/etc/rc.d/apache.sh start
64 #openbsd
65 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 10; /usr/sbin/httpd -u -DSSL
66 #apache
67 #HTTPD_RESTART = /usr/local/apache/bin/apachectl stop; sleep 10; /usr/local/apache/bin/apachectl startssl
68
69 #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf)
70 #deb (3.1+), apache1
71 #APACHE_CONF = /etc/apache/conf.d
72 #deb (3.1+), apache2
73 APACHE_CONF = /etc/apache2/conf.d
74
75 FREESIDE_RESTART = ${INIT_FILE} restart
76
77 #deb, redhat, fedora, mandrake, suse, others?
78 INSTALLGROUP = root
79 #freebsd, openbsd
80 #INSTALLGROUP = wheel
81
82 #edit the stuff below to have the daemons start
83
84 QUEUED_USER=fs_queue
85
86 SELFSERVICE_USER = fs_selfservice
87 #never run on the same machine in production!!!
88 SELFSERVICE_MACHINES = 
89 # SELFSERVICE_MACHINES = www.example.com
90 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
91
92 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
93 #installation.
94 SELFSERVICE_INSTALL_USER = ivan
95 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
96 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
97
98 #RT_ENABLED = 0
99 RT_ENABLED = 1
100 RT_DOMAIN = example.com
101 RT_TIMEZONE = US/Pacific
102 #RT_TIMEZONE = US/Eastern
103 FREESIDE_URL = "http://localhost/freeside/"
104
105 #for now, same db as specified in DATASOURCE... eventually, otherwise?
106 RT_DB_DATABASE = freeside
107
108 RPM_SPECFILE = install/rpm/freeside.spec
109
110 #---
111
112
113 #rt/config.layout.in
114 RT_PATH = /opt/rt3
115
116 #only used for dev kludge now, not a big deal
117 FREESIDE_PATH = `pwd`
118 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.10.0/
119
120 VERSION=1.7.4
121 TAG=freeside_1_7_4
122
123 DEBVERSION = `echo ${VERSION} | perl -pe 's/(\d)([a-z])/\1~\2/'`-1
124
125 help:
126         @echo "supported targets:"
127         @echo "                   create-database create-config"
128         @echo "                   install deploy"
129         @echo "                   configure-rt create-rt"
130         @echo "                   clean help"
131         @echo
132         @echo "                   install-docs install-perl-modules"
133         @echo "                   install-init install-apache"
134         @echo "                   install-rt"
135         @echo "                   install-selfservice update-selfservice"
136         @echo
137         @echo "                   dev dev-docs dev-perl-modules"
138         @echo
139         @echo "                   masondocs alldocs docs"
140         @echo "                   wikiman"
141         @echo "                   perl-modules"
142         #@echo
143         #@echo "                   upload-docs release update-webdemo"
144
145
146 masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
147         rm -rf masondocs
148         cp -pr httemplate masondocs
149         touch masondocs
150
151 alldocs: masondocs
152
153 docs:
154         make masondocs
155
156 wikiman:
157         chmod a+rx ./bin/pod2x
158         ./bin/pod2x
159
160 install-docs: docs
161         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
162         cp -r masondocs ${FREESIDE_DOCUMENT_ROOT}
163         chown -R freeside:freeside ${FREESIDE_DOCUMENT_ROOT}
164         cp htetc/handler.pl ${MASON_HANDLER}
165           perl -p -i -e "\
166             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
167             s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
168             s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
169             s'%%%MASONDATA%%%'${MASONDATA}'g;\
170           " ${MASON_HANDLER}
171         [ ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
172         chown -R freeside ${MASONDATA}
173
174 dev-docs:
175         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
176         ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
177         cp htetc/handler.pl ${MASON_HANDLER}
178         perl -p -i -e "\
179           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
180           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
181           s'%%%MASONDATA%%%'${MASONDATA}'g;\
182           s'###use Module::Refresh;###'use Module::Refresh;'; \
183           s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
184         " ${MASON_HANDLER} || true
185
186
187 perl-modules:
188         cd FS; \
189         [ -e Makefile ] || perl Makefile.PL; \
190         make; \
191         perl -p -i -e "\
192           s/%%%VERSION%%%/${VERSION}/g;\
193         " blib/lib/FS.pm;\
194         perl -p -i -e "\
195           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
196           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
197         " blib/lib/FS/*.pm;\
198         perl -p -i -e "\
199           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
200         " blib/lib/FS/part_export/*.pm;\
201         perl -p -i -e "\
202           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
203           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
204         " blib/lib/FS/Cron/*.pm;\
205         perl -p -i -e "\
206           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
207           s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
208           s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
209           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
210           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
211         " blib/script/*
212
213 install-perl-modules: perl-modules
214         [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
215           && rm ${PERL_INC_DEV_KLUDGE}/FS \
216           && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
217           || true
218         cd FS; \
219         make install UNINST=1
220
221 dev-perl-modules: perl-modules
222         [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
223           && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
224           || true
225
226         rm -rf ${PERL_INC_DEV_KLUDGE}/FS
227         ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
228
229 install-init:
230         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
231         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
232         perl -p -i -e "\
233           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
234           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
235           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
236         " ${INIT_FILE}
237         ${INIT_INSTALL}
238
239 install-apache:
240         [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
241         [ -d ${APACHE_CONF} ] && \
242           ( install -o root -m 755 htetc/freeside-base${APACHE_VERSION}.conf ${APACHE_CONF} && \
243             ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
244             perl -p -i -e "\
245               s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
246               s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
247               s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
248             " ${APACHE_CONF}/freeside-*.conf \
249           ) || true
250
251 install-selfservice:
252         [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
253         [ -e ~freeside/.ssh/id_dsa.pub ] || [ -e ~freeside/.ssh/id_rsa.pub ] || su - freeside -c 'ssh-keygen -t dsa'
254         for MACHINE in ${SELFSERVICE_MACHINES}; do \
255           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
256           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
257           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
258           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
259           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -d -o freeside -m 600 ~freeside/.ssh/" ;\
260           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -o freeside -m 600 ./id_dsa.pub ~freeside/.ssh/authorized_keys" ;\
261            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
262         done
263
264 update-selfservice:
265         for MACHINE in ${SELFSERVICE_MACHINES}; do \
266           RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
267           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; make clean; perl Makefile.PL && make" ;\
268           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
269         done
270
271 install: install-perl-modules install-docs install-init install-apache install-rt
272
273 deploy: install
274         ${HTTPD_RESTART}
275         ${FREESIDE_RESTART}
276
277 dev: dev-perl-modules dev-docs
278
279 create-database:
280         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
281
282 create-config: install-perl-modules
283         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
284         install -d -o freeside ${FREESIDE_CONF}
285
286         touch ${FREESIDE_CONF}/secrets
287         chown freeside ${FREESIDE_CONF}/secrets
288         chmod 600 ${FREESIDE_CONF}/secrets
289
290         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
291         chmod 600 ${FREESIDE_CONF}/secrets
292         chown freeside ${FREESIDE_CONF}/secrets
293
294         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
295         rm -rf conf/registries #old dirs just won't go away
296         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
297         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
298         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
299
300         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
301         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
302
303         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
304         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
305
306         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
307         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
308
309 configure-rt:
310         cd rt; \
311         cp config.layout.in config.layout; \
312         perl -p -i -e "\
313           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
314           s'%%%MASONDATA%%%'${MASONDATA}'g;\
315         " config.layout; \
316         ./configure --enable-layout=Freeside\
317                     --with-db-type=${DB_TYPE} \
318                     --with-db-dba=${DB_USER} \
319                     --with-db-database=${RT_DB_DATABASE} \
320                     --with-db-rt-user=${DB_USER} \
321                     --with-db-rt-pass=${DB_PASSWORD} \
322                     --with-web-user=freeside \
323                     --with-web-group=freeside \
324                     --with-rt-group=freeside
325
326 create-rt: configure-rt
327         [ -d /opt           ] || mkdir /opt           #doh
328         [ -d /opt/rt3       ] || mkdir /opt/rt3       #
329         [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
330         cd rt; make install
331         rt/sbin/rt-setup-database --dba '${DB_USER}' \
332                                   -dba-password '${DB_PASSWORD}' \
333                                   -action schema \
334          || true
335         rt/sbin/rt-setup-database --action insert_initial \
336         && rt/sbin/rt-setup-database --action insert --datafile ${RT_PATH}/etc/initialdata \
337         || true
338         perl -p -i -e "\
339           s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
340           s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
341           s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
342         " ${RT_PATH}/etc/RT_SiteConfig.pm
343
344 install-rt:
345         [ ${RT_ENABLED} -eq 1 ] && ( cd rt; make install ) || true
346
347 clean:
348         rm -rf masondocs
349         rm -rf httemplate/docs/man
350         rm -rf pod2htmi.tmp
351         rm -rf pod2htmd.tmp
352         -cd FS; \
353         make clean
354         -cd fs_selfservice/FS-SelfService; \
355         make clean
356
357 #these are probably only useful if you're me...
358
359 #release: upload-docs
360 .PHONY: release
361 release:
362         # Update the changelog
363         ./CVS2CL
364         cvs commit -m "Updated for ${VERSION}" ChangeLog
365
366         # Update the RPM specfile
367         cvs edit ${RPM_SPECFILE}
368         perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
369         perl -p -i -e "s/\d+[^\}]+/1/ if /%define\s+release\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
370         cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
371
372         # Update the Debian changelog
373         cvs edit debian/changelog
374         dch -v ${DEBVERSION} -p "New upstream release"
375         cvs commit -m "Updated for ${VERSION}" debian/changelog
376
377         #cvs tag ${TAG}
378         cvs tag -F ${TAG}
379
380         #cd /home/ivan
381         cvs export -r ${TAG} -d freeside-${VERSION} freeside
382         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
383
384         scp freeside-${VERSION}.tar.gz ivan@420.am:/var/www/www.sisd.com/freeside/
385         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
386
387         #these things failing should not make release target fail, so: "|| true"
388
389         #kick off vmware update
390         #./BUILD_VMWARE_APPLIANCE ${$TAG} || true
391
392         #kick off deb package update
393
394         #kick off rpm package update too?
395
396         #update web demo?
397
398         #update web demo self-service?
399
400 update-webdemo:
401         ssh ivan@420.am '( cd freeside; cvs update -d -P )'
402         #ssh root@420.am '( cd /home/ivan/freeside; make clean; make deploy )'
403         ssh root@420.am '( cd /home/ivan/freeside; make deploy )'
404