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