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