that should fix statuses on receivables report
[freeside.git] / Makefile
1 #!/usr/bin/make
2
3 #solaris and perhaps other very weirdass /bin/sh
4 #SHELL="/bin/ksh"
5
6 DATASOURCE = DBI:Pg:dbname=freeside
7 #DATASOURCE=DBI:mysql:freeside
8
9 DB_USER = freeside
10 DB_PASSWORD=
11
12 TEMPLATE = mason
13
14 MASON_HANDLER = /usr/local/etc/freeside/handler.pl
15 MASONDATA = /usr/local/etc/freeside/masondata
16
17 #deb
18 FREESIDE_DOCUMENT_ROOT = /var/www/freeside
19 #redhat, fedora, mandrake
20 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
21 #freebsd
22 #FREESIDE_DOCUMENT_ROOT = /usr/local/www/data/freeside
23 #openbsd
24 #FREESIDE_DOCUMENT_ROOT = /var/www/htdocs/freeside
25 #suse
26 #FREESIDE_DOCUMENT_ROOT = /srv/www/htdocs/freeside
27 #apache
28 #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside
29
30 #deb, redhat, fedora, mandrake, suse, others?
31 INIT_FILE = /etc/init.d/freeside
32 #freebsd
33 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
34
35 #deb
36 INIT_INSTALL = /usr/sbin/update-rc.d freeside defaults 21 20
37 #redhat, fedora
38 #INIT_INSTALL = /sbin/chkconfig freeside on
39 #not necessary (freebsd)
40 #INIT_INSTALL = /usr/bin/true
41
42 #deb, suse
43 HTTPD_RESTART = /etc/init.d/apache restart
44 #redhat, fedora, mandrake
45 #HTTPD_RESTART = /etc/init.d/httpd restart
46 #freebsd
47 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop || true; sleep 10; /usr/local/etc/rc.d/apache.sh start
48 #openbsd
49 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 10; /usr/sbin/httpd -u -DSSL
50 #apache
51 #HTTPD_RESTART = /usr/local/apache/bin/apachectl stop; sleep 10; /usr/local/apache/bin/apachectl startssl
52
53 #(an include directory, not a file - "Include /etc/apache/conf.d" in httpd.conf)
54 #deb (3.1+), 
55 APACHE_CONF = /etc/apache/conf.d
56
57 FREESIDE_RESTART = ${INIT_FILE} restart
58
59 #deb, redhat, fedora, mandrake, suse, others?
60 INSTALLGROUP = root
61 #freebsd, openbsd
62 #INSTALLGROUP = wheel
63
64 #edit the stuff below to have the daemons start
65
66 QUEUED_USER=fs_queue
67
68 SELFSERVICE_USER = fs_selfservice
69 #never run on the same machine in production!!!
70 SELFSERVICE_MACHINES = localhost
71 # SELFSERVICE_MACHINES = www.example.com
72 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
73
74 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
75 #installation.
76 SELFSERVICE_INSTALL_USER = ivan
77 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
78 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
79
80 #RT_ENABLED = 0
81 RT_ENABLED = 1
82 RT_DOMAIN = example.com
83 RT_TIMEZONE = US/Pacific
84 #RT_TIMEZONE = US/Eastern
85 FREESIDE_URL = "http://localhost/freeside/"
86
87 #for now, same db as specified in DATASOURCE... eventually, otherwise?
88 RT_DB_DATABASE = freeside
89
90 #---
91
92 #not changable yet
93 FREESIDE_CONF = /usr/local/etc/freeside
94 #rt/config.layout.in
95 RT_PATH = /opt/rt3
96
97 #only used for dev kludge now, not a big deal
98 FREESIDE_PATH = `pwd`
99 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.8.8/
100
101 VERSION=1.7.0
102 TAG=freeside_1_7_0
103
104 help:
105         @echo "supported targets:"
106         @echo "                   create-database create-config"
107         @echo "                   install deploy"
108         @echo "                   configure-rt create-rt"
109         @echo "                   clean help"
110         @echo
111         @echo "                   install-docs install-perl-modules"
112         @echo "                   install-init install-apache"
113         @echo "                   install-rt"
114         @echo "                   install-selfservice update-selfservice"
115         @echo
116         @echo "                   dev dev-docs dev-perl-modules"
117         @echo
118         @echo "                   masondocs alldocs docs"
119         @echo "                   htmlman forcehtmlman"
120         @echo "                   perl-modules"
121         #@echo
122         #@echo "                   upload-docs release update-webdemo"
123
124
125 masondocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
126         rm -rf masondocs
127         cp -pr httemplate masondocs
128         touch masondocs
129
130 alldocs: masondocs
131
132 docs:
133         make ${TEMPLATE}docs
134
135 htmlman:
136         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
137         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
138         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
139         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
140         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
141         chmod a+rx bin/pod2x
142         [ -e DONT_REBUILD_DOCS ] || bin/pod2x
143
144 forcehtmlman:
145         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
146         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
147         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
148         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
149         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
150         bin/pod2x
151
152 install-docs: docs
153         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
154         cp -r ${TEMPLATE}docs ${FREESIDE_DOCUMENT_ROOT}
155         cp htetc/handler.pl ${MASON_HANDLER}
156         perl -p -i -e "\
157           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
158           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
159         " ${MASON_HANDLER}
160         [ ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
161         chown -R freeside ${MASONDATA}
162
163 dev-docs:
164         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
165         ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
166         cp htetc/handler.pl ${MASON_HANDLER}
167         perl -p -i -e "\
168           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
169           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
170           s'###use Module::Refresh;###'use Module::Refresh;'; \
171           s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
172         " ${MASON_HANDLER} || true
173
174
175 perl-modules:
176         cd FS; \
177         [ -e Makefile ] || perl Makefile.PL; \
178         make; \
179         perl -p -i -e "\
180           s/%%%VERSION%%%/${VERSION}/g;\
181         " blib/lib/FS.pm; \
182
183 install-perl-modules: perl-modules
184         [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
185           && rm ${PERL_INC_DEV_KLUDGE}/FS \
186           && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
187           || true
188         cd FS; \
189         make install UNINST=1
190
191 dev-perl-modules: perl-modules
192         [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
193           && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
194           || true
195
196         rm -rf ${PERL_INC_DEV_KLUDGE}/FS
197         ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
198
199 install-init:
200         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
201         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
202         perl -p -i -e "\
203           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
204           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
205           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
206         " ${INIT_FILE}
207         ${INIT_INSTALL}
208
209 install-apache:
210         [ -d ${APACHE_CONF} ] && \
211           ( install -o root -m 755 htetc/freeside-base.conf ${APACHE_CONF} && \
212             ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
213             perl -p -i -e "\
214               s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
215             " ${APACHE_CONF}/freeside-*.conf \
216           ) || true
217
218 install-selfservice:
219         [ -e ~freeside/.ssh/id_dsa.pub ] || su - freeside -c 'ssh-keygen -t dsa'
220         for MACHINE in ${SELFSERVICE_MACHINES}; do \
221           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
222           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
223           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
224           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
225           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -d -o freeside -m 600 ~freeside/.ssh/" ;\
226           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -o freeside -m 600 ./id_dsa.pub ~freeside/.ssh/authorized_keys" ;\
227            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
228         done
229
230 update-selfservice:
231         for MACHINE in ${SELFSERVICE_MACHINES}; do \
232           RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
233           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
234           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
235         done
236
237 install: install-perl-modules install-docs install-init install-apache install-rt
238
239 deploy: install
240         ${HTTPD_RESTART}
241         ${FREESIDE_RESTART}
242
243 dev: dev-perl-modules dev-docs
244
245 create-database:
246         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
247
248 create-config: install-perl-modules
249         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
250         install -d -o freeside ${FREESIDE_CONF}
251
252         touch ${FREESIDE_CONF}/secrets
253         chown freeside ${FREESIDE_CONF}/secrets
254         chmod 600 ${FREESIDE_CONF}/secrets
255
256         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
257         chmod 600 ${FREESIDE_CONF}/secrets
258         chown freeside ${FREESIDE_CONF}/secrets
259
260         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
261         rm -rf conf/registries #old dirs just won't go away
262         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
263         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
264         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
265
266         mkdir "${FREESIDE_CONF}/counters.${DATASOURCE}"
267         chown freeside "${FREESIDE_CONF}/counters.${DATASOURCE}"
268
269         mkdir "${FREESIDE_CONF}/cache.${DATASOURCE}"
270         chown freeside "${FREESIDE_CONF}/cache.${DATASOURCE}"
271
272         mkdir "${FREESIDE_CONF}/export.${DATASOURCE}"
273         chown freeside "${FREESIDE_CONF}/export.${DATASOURCE}"
274
275 configure-rt:
276         cd rt; \
277         cp config.layout.in config.layout; \
278         perl -p -i -e "\
279           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
280           s'%%%MASONDATA%%%'${MASONDATA}'g;\
281         " config.layout; \
282         ./configure --enable-layout=Freeside\
283                     --with-db-type=Pg \
284                     --with-db-dba=${DB_USER} \
285                     --with-db-database=${RT_DB_DATABASE} \
286                     --with-db-rt-user=${DB_USER} \
287                     --with-db-rt-pass=${DB_PASSWORD} \
288                     --with-web-user=freeside \
289                     --with-web-group=freeside \
290                     --with-rt-group=freeside
291
292 create-rt: configure-rt
293         [ -d /opt           ] || mkdir /opt           #doh
294         [ -d /opt/rt3       ] || mkdir /opt/rt3       #
295         [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
296         cd rt; make install
297         echo -e "${DB_PASSWORD}\n\\d sessions"\
298          | psql -U ${DB_USER} -W ${RT_DB_DATABASE} 2>&1\
299          | grep '^Did not find'\
300          && rt/sbin/rt-setup-database --dba '${DB_USER}' \
301                                      --dba-password '${DB_PASSWORD}' \
302                                      --action schema \
303          || true
304         rt/sbin/rt-setup-database --action insert_initial \
305         && rt/sbin/rt-setup-database --action insert --datafile ${RT_PATH}/etc/initialdata \
306         || true
307         perl -p -i -e "\
308           s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
309           s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
310           s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
311         " ${RT_PATH}/etc/RT_SiteConfig.pm
312
313 install-rt:
314         [ ${RT_ENABLED} -eq 1 ] && ( cd rt; make install ) || true
315
316 clean:
317         rm -rf masondocs
318         rm -rf httemplate/docs/man
319         rm -rf pod2htmi.tmp
320         rm -rf pod2htmd.tmp
321         -cd FS; \
322         make clean
323         -cd fs_selfservice/FS-SelfService; \
324         make clean
325
326 #these are probably only useful if you're me...
327
328 upload-docs: forcehtmlman
329         ssh 420.am rm -rf /var/www/www.sisd.com/freeside/docs
330         scp -pr httemplate/docs 420.am:/var/www/www.sisd.com/freeside/docs
331
332 #release: upload-docs
333 release:
334         cd /home/ivan/freeside
335         #cvs tag ${TAG}
336         cvs tag -F ${TAG}
337
338         #cd /home/ivan
339         cvs export -r ${TAG} -d freeside-${VERSION} freeside
340         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
341
342         scp freeside-${VERSION}.tar.gz ivan@420.am:/var/www/www.sisd.com/freeside/
343         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
344
345 update-webdemo:
346         ssh ivan@420.am '( cd freeside; cvs update -d -P )'
347         #ssh root@420.am '( cd /home/ivan/freeside; make clean; make deploy )'
348         ssh root@420.am '( cd /home/ivan/freeside; make deploy )'
349