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