improve testing need for invoicing list
[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.4rc2
121 TAG=freeside_1_7_4rc2
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'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
168             s'%%%MASONDATA%%%'${MASONDATA}'g;\
169           " ${MASON_HANDLER}
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'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
179           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
180           s'%%%MASONDATA%%%'${MASONDATA}'g;\
181           s'###use Module::Refresh;###'use Module::Refresh;'; \
182           s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
183         " ${MASON_HANDLER} || true
184
185
186 perl-modules:
187         cd FS; \
188         [ -e Makefile ] || perl Makefile.PL; \
189         make; \
190         perl -p -i -e "\
191           s/%%%VERSION%%%/${VERSION}/g;\
192         " blib/lib/FS.pm;\
193         perl -p -i -e "\
194           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
195           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
196         " blib/lib/FS/*.pm;\
197         perl -p -i -e "\
198           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
199         " blib/lib/FS/part_export/*.pm;\
200         perl -p -i -e "\
201           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
202           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
203         " blib/lib/FS/Cron/*.pm;\
204         perl -p -i -e "\
205           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
206           s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
207           s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
208           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
209           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
210         " blib/script/*
211
212 install-perl-modules: perl-modules
213         [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
214           && rm ${PERL_INC_DEV_KLUDGE}/FS \
215           && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
216           || true
217         cd FS; \
218         make install UNINST=1
219
220 dev-perl-modules: perl-modules
221         [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
222           && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
223           || true
224
225         rm -rf ${PERL_INC_DEV_KLUDGE}/FS
226         ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
227
228 install-init:
229         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
230         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
231         perl -p -i -e "\
232           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
233           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
234           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
235         " ${INIT_FILE}
236         ${INIT_INSTALL}
237
238 install-apache:
239         [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
240         [ -d ${APACHE_CONF} ] && \
241           ( install -o root -m 755 htetc/freeside-base${APACHE_VERSION}.conf ${APACHE_CONF} && \
242             ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
243             perl -p -i -e "\
244               s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
245               s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
246               s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
247             " ${APACHE_CONF}/freeside-*.conf \
248           ) || true
249
250 install-selfservice:
251         [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
252         [ -e ~freeside/.ssh/id_dsa.pub ] || [ -e ~freeside/.ssh/id_rsa.pub ] || su - freeside -c 'ssh-keygen -t dsa'
253         for MACHINE in ${SELFSERVICE_MACHINES}; do \
254           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
255           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
256           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
257           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
258           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -d -o freeside -m 600 ~freeside/.ssh/" ;\
259           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -o freeside -m 600 ./id_dsa.pub ~freeside/.ssh/authorized_keys" ;\
260            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
261         done
262
263 update-selfservice:
264         for MACHINE in ${SELFSERVICE_MACHINES}; do \
265           RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
266           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; make clean; perl Makefile.PL && make" ;\
267           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
268         done
269
270 install: install-perl-modules install-docs install-init install-apache install-rt
271
272 deploy: install
273         ${HTTPD_RESTART}
274         ${FREESIDE_RESTART}
275
276 dev: dev-perl-modules dev-docs
277
278 create-database:
279         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
280
281 create-config: install-perl-modules
282         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
283         install -d -o freeside ${FREESIDE_CONF}
284
285         touch ${FREESIDE_CONF}/secrets
286         chown freeside ${FREESIDE_CONF}/secrets
287         chmod 600 ${FREESIDE_CONF}/secrets
288
289         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
290         chmod 600 ${FREESIDE_CONF}/secrets
291         chown freeside ${FREESIDE_CONF}/secrets
292
293         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
294         rm -rf conf/registries #old dirs just won't go away
295         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
296         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
297         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
298
299         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
300         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
301
302         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
303         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
304
305         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
306         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
307
308 configure-rt:
309         cd rt; \
310         cp config.layout.in config.layout; \
311         perl -p -i -e "\
312           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
313           s'%%%MASONDATA%%%'${MASONDATA}'g;\
314         " config.layout; \
315         ./configure --enable-layout=Freeside\
316                     --with-db-type=${DB_TYPE} \
317                     --with-db-dba=${DB_USER} \
318                     --with-db-database=${RT_DB_DATABASE} \
319                     --with-db-rt-user=${DB_USER} \
320                     --with-db-rt-pass=${DB_PASSWORD} \
321                     --with-web-user=freeside \
322                     --with-web-group=freeside \
323                     --with-rt-group=freeside
324
325 create-rt: configure-rt
326         [ -d /opt           ] || mkdir /opt           #doh
327         [ -d /opt/rt3       ] || mkdir /opt/rt3       #
328         [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
329         cd rt; make install
330         rt/sbin/rt-setup-database --dba '${DB_USER}' \
331                                   -dba-password '${DB_PASSWORD}' \
332                                   -action schema \
333          || true
334         rt/sbin/rt-setup-database --action insert_initial \
335         && rt/sbin/rt-setup-database --action insert --datafile ${RT_PATH}/etc/initialdata \
336         || true
337         perl -p -i -e "\
338           s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
339           s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
340           s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
341         " ${RT_PATH}/etc/RT_SiteConfig.pm
342
343 install-rt:
344         [ ${RT_ENABLED} -eq 1 ] && ( cd rt; make install ) || true
345
346 clean:
347         rm -rf masondocs
348         rm -rf httemplate/docs/man
349         rm -rf pod2htmi.tmp
350         rm -rf pod2htmd.tmp
351         -cd FS; \
352         make clean
353         -cd fs_selfservice/FS-SelfService; \
354         make clean
355
356 #these are probably only useful if you're me...
357
358 #release: upload-docs
359 .PHONY: release
360 release:
361         # Update the changelog
362         ./CVS2CL
363         cvs commit -m "Updated for ${VERSION}" ChangeLog
364
365         # Update the RPM specfile
366         cvs edit ${RPM_SPECFILE}
367         perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
368         perl -p -i -e "s/\d+[^\}]+/1/ if /%define\s+release\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
369         cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
370
371         # Update the Debian changelog
372         cvs edit debian/changelog
373         dch -v ${DEBVERSION} -p "New upstream release"
374         cvs commit -m "Updated for ${VERSION}" debian/changelog
375
376         #cvs tag ${TAG}
377         cvs tag -F ${TAG}
378
379         #cd /home/ivan
380         cvs export -r ${TAG} -d freeside-${VERSION} freeside
381         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
382
383         scp freeside-${VERSION}.tar.gz ivan@420.am:/var/www/www.sisd.com/freeside/
384         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
385
386         #these things failing should not make release target fail, so: "|| true"
387
388         #kick off vmware update
389         #./BUILD_VMWARE_APPLIANCE ${$TAG} || true
390
391         #kick off deb package update
392
393         #kick off rpm package update too?
394
395         #update web demo?
396
397         #update web demo self-service?
398
399 update-webdemo:
400         ssh ivan@420.am '( cd freeside; cvs update -d -P )'
401         #ssh root@420.am '( cd /home/ivan/freeside; make clean; make deploy )'
402         ssh root@420.am '( cd /home/ivan/freeside; make deploy )'
403