self-service installer?
[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
67 #---
68
69 #not changable yet
70 FREESIDE_CONF = /usr/local/etc/freeside
71
72 VERSION=1.4.2beta1
73 TAG=freeside_1_4_2beta1
74
75 help:
76         @echo "supported targets: aspdocs masondocs alldocs docs install-docs"
77         @echo "                   htmlman"
78         @echo "                   perl-modules install-perl-modules"
79         @echo "                   install deploy"
80         @echo "                   create-database"
81         @echo "                   clean"
82
83 aspdocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
84         rm -rf aspdocs
85         cp -pr httemplate aspdocs
86         perl -p -i -e "\
87           s/%%%VERSION%%%/${VERSION}/g;\
88         " aspdocs/index.html
89         touch aspdocs
90
91
92 masondocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
93         rm -rf masondocs
94         cp -pr httemplate masondocs
95         ( cd masondocs; \
96           ../bin/masonize; \
97         )
98         perl -p -i -e "\
99           s/%%%VERSION%%%/${VERSION}/g;\
100         " masondocs/index.html
101         touch masondocs
102
103 alldocs: aspdocs masondocs
104
105 docs:
106         make ${TEMPLATE}docs
107
108 htmlman:
109         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
110         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
111         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
112         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
113         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
114         chmod a+rx bin/pod2x
115         [ -e DONT_REBUILD_DOCS ] || bin/pod2x
116
117 forcehtmlman:
118         [ -e ./httemplate/docs/man ] || mkdir httemplate/docs/man
119         [ -e ./httemplate/docs/man/bin ] || mkdir httemplate/docs/man/bin
120         [ -e ./httemplate/docs/man/FS ] || mkdir httemplate/docs/man/FS
121         [ -e ./httemplate/docs/man/FS/UI ] || mkdir httemplate/docs/man/FS/UI
122         [ -e ./httemplate/docs/man/FS/part_export ] || mkdir httemplate/docs/man/FS/part_export
123         bin/pod2x
124
125 install-docs: docs
126         [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
127         cp -r ${TEMPLATE}docs ${FREESIDE_DOCUMENT_ROOT}
128         [ "${TEMPLATE}" = "asp" -a ! -e ${ASP_GLOBAL} ] && mkdir ${ASP_GLOBAL} || true
129         [ "${TEMPLATE}" = "asp" ] && chown -R freeside ${ASP_GLOBAL} || true
130         [ "${TEMPLATE}" = "asp" ] && cp htetc/global.asa ${ASP_GLOBAL} || true
131         [ "${TEMPLATE}" = "mason" ] && cp htetc/handler.pl ${MASON_HANDLER} || true
132         [ "${TEMPLATE}" = "mason" ] && \
133           perl -p -i -e "\
134             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
135           " ${MASON_HANDLER} || true
136         [ "${TEMPLATE}" = "mason" -a ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
137         [ "${TEMPLATE}" = "mason" ] && chown -R freeside ${MASONDATA} || true
138
139 perl-modules:
140         cd FS; \
141         [ -e Makefile ] || perl Makefile.PL; \
142         make
143
144 install-perl-modules: perl-modules
145         cd FS; \
146         make install UNINST=1
147
148 install-init:
149         #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
150         install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
151         perl -p -i -e "\
152           s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
153           s'%%%FREESIDE_PATH%%%'${FREESIDE_PATH}'g;\
154           s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
155           s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
156         " ${INIT_FILE}
157
158 install-selfservice:
159         for MACHINE in ${SELFSERVICE_MACHINES}; do \
160           scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@\$MACHINE:.
161           ssh ${SELFSERVICE_INSTALL_USER}@\$MACHINE "cd FS-SelfService; perl Makefile.PL && make"
162           ssh ${SELFSERVICE_INSTALL_USER}@\$MACHINE "cd FS-SelfService; sudo make install"
163
164 install: install-perl-modules install-docs install-init
165
166 deploy: install
167         ${HTTPD_RESTART}
168         ${FREESIDE_RESTART}
169
170 create-database:
171         perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
172
173 create-config: install-perl-modules
174         [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
175         install -d -o freeside ${FREESIDE_CONF}
176
177         touch ${FREESIDE_CONF}/secrets
178         chown freeside ${FREESIDE_CONF}/secrets
179         chmod 600 ${FREESIDE_CONF}/secrets
180
181         echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
182         chmod 600 ${FREESIDE_CONF}/secrets
183         chown freeside ${FREESIDE_CONF}/secrets
184
185         mkdir "${FREESIDE_CONF}/conf.${DATASOURCE}"
186         rm -rf conf/registries #old dirs just won't go away
187         #cp conf/[a-z]* "${FREESIDE_CONF}/conf.${DATASOURCE}"
188         cp `ls -d conf/[a-z]* | grep -v CVS` "${FREESIDE_CONF}/conf.${DATASOURCE}"
189         chown -R freeside "${FREESIDE_CONF}/conf.${DATASOURCE}"
190
191         mkdir "${FREESIDE_CONF}/counters.${DATASOURCE}"
192         chown freeside "${FREESIDE_CONF}/counters.${DATASOURCE}"
193
194         mkdir "${FREESIDE_CONF}/cache.${DATASOURCE}"
195         chown freeside "${FREESIDE_CONF}/cache.${DATASOURCE}"
196
197         mkdir "${FREESIDE_CONF}/export.${DATASOURCE}"
198         chown freeside "${FREESIDE_CONF}/export.${DATASOURCE}"
199
200 clean:
201         rm -rf aspdocs masondocs
202         cd FS; \
203         make clean
204
205 #these are probably only useful if you're me...
206
207 upload-docs: forcehtmlman
208         ssh pouncequick.420.am rm -rf /var/www/www.sisd.com/freeside/docs
209         scp -pr httemplate/docs pouncequick.420.am:/var/www/www.sisd.com/freeside/docs
210
211 #release: upload-docs update-webdemo
212 release: upload-docs
213         cd /home/ivan/freeside1.4
214         #cvs tag ${TAG}
215         cvs tag -F ${TAG}
216
217         #cd /home/ivan
218         cvs export -r ${TAG} -d freeside-${VERSION} freeside
219         tar czvf freeside-${VERSION}.tar.gz freeside-${VERSION}
220
221         scp freeside-${VERSION}.tar.gz ivan@pouncequick.420.am:/var/www/sisd.420.am/freeside/
222         mv freeside-${VERSION} freeside-${VERSION}.tar.gz ..
223
224 update-webdemo:
225         ssh ivan@pouncequick.420.am '( cd freeside; cvs update -r FREESIDE_1_4_BRANCH -d -P )'
226         #ssh root@pouncequick.420.am '( cd /home/ivan/freeside; make clean; make deploy )'
227         ssh root@pouncequick.420.am '( cd /home/ivan/freeside; make deploy )'
228