3 #solaris and perhaps other very weirdass /bin/sh
12 DATASOURCE = DBI:${DB_TYPE}:dbname=freeside
14 #changable now (some things which should go to the others still go to CONF)
15 FREESIDE_CONF = /usr/local/etc/freeside
16 FREESIDE_LOG = /usr/local/etc/freeside
17 FREESIDE_LOCK = /usr/local/etc/freeside
18 FREESIDE_CACHE = /usr/local/etc/freeside
19 FREESIDE_EXPORT = /usr/local/etc/freeside
21 MASON_HANDLER = ${FREESIDE_CONF}/handler.pl
22 MASONDATA = ${FREESIDE_CACHE}/masondata
24 #where to put the default configuraiton used by freeside-setup to initialize
25 #a new database (not used after that). primarily of interest to distro
27 DIST_CONF = ${FREESIDE_CONF}/default_conf
29 #mod_perl v2 1.999_22 on Apache 2.0 through 2.3 (Debian ancient through 7.x)
31 #Apache 2.4 (Debian 8.x)
33 APACHE_VERSION := $(shell /usr/sbin/apache2 -v | grep -q '\/2\.4\.' && echo '2.4' || echo '2')
35 #deb (-7 and upgrades)
36 #FREESIDE_DOCUMENT_ROOT = /var/www/freeside
37 #deb (new installs of 8+) (plus needs more work w/new auth)
38 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
39 FREESIDE_DOCUMENT_ROOT := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo '/var/www/html/freeside' || echo '/var/www/freeside')
41 #redhat, fedora, mandrake
42 #FREESIDE_DOCUMENT_ROOT = /var/www/html/freeside
44 #FREESIDE_DOCUMENT_ROOT = /usr/local/www/data/freeside
46 #FREESIDE_DOCUMENT_ROOT = /var/www/htdocs/freeside
48 #FREESIDE_DOCUMENT_ROOT = /srv/www/htdocs/freeside
50 #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside
52 POD2HTML_DIR = ${FREESIDE_DOCUMENT_ROOT}/docs/library
54 #deb, redhat, fedora, mandrake, suse, others?
55 INIT_FILE = /etc/init.d/freeside
57 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
60 INIT_INSTALL = PATH=${PATH}:/sbin /usr/sbin/update-rc.d freeside defaults 23 01
62 #INIT_INSTALL = /sbin/chkconfig freeside on
63 #not necessary (freebsd)
64 #INIT_INSTALL = /usr/bin/true
67 #HTTPD_RESTART = /etc/init.d/apache restart
69 HTTPD_RESTART = /etc/init.d/apache2 restart
70 #redhat, fedora, mandrake
71 #HTTPD_RESTART = /etc/init.d/httpd restart
73 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop || true; sleep 10; /usr/local/etc/rc.d/apache.sh start
75 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 10; /usr/sbin/httpd -u -DSSL
77 #HTTPD_RESTART = /usr/local/apache/bin/apachectl stop; sleep 10; /usr/local/apache/bin/apachectl startssl
79 #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf)
81 #APACHE_CONF = /etc/apache2/conf.d
82 #debian unstable/8.0+, apache2.4
83 #APACHE_CONF = /etc/apache2/conf-available
84 APACHE_CONF := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo '/etc/apache2/conf-available' || echo '/etc/apache2/conf.d')
86 INSSERV_OVERRIDE = /etc/insserv/overrides
88 FREESIDE_RESTART = ${INIT_FILE} restart
90 #deb, redhat, fedora, mandrake, suse, others?
95 #edit the stuff below to have the daemons start
100 SELFSERVICE_USER = fs_selfservice
101 #never run on the same machine in production!!!
102 SELFSERVICE_MACHINES =
103 # SELFSERVICE_MACHINES = www.example.com
104 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
106 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
108 SELFSERVICE_INSTALL_USER = ivan
109 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
110 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
114 RT_DOMAIN = example.com
115 RT_TIMEZONE = US/Pacific
116 #RT_TIMEZONE = US/Eastern
117 FREESIDE_URL = "http://localhost/freeside/"
119 #for now, same db as specified in DATASOURCE... eventually, otherwise?
120 RT_DB_DATABASE = freeside
124 # for auto-version updates, so we can "make release" more things automatically
125 RPM_SPECFILE = rpm/freeside.spec
132 #only used for dev kludge now, not a big deal
133 FREESIDE_PATH = `pwd`
134 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.24.1/
136 VERSION := `grep '^$$VERSION' FS/FS.pm | cut -d\' -f2`
137 TAG := freeside_`grep '^$$VERSION' FS/FS.pm | cut -d\' -f2 | perl -pe 's/\./_/g'`
139 #DEBVERSION = `echo ${VERSION} | perl -pe 's/(\d)([a-z])/\1~\2/'`-1
141 TEXMFHOME := "\$$TEXMFHOME"
150 @echo "supported targets:"
151 @echo " create-database create-config"
152 @echo " install deploy"
153 @echo " configure-rt create-rt"
156 @echo " install-docs install-perl-modules"
157 @echo " install-init install-apache"
158 @echo " install-rt install-texmf"
159 @echo " install-selfservice update-selfservice"
161 @echo " dev dev-docs dev-perl-modules"
163 @echo " masondocs alldocs docs"
165 @echo " perl-modules"
167 #@echo " upload-docs release"
170 masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
172 cp -pr httemplate masondocs
181 chmod a+rx ./bin/pod2x
185 #ancient attempt to avoid overwriting customer modifications directly to production web files that's overlived its usefulness
186 #[ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
187 #cp -r masondocs ${FREESIDE_DOCUMENT_ROOT}
188 [ -h ${FREESIDE_DOCUMENT_ROOT} ] && rm ${FREESIDE_DOCUMENT_ROOT} || true
189 mkdir -p ${FREESIDE_DOCUMENT_ROOT}
190 cp -r masondocs/* masondocs/.htaccess ${FREESIDE_DOCUMENT_ROOT}
191 chown -R freeside:freeside ${FREESIDE_DOCUMENT_ROOT}
192 install -D htetc/handler.pl ${MASON_HANDLER}
194 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
195 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
196 " ${MASON_HANDLER} || true
197 mkdir -p ${FREESIDE_EXPORT}/profile
198 chown freeside ${FREESIDE_EXPORT}/profile
199 rm -rf ${MASONDATA}/*
200 mkdir ${MASONDATA}/cache || true
201 mkdir ${MASONDATA}/obj || true
202 chown -f -R freeside ${MASONDATA} || true
205 [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
206 ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
207 cp htetc/handler.pl ${MASON_HANDLER}
209 s'###use Module::Refresh;###'use Module::Refresh;'; \
210 s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
211 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
212 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
213 " ${MASON_HANDLER} || true
217 [ -e Makefile ] || perl Makefile.PL; \
220 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
221 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
222 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
223 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
224 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
225 s'%%%RT_PATH%%%'${RT_PATH}'g; \
226 s'%%%MASONDATA%%%'${MASONDATA}'g;\
227 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
230 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
231 s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
232 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
233 " blib/lib/FS/Cron/*.pm;\
235 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
236 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
237 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
238 " blib/lib/FS/part_export/*.pm;\
240 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
241 " blib/lib/FS/cust_main/*.pm blib/lib/FS/cust_pkg/*.pm blib/lib/FS/contact/*.pm;\
243 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
244 " blib/lib/FS/Daemon/*.pm;\
246 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
247 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
248 s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
249 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
250 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
251 s|%%%DIST_CONF%%%|${DIST_CONF}|g;\
254 install-perl-modules: perl-modules install-rt-initialdata
255 [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
256 && rm ${PERL_INC_DEV_KLUDGE}/FS \
257 && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
260 make install UNINST=1
261 #install this for freeside-setup
262 install -d $(DIST_CONF)
263 #install conf/[a-z]* $(DEFAULT_CONF)
265 install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
267 dev-perl-modules: perl-modules
268 [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
269 && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
272 rm -rf ${PERL_INC_DEV_KLUDGE}/FS
273 ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
276 mkdir -p /usr/local/share/texmf/tex/latex
277 install -D -o freeside -m 444 etc/*.sty \
278 /usr/local/share/texmf/tex/latex/
279 texhash /usr/local/share/texmf
282 #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
283 install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
285 s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
286 s/%%%API_USER%%%/${API_USER}/g;\
287 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
288 s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
293 [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
294 [ -d ${APACHE_CONF} ] && \
295 ( install -o root -m 755 htetc/freeside-base${APACHE_VERSION}.conf ${APACHE_CONF} && \
296 ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
297 ( [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-torrus.conf ${APACHE_CONF} || true ) && \
299 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
300 s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
301 s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
302 " ${APACHE_CONF}/freeside-*.conf \
304 [ -d ${APACHE_CONF} ] && [ -x /usr/sbin/a2enconf ] && ( /usr/sbin/a2enconf freeside-base${APACHE_VERSION} ) || true
305 [ -d ${APACHE_CONF} ] && [ ${APACHE_VERSION} = '2.4' ] && [ -x /usr/sbin/a2disconf ] && ( /usr/sbin/a2disconf freeside-base2 ) || true
306 [ -d ${APACHE_CONF} ] && [ -x /usr/sbin/a2enconf ] && [ ${RT_ENABLED} -eq 1 ] && ( /usr/sbin/a2enconf freeside-rt ) || true
307 [ -d ${INSSERV_OVERRIDE} ] && [ -x /sbin/insserv ] && ( install -o root -m 755 init.d/insserv-override-apache2 ${INSSERV_OVERRIDE}/apache2 && insserv -d ) || true
310 [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
311 [ -e ~freeside/.ssh/id_rsa.pub ] || su - freeside -c 'ssh-keygen'
312 for MACHINE in ${SELFSERVICE_MACHINES}; do \
313 scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
314 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
315 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
316 scp ~freeside/.ssh/id_rsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
317 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo ${SELFSERVICE_INSTALL_USERADD} freeside; sudo install -d -o freeside -m 755 ~freeside/.ssh/; sudo install -o freeside -m 600 ./id_rsa.pub ~freeside/.ssh/authorized_keys" ;\
318 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
322 for MACHINE in ${SELFSERVICE_MACHINES}; do \
323 RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
324 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; make clean; perl Makefile.PL && make" ;\
325 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
329 chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
330 chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
331 chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
334 echo "${POD2HTML_DIR}"
335 mkdir -p "${POD2HTML_DIR}"
336 perl -IFS -MFS::Misc::Pod2Html -e "FS::Misc::Pod2Html::fs_pod2html_from_src('${POD2HTML_DIR}');"
337 chown freeside:freeside -R "${POD2HTML_DIR}"
339 install: install-perl-modules install-docs install-init install-apache install-rt install-torrus install-texmf install-chown install-pod2html
345 dev: dev-perl-modules dev-docs
348 perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
350 create-config: install-perl-modules
351 [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
352 install -d -o freeside ${FREESIDE_CONF}
354 touch ${FREESIDE_CONF}/secrets
355 chown freeside ${FREESIDE_CONF}/secrets
356 chmod 600 ${FREESIDE_CONF}/secrets
358 /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
359 chmod 600 ${FREESIDE_CONF}/secrets
360 chown freeside ${FREESIDE_CONF}/secrets
362 mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
363 chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
365 mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
366 chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
368 mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
369 chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
371 #install this for freeside-setup
372 install -d $(DIST_CONF)
373 #install conf/[a-z]* $(DEFAULT_CONF)
375 install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
380 cp config.layout.in config.layout; \
382 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
383 s'%%%MASONDATA%%%'${MASONDATA}'g;\
385 ./configure --enable-layout=Freeside\
386 --with-db-type=${DB_TYPE} \
387 --with-db-dba=${DB_USER} \
388 --with-db-database=${RT_DB_DATABASE} \
389 --with-db-rt-user=${DB_USER} \
390 --with-db-rt-pass="${DB_PASSWORD}" \
391 --with-web-user=freeside \
392 --with-web-group=freeside \
393 --with-rt-group=freeside \
394 --with-web-handler=modperl2
396 create-rt: configure-rt
397 [ -d /opt ] || mkdir /opt #doh
398 [ -d /opt/rt3 ] || mkdir /opt/rt3 #
399 [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
401 rt/sbin/rt-setup-database --dba '${DB_USER}' \
402 --dba-password '${DB_PASSWORD}' \
405 rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
407 && rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
409 --datafile ${RT_PATH}/etc/initialdata \
413 if [ ${RT_ENABLED} -eq 1 ]; then ( cd rt; make install ); fi
414 if [ ${RT_ENABLED} -eq 1 ]; then cp -r rt/share/static/images ${FREESIDE_DOCUMENT_ROOT}/rt/NoAuth/ ;fi
415 if [ ${RT_ENABLED} -eq 1 ]; then perl -p -i -e "\
416 s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
417 s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
418 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
419 " ${RT_PATH}/etc/RT_SiteConfig.pm; fi
420 if [ ${RT_ENABLED} -eq 1 ]; then \
421 chown -R freeside:freeside ${RT_PATH}/etc; fi
423 install-rt-initialdata:
424 if [ ${RT_ENABLED} -eq 1 ] && [ -d ${RT_PATH} ]; then \
425 chown -R freeside:freeside ${RT_PATH}/etc; \
426 install -D -o freeside -g freeside -m 0440 rt/etc/initialdata \
427 ${RT_PATH}/etc/initialdata; fi
431 torrus_user=freeside var_user=freeside var_group=freeside ./configure
434 if [ ${TORRUS_ENABLED} -eq 1 ]; then ( cd torrus; \
438 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
439 " /usr/local/etc/torrus/conf/torrus-siteconfig.pl; \
445 rm -rf httemplate/docs/man
450 -cd fs_selfservice/FS-SelfService; \
453 #these are probably only useful if you're me...
455 #release: upload-docs
458 # Update the changelog
460 #cvs commit -m "Updated for ${VERSION}" ChangeLog
462 # Update the RPM specfile
463 #cvs edit ${RPM_SPECFILE}
464 #perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
465 #perl -p -i -e "s/\d+[^\}]+/1/ if /%define\s+release\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
466 #cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
468 # Update the Debian changelog
469 #cvs edit debian/changelog
470 #dch -v ${DEBVERSION} -p "New upstream release"
471 #cvs commit -m "Updated for ${VERSION}" debian/changelog
473 # Make sure other people's changes are pulled in!
480 git archive --prefix=freeside-${VERSION}/ ${TAG} | gzip -9 >freeside-${VERSION}.tar.gz
482 scp freeside-${VERSION}.tar.gz ivan@freeside.biz:/var/www/www.freeside.biz/freeside/
483 mv freeside-${VERSION}.tar.gz ..
485 #these things failing should not make release target fail, so: "|| true"
487 #kick off vmware update
488 #./BUILD_VMWARE_APPLIANCE ${$TAG} || true
490 #kick off deb package update
492 #kick off rpm package update too?
496 #update web demo self-service?