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