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