more accurate split of files into -webui and -lib packages
[freeside.git] / debian / rules
1 #!/usr/bin/make -f
2 # -*- makefile -*-
3
4 # Uncomment this to turn on verbose mode.
5 #export DH_VERBOSE=1
6
7 # If set to a true value then MakeMaker's prompt function will
8 # always return the default without waiting for user input.
9 #export PERL_MM_USE_DEFAULT=1
10
11 PERL   ?= /usr/bin/perl
12 #PACKAGE = $(shell dh_listpackages)
13 PACKAGE = freeside
14 TMP     = $(CURDIR)/debian/$(PACKAGE)
15 #DBC_SCRIPTS = $(TMP)/usr/share/dbconfig-common/scripts/freeside
16
17 ##this is gotten from dbconfig-common
18 DB_TYPE = Pg
19
20 #Data source
21 DATASOURCE = DBI:${DB_TYPE}:dbname=freeside
22
23 #no chance, it doesn't get backslash-interpolted now...
24 ##DEBVERSION                    = `head -1 debian/changelog | cut -d')' -f1 | cut -c11-`
25 #DEBVERSION                    = 1.7.3~rc2-1
26 #export VERSION                = $(DEBVERSION) (Debian)
27
28 #export FREESIDE_CONF          = /etc/freeside
29 #export FREESIDE_LOG           = /var/log/freeside
30 #export FREESIDE_LOCK          = /var/lock/freeside
31 #export FREESIDE_CACHE         = $(TMP)/var/cache/freeside
32 #FREESIDE_CACHE         = $(TMP)/var/cache/freeside
33
34 #XXX huh?
35 #export FREESIDE_EXPORT        = /var/spool/freeside
36
37 export FREESIDE_CONF = $(TMP)/usr/local/etc/freeside
38 export FREESIDE_LOG = $(TMP)/usr/local/etc/freeside
39 export FREESIDE_LOCK = $(TMP)/usr/local/etc/freeside
40 export FREESIDE_CACHE = $(TMP)/usr/local/etc/freeside
41 export FREESIDE_EXPORT = $(TMP)/usr/local/etc/freeside
42
43 export DIST_CONF = ${FREESIDE_CONF}/default_conf
44
45 #XXX own subdir?
46 #export MASON_HANDLER          = /usr/share/freeside/handler.pl
47 export MASON_HANDLER=$(TMP)-webui/usr/local/etc/freeside/handler.pl
48
49 export APACHE_VERSION        := $(shell /usr/sbin/apache2 -v | grep -q '\/2\.4\.' && echo '2.4' || echo '2')
50 export APACHE_DOCUMENT_ROOT  := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo '/var/www/html' || echo '/var/www')
51 export FREESIDE_DOCUMENT_ROOT = $(TMP)-webui$(APACHE_DOCUMENT_ROOT)/freeside
52 export INIT_FILE              = $(TMP).init
53 export INIT_INSTALL           = /bin/true
54 export HTTPD_RESTART          = /bin/true
55 export APACHE_CONF           := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo "$(TMP)-webui/etc/apache2/conf-available" || echo "$(TMP)-webui/etc/apache2/conf.d")
56 export TORRUS_CONF           := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo "$(TMP)-torrus/etc/apache2/conf-available" || echo "$(TMP)-torrus/etc/apache2/conf.d")
57 export FREESIDE_RESTART       = /bin/true
58
59 #XXX root?
60 export INSTALLGROUP           = adm
61
62 export SELFSERVICE_MACHINES   = 
63
64 #prompt ?   XXX these are runtime, not buildtime :/
65 export RT_DOMAIN              =  freeside.biz
66 export RT_TIMEZONE            = US/Eastern
67 export HOSTNAME               = localhost
68 export FREESIDE_URL           = http://$(HOSTNAME)/freeside/
69
70 #specific to deb pkg, for purposes of saving off a permanent copy of default
71 #config for postinst and that sort of thing
72 #export DIST_CONF           = /usr/share/freeside/default_conf
73
74 #XXX yuck.  proper RT layout is entirely necessary
75 #this seems to infect way to much of RT with the build location, requiring
76 # a kludge to hack it out afterwords.  look into using fakeroot (didn't
77 # realize it would need to be explicit argh)
78 # (but leaving it for now, otherwise can't get RT to put files where we need em)
79 export RT_PATH                = $(TMP)-lib/opt/rt3
80
81 export TEXMF_PATH             = $(TMP)-lib/usr/local/share/texmf/tex/latex
82
83 # This has to be exported to make some magic below work.
84 export DH_OPTIONS
85
86 configure: configure-stamp
87 configure-stamp:
88         dh_testdir
89         # Add here commands to configure the package.
90         
91         touch configure-stamp
92
93
94 build: build-stamp
95 build-stamp: 
96         dh_testdir
97         # Add commands to compile the package here
98         
99         ( cd FS/ && $(PERL) Makefile.PL INSTALLDIRS=vendor && $(MAKE) )
100         $(MAKE) perl-modules
101         
102         ( cd fs_selfservice/FS-SelfService/ && $(PERL) Makefile.PL && $(MAKE) )
103         
104         #install this for freeside-setup
105         install -d $(DIST_CONF)
106         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
107
108         #TEST#
109
110         touch $@
111
112 clean:
113         dh_testdir
114         dh_testroot
115         dh_clean build-stamp install-stamp
116
117         # Add here commands to clean up after the build process.
118         $(MAKE) -e clean
119         #|| true #XXX freeside clean target fucked
120
121         dh_clean 
122
123 install: install-stamp
124 install-stamp: build-stamp
125         dh_testdir
126         dh_testroot
127         dh_clean -k
128         dh_installdirs
129
130         # Add here commands to install package into
131         # debian/<package>-whatever.
132
133         install -d $(FREESIDE_DOCUMENT_ROOT)
134         install -d $(TMP)-webui/usr/local/etc/freeside/
135         install -d $(TMP)-webui/etc/insserv/overrides/
136         install -d $(TMP)/usr/local/etc/freeside/
137         install -d $(TMP)-webui/masondata #MASONDATA
138 #       install -d $(TMP)-lib/usr/bin
139
140         ( cd FS/ && $(MAKE) -e DESTDIR=${TMP}-lib install)
141
142         # Install configuration files
143         install -d -o freeside ${FREESIDE_CONF}
144
145         touch ${FREESIDE_CONF}/secrets
146         chown freeside ${FREESIDE_CONF}/secrets
147         chmod 600 ${FREESIDE_CONF}/secrets
148
149         /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
150         chmod 600 ${FREESIDE_CONF}/secrets
151         chown freeside ${FREESIDE_CONF}/secrets
152
153         mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
154         chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
155
156         mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
157         chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
158
159         mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
160         chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
161
162         #install this for freeside-setup
163         install -d $(DIST_CONF)
164         #install conf/[a-z]* $(DEFAULT_CONF)
165         #CVS is not [a-z]
166         install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
167
168         # Install interfaces
169         $(MAKE) -e DESTDIR=$(TMP)-webui install-docs
170         
171         # Install tex
172         install -d ${TEXMF_PATH}
173         install -o freeside -m 444 etc/*.sty ${TEXMF_PATH}
174
175         # Create Apache configurations
176         install -d $(APACHE_CONF)
177         $(MAKE) -e DESTDIR=$(APACHE_CONF) install-apache
178         install -o root -m 755 init.d/insserv-override-apache2 $(TMP)-webui/etc/insserv/overrides/apache2
179
180         #Hack the build dir out of apache config
181
182         perl -p -i -e "\
183          s'${TMP}(-webui)?''g;\
184         " $(APACHE_CONF)/*
185
186         # Install init
187         $(MAKE) -e DESTDIR=$(TMP) install-init
188
189         #hack the build dir out of Freeside too.  oh yeah, sucky.
190         perl -p -i -e "\
191           s'${TMP}(-webui)?''g;\
192         " ${TMP}/usr/local/etc/freeside/handler.pl \
193           ${TMP}/usr/share/perl5/FS/* \
194           ${TMP}/usr/share/perl5/FS/*/* \
195           ${TMP}/usr/bin/*
196
197         #hack the build dur out of lib
198         perl -p -i -e "\
199           s'${TMP}-lib?''g;\
200           s'${TMP}(-webui)?''g;\
201         " ${TMP}/usr/local/etc/freeside/handler.pl \
202           ${TMP}-lib/usr/share/perl5/FS/*.pm \
203           ${TMP}-lib/usr/share/perl5/FS/*/*.pm 
204         
205         #hack the build dir out of Freeside binaries
206
207         perl -p -i -e "\
208           s'${TMP}?''g;\
209         " ${TMP}-lib/usr/bin/* \
210           ${TMP}-webui/usr/local/etc/freeside/handler.pl
211
212         # Self-service
213         
214         ( cd fs_selfservice/FS-SelfService/; $(MAKE) -e DESTDIR=${TMP}-selfservice-lib install ) 
215         install -d -o freeside -g freeside ${TMP}-selfservice-lib/usr/local/freeside
216         touch ${TMP}-selfservice-lib/usr/local/freeside/selfservice_socket 
217         chown -R freeside ${TMP}-selfservice-lib/usr/local/freeside
218         chmod 600 ${TMP}-selfservice-lib/usr/local/freeside/selfservice_socket
219         
220         install -d -o freeside -g freeside ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/
221         cp -R fs_selfservice/FS-SelfService/cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST
222         chown freeside.freeside ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*.cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*/*.cgi;
223         chmod 755 ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*.cgi ${TMP}-selfservice-ui$(APACHE_DOCUMENT_ROOT)/selfservice-DIST/*/*.cgi
224
225         # NG-selfservice
226
227         install -d ${TMP}-ng-selfservice$(APACHE_DOCUMENT_ROOT)/
228         cp -R ng_selfservice ${TMP}-ng-selfservice$(APACHE_DOCUMENT_ROOT)/ng_selfservice-DIST/
229
230         # Torrus 
231         
232         install -d ${TORRUS_CONF}
233         install -o root -m 755 htetc/freeside-torrus.conf $(TORRUS_CONF)/
234
235         ( cd torrus; \
236         torrus_user=freeside var_user=freeside var_group=freeside ./configure; \
237         $(MAKE) -e DESTDIR=${TMP}-torrus/; \
238         $(MAKE) -e DESTDIR=${TMP}-torrus/ install; \
239         perl -p -i -e "\
240             s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
241         " ${TMP}-torrus/usr/local/etc/torrus/conf/torrus-siteconfig.pl )
242
243         #RT Config
244
245         ( cd rt; \
246           cp config.layout.in config.layout; \
247           perl -p -i -e "\
248             s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
249             s'%%%MASONDATA%%%'${FREESIDE_CACHE}/masondata'g;\
250           " config.layout; \
251           ./configure --prefix=${RT_PATH} \
252                 --enable-layout=Freeside \
253                 --with-db-type=Pg \
254                 --with-db-dba=freeside \
255                 --with-db-database=freeside \
256                 --with-db-rt-user=freeside \
257                 --with-db-rt-pass="" \
258                 --with-web-user=freeside \
259                 --with-web-group=freeside \
260                 --with-rt-group=freeside \
261                 --with-web-handler=modperl2 )
262
263         ##(create-rt)
264         #$(MAKE) -e DESTDIR=${TMP}-lib create-rt
265         install -d $(RT_PATH)
266         install -d $(RT_PATH)/share
267
268         ( cd rt; $(MAKE) config-install dirs files-install fixperms instruct )
269         cp -r ${RT_PATH}/share/static/images ${FREESIDE_DOCUMENT_ROOT}/rt/NoAuth/
270         
271         ##hack the build dir out of RT.  yeah, sucky.
272
273         perl -p -i -e "\
274         s'${TMP}(-webui|-lib)''g;\
275         s'${TMP}''g;\
276         " ${TMP}-lib/opt/rt3/etc/*.pm \
277                 ${TMP}-lib/opt/rt3/lib/*.pm \
278                 ${TMP}-lib/opt/rt3/lib/RT/*.pm \
279                 ${TMP}-lib/opt/rt3/etc/upgrade/* \
280                 ${TMP}-lib/opt/rt3/sbin/* \
281                 ${TMP}-lib/opt/rt3/bin/* \
282
283         # Default RT Settings
284         perl -p -i -e "\
285                 s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
286                 s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
287                 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
288                 " ${RT_PATH}/etc/RT_SiteConfig.pm
289
290         dh_install
291
292         #touch $@
293
294 binary-arch:
295 # We have nothing to do here for an architecture-independent package
296
297 binary-indep: build install
298         dh_testdir
299         dh_testroot
300         dh_installdeb install
301         dh_installdocs #freeside.docs README AGPL
302         dh_installexamples eg/* bin/*
303 #       dh_installmenu
304         dh_installdebconf       
305 #       dh_installlogrotate     
306         dh_installinit --no-start 
307         dh_installcron
308 #       dh_installinfo
309         dh_installman
310         dh_perl
311         dh_link
312         dh_compress 
313         dh_fixperms -X/var/www/selfservice-DIST -X/usr/local/freeside
314         dh_gencontrol
315         dh_md5sums
316         dh_builddeb
317
318 binary: binary-indep binary-arch
319 .PHONY: build clean binary-indep binary-arch binary install