e1368c35c8ea2224171240ba32c6a9e9910e054b
[freeside.git] / Makefile
1 #!/usr/bin/make
2
3 DATASOURCE = DBI:Pg:dbname=freeside
4 #DATASOURCE=DBI:mysql:freeside
5
6 DB_USER = freeside
7 DB_PASSWORD=
8
9 #TEMPLATE = asp
10 TEMPLATE = mason
11
12 ASP_GLOBAL = /usr/local/etc/freeside/asp-global
13 MASON_HANDLER = /usr/local/etc/freeside/handler.pl
14 MASONDATA = /usr/local/etc/freeside/masondata
15
16 #deb
17 FREESIDE_DOCUMENT_ROOT = /var/www/freeside
18 #redhat, fedora, mandrake
19 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
20 #freebsd
21 #FREESIDE_DOCUMENT_ROOT = /usr/local/www/data/freeside
22 #openbsd
23 #FREESIDE_DOCUMENT_ROOT = /var/www/htdocs/freeside
24 #suse
25 #FREESIDE_DOCUMENT_ROOT = /srv/www/htdocs/freeside
26 #apache
27 #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside
28
29 #deb, redhat, fedora, mandrake, suse, others?
30 INIT_FILE = /etc/init.d/freeside
31 #freebsd
32 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
33
34 #deb, suse
35 HTTPD_RESTART = /etc/init.d/apache restart
36 #redhat, fedora, mandrake
37 #HTTPD_RESTART = /etc/init.d/httpd restart
38 #freebsd
39 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop; sleep 1; /usr/local/etc/rc.d/apache.sh start
40 #openbsd
41 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 1; /usr/sbin/httpd -u -DSSL
42 #apache
43 #HTTPD_RESTART = /usr/local/apache/bin/apachectl restart
44
45 FREESIDE_RESTART = ${INIT_FILE} restart
46
47 #deb, redhat, fedora, mandrake, suse, others?
48 INSTALLGROUP = root
49 #freebsd, openbsd
50 #INSTALLGROUP = wheel
51
52 #edit the stuff below to have the daemons start
53
54 QUEUED_USER=fs_queue
55
56 #eventually this shouldn't be needed
57 FREESIDE_PATH = `pwd`
58
59 SELFSERVICE_USER = fs_selfservice
60 # SELFSERVICE_MACHINES = www.example.com
61 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
62
63 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
64 #installation.
65 SELFSERVICE_INSTALL_USER = ivan
66 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
67 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
68
69 #---
70
71 #not changable yet
72 FREESIDE_CONF = /usr/local/etc/freeside
73
74 VERSION=1.4.2beta1
75 TAG=freeside_1_4_2beta1
76
77 help:
78         @echo "supported targets: aspdocs masondocs alldocs docs install-docs"
79         @echo "                   htmlman"
80         @echo "                   perl-modules install-perl-modules"
81         @echo "                   install deploy"
82         @echo "                   create-database"
83         @echo "                   clean"
84
85 aspdocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
86         rm -rf aspdocs
87         cp -pr httemplate aspdocs
88         perl -p -i -e "\
89           s/%%%VERSION%%%/${VERSION}/g;\
90         " aspdocs/index.html
91         touch aspdocs
92
93
94 masondocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
95         rm -rf masondocs
96         cp -pr httemplate masondocs
97         ( cd masondocs; \
98           ../bin/masonize; \
99         )
100         perl -p -i -e "\
101           s/%%%VERSION%%%/${VERSION}/g;\
102         " masondocs/index.html
103         touch masondocs
104
105 alldocs: aspdocs masondocs
106
107 docs:
108         make ${TEMPLATE}docs
109
110 htmlman:
111         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
112         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
113         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
114         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
115         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
116         chmod a+rx bin/pod2x
117         [ -e DONT_REBUILD_DOCS ] || bin/pod2x
118
119 forcehtmlman:
120         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
121         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
122         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
123         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
124         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
125         bin/pod2x
126
127 install-docs: docs
128         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
129         cp -r ${TEMPLATE}docs ${FREESIDE_DOCUMENT_ROOT}
130         [ "${TEMPLATE}" = "asp" -a ! -e ${ASP_GLOBAL} ] && mkdir ${ASP_GLOBAL} || true
131         [ "${TEMPLATE}" = "asp" ] && chown -R freeside ${ASP_GLOBAL} || true
132         [ "${TEMPLATE}" = "asp" ] && cp htetc/global.asa ${ASP_GLOBAL} || true
133         [ "${TEMPLATE}" = "mason" ] && cp htetc/handler.pl ${MASON_HANDLER} || true
134         [ "${TEMPLATE}" = "mason" ] && \
135           perl -p -i -e "\
136             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
137           " ${MASON_HANDLER} || true
138         [ "${TEMPLATE}" = "mason" -a ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
139         [ "${TEMPLATE}" = "mason" ] && chown -R freeside ${MASONDATA} || true
140
141 perl-modules:
142         cd FS; \
143         [ -e Makefile ] || perl Makefile.PL; \
144         make
145
146 install-perl-modules: perl-modules
147         cd FS; \
148         make install UNINST=1
149
150 install-init:
151         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
152         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
153         perl -p -i -e "\
154           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
155           s'%%%FREESIDE_PATH%%%'${FREESIDE_PATH}'g;\
156           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
157           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
158         " ${INIT_FILE}
159
160 install-selfservice:
161         [ -e ~freeside/.ssh/id_dsa.pub ] || su -c 'ssh-keygen -t dsa' - freeside
162         for MACHINE in ${SELFSERVICE_MACHINES}; do \
163           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
164           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
165           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
166           scp ~freeside/.ssh/id_dsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
167           ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -D -o freeside -m 600 ./id_dsa.pub ~freeside/.ssh/authorized_keys" ;\
168            ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
169         done
170
171 install: install-perl-modules install-docs install-init
172
173 deploy: install
174         ${HTTPD_RESTART}
175         ${FREESIDE_RESTART}
176
177 create-database:
178         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
179
180 create-config: install-perl-modules
181         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
182         install -d -o freeside ${FREESIDE_CONF}
183
184         touch ${FREESIDE_CONF}/secrets
185         chown freeside ${FREESIDE_CONF}/secrets
186         chmod 600 ${FREESIDE_CONF}/secrets
187
188         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
189         chmod 600 ${FREESIDE_CONF}/secrets
190         chown freeside ${FREESIDE_CONF}/secrets
191
192         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
193         rm -rf conf/registries #old dirs just won't go away
194         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
195         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
196         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
197
198         mkdir "${FREESIDE_CONF}/counters.${DATASOURCE}"
199         chown freeside "${FREESIDE_CONF}/counters.${DATASOURCE}"
200
201         mkdir "${FREESIDE_CONF}/cache.${DATASOURCE}"
202         chown freeside "${FREESIDE_CONF}/cache.${DATASOURCE}"
203
204         mkdir "${FREESIDE_CONF}/export.${DATASOURCE}"
205         chown freeside "${FREESIDE_CONF}/export.${DATASOURCE}"
206
207 clean:
208         rm -rf aspdocs masondocs
209         cd FS; \
210         make clean
211
212 #these are probably only useful if you're me...
213
214 upload-docs: forcehtmlman
215         ssh pouncequick.420.am rm -rf /var/www/www.sisd.com/freeside/docs
216         scp -pr httemplate/docs pouncequick.420.am:/var/www/www.sisd.com/freeside/docs
217
218 #release: upload-docs update-webdemo
219 release: upload-docs
220         cd /home/ivan/freeside1.4
221         #cvs tag ${TAG}
222         cvs tag -F ${TAG}
223
224         #cd /home/ivan
225         cvs export -r ${TAG} -d freeside-${VERSION} freeside
226         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
227
228         scp freeside-${VERSION}.tar.gz ivan@pouncequick.420.am:/var/www/sisd.420.am/freeside/
229         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
230
231 update-webdemo:
232         ssh ivan@pouncequick.420.am '( cd freeside; cvs update -r FREESIDE_1_4_BRANCH -d -P )'
233         #ssh root@pouncequick.420.am '( cd /home/ivan/freeside; make clean; make deploy )'
234         ssh root@pouncequick.420.am '( cd /home/ivan/freeside; make deploy )'
235