that explains the bs with ChangeLog
[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+), apache2
71 APACHE_CONF = /etc/apache2/conf.d
72
73 FREESIDE_RESTART = ${INIT_FILE} restart
74
75 #deb, redhat, fedora, mandrake, suse, others?
76 INSTALLGROUP = root
77 #freebsd, openbsd
78 #INSTALLGROUP = wheel
79
80 #edit the stuff below to have the daemons start
81
82 QUEUED_USER=fs_queue
83
84 SELFSERVICE_USER = fs_selfservice
85 #never run on the same machine in production!!!
86 SELFSERVICE_MACHINES = localhost
87 # SELFSERVICE_MACHINES = www.example.com
88 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
89
90 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
91 #installation.
92 SELFSERVICE_INSTALL_USER = ivan
93 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
94 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
95
96 #RT_ENABLED = 0
97 RT_ENABLED = 1
98 RT_DOMAIN = example.com
99 RT_TIMEZONE = US/Pacific
100 #RT_TIMEZONE = US/Eastern
101 FREESIDE_URL = "http://localhost/freeside/"
102
103 #for now, same db as specified in DATASOURCE... eventually, otherwise?
104 RT_DB_DATABASE = freeside
105
106 RPM_SPECFILE = rpm/freeside.spec
107
108 #---
109
110
111 #rt/config.layout.in
112 RT_PATH = /opt/rt3
113
114 #only used for dev kludge now, not a big deal
115 FREESIDE_PATH = `pwd`
116 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.8.8/
117
118 VERSION=1.9.0cvs
119 TAG=freeside_1_9_0
120
121 DEBVERSION = `echo ${VERSION} | perl -pe 's/(\d)([a-z])/\1~\2/'`-1
122
123 help:
124         @echo "supported targets:"
125         @echo "                   create-database create-config"
126         @echo "                   install deploy"
127         @echo "                   configure-rt create-rt"
128         @echo "                   clean help"
129         @echo
130         @echo "                   install-docs install-perl-modules"
131         @echo "                   install-init install-apache"
132         @echo "                   install-rt"
133         @echo "                   install-selfservice update-selfservice"
134         @echo
135         @echo "                   dev dev-docs dev-perl-modules"
136         @echo
137         @echo "                   masondocs alldocs docs"
138         @echo "                   wikiman"
139         @echo "                   perl-modules"
140         #@echo
141         #@echo "                   upload-docs release update-webdemo"
142
143
144 masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
145         rm -rf masondocs
146         cp -pr httemplate masondocs
147         touch masondocs
148
149 alldocs: masondocs
150
151 docs:
152         make masondocs
153
154 wikiman:
155         chmod a+rx ./bin/pod2x
156         ./bin/pod2x
157
158 install-docs: docs
159         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
160         cp -r masondocs ${FREESIDE_DOCUMENT_ROOT}
161         chown -R freeside:freeside ${FREESIDE_DOCUMENT_ROOT}
162         cp htetc/handler.pl ${MASON_HANDLER}
163           perl -p -i -e "\
164             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
165             s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
166             s'%%%MASONDATA%%%'${MASONDATA}'g;\
167           " ${MASON_HANDLER}
168         [ ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
169         chown -R freeside ${MASONDATA}
170
171 dev-docs:
172         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
173         ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
174         cp htetc/handler.pl ${MASON_HANDLER}
175         perl -p -i -e "\
176           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
177           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
178           s'%%%MASONDATA%%%'${MASONDATA}'g;\
179           s'###use Module::Refresh;###'use Module::Refresh;'; \
180           s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
181         " ${MASON_HANDLER} || true
182
183
184 perl-modules:
185         cd FS; \
186         [ -e Makefile ] || perl Makefile.PL; \
187         make; \
188         perl -p -i -e "\
189           s/%%%VERSION%%%/${VERSION}/g;\
190         " blib/lib/FS.pm;\
191         perl -p -i -e "\
192           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
193           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
194         " blib/lib/FS/*.pm;\
195         perl -p -i -e "\
196           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
197         " blib/lib/FS/part_export/*.pm;\
198         perl -p -i -e "\
199           s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
200           s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
201           s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
202           s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
203           s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
204         " blib/script/*
205
206 install-perl-modules: perl-modules
207         [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
208           && rm ${PERL_INC_DEV_KLUDGE}/FS \
209           && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
210           || true
211         cd FS; \
212         make install UNINST=1
213
214 dev-perl-modules: perl-modules
215         [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
216           && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
217           || true
218
219         rm -rf ${PERL_INC_DEV_KLUDGE}/FS
220         ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
221
222 install-init:
223         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
224         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
225         perl -p -i -e "\
226           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
227           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
228           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
229         " ${INIT_FILE}
230         ${INIT_INSTALL}
231
232 install-apache:
233         [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
234         [ -d ${APACHE_CONF} ] && \
235           ( install -o root -m 755 htetc/freeside-base${APACHE_VERSION}.conf ${APACHE_CONF} && \
236             ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
237             perl -p -i -e "\
238               s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
239               s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
240               s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
241             " ${APACHE_CONF}/freeside-*.conf \
242           ) || true
243
244 install-selfservice:
245         [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
246         [ -e ~freeside/.ssh/id_dsa.pub ] || su - freeside -c 'ssh-keygen -t dsa'
247         for MACHINE in ${SELFSERVICE_MACHINES}; do \
248           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
249           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
250           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
251           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
252           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" ;\
253            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
254         done
255
256 update-selfservice:
257         for MACHINE in ${SELFSERVICE_MACHINES}; do \
258           RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
259           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
260           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
261         done
262
263 install: install-perl-modules install-docs install-init install-apache install-rt
264
265 deploy: install
266         ${HTTPD_RESTART}
267         ${FREESIDE_RESTART}
268
269 dev: dev-perl-modules dev-docs
270
271 create-database:
272         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
273
274 create-config: install-perl-modules
275         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
276         install -d -o freeside ${FREESIDE_CONF}
277
278         touch ${FREESIDE_CONF}/secrets
279         chown freeside ${FREESIDE_CONF}/secrets
280         chmod 600 ${FREESIDE_CONF}/secrets
281
282         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
283         chmod 600 ${FREESIDE_CONF}/secrets
284         chown freeside ${FREESIDE_CONF}/secrets
285
286         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
287         rm -rf conf/registries #old dirs just won't go away
288         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
289         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
290         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
291
292         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
293         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
294
295         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
296         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
297
298         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
299         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
300
301 configure-rt:
302         cd rt; \
303         cp config.layout.in config.layout; \
304         perl -p -i -e "\
305           s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
306           s'%%%MASONDATA%%%'${MASONDATA}'g;\
307         " config.layout; \
308         ./configure --enable-layout=Freeside\
309                     --with-db-type=${DB_TYPE} \
310                     --with-db-dba=${DB_USER} \
311                     --with-db-database=${RT_DB_DATABASE} \
312                     --with-db-rt-user=${DB_USER} \
313                     --with-db-rt-pass=${DB_PASSWORD} \
314                     --with-web-user=freeside \
315                     --with-web-group=freeside \
316                     --with-rt-group=freeside
317
318 create-rt: configure-rt
319         [ -d /opt           ] || mkdir /opt           #doh
320         [ -d /opt/rt3       ] || mkdir /opt/rt3       #
321         [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
322         cd rt; make install
323         rt/sbin/rt-setup-database --dba '${DB_USER}' \
324                                   -dba-password '${DB_PASSWORD}' \
325                                   -action schema \
326          || true
327         rt/sbin/rt-setup-database --action insert_initial \
328         && rt/sbin/rt-setup-database --action insert --datafile ${RT_PATH}/etc/initialdata \
329         || true
330
331 install-rt:
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         [ ${RT_ENABLED} -eq 1 ] && ( cd rt; make install ) || true
338
339 clean:
340         rm -rf masondocs
341         rm -rf httemplate/docs/man
342         rm -rf pod2htmi.tmp
343         rm -rf pod2htmd.tmp
344         -cd FS; \
345         make clean
346         -cd fs_selfservice/FS-SelfService; \
347         make clean
348
349 #these are probably only useful if you're me...
350
351 #release: upload-docs
352 .PHONY: release
353 release:
354         # Update the changelog
355         ./CVS2CL
356         cvs commit -m "Updated for ${VERSION}" -ko ChangeLog
357
358         # Update the RPM specfile
359         cvs edit ${RPM_SPECFILE}
360         perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
361         cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
362
363         # Update the Debian changelog
364         cvs edit 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