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 #deb, redhat, fedora, mandrake, suse, others?
53 INIT_FILE = /etc/init.d/freeside
55 #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh
58 INIT_INSTALL = PATH=${PATH}:/sbin /usr/sbin/update-rc.d freeside defaults 23 01
60 #INIT_INSTALL = /sbin/chkconfig freeside on
61 #not necessary (freebsd)
62 #INIT_INSTALL = /usr/bin/true
65 #HTTPD_RESTART = /etc/init.d/apache restart
67 HTTPD_RESTART = /etc/init.d/apache2 restart
68 #redhat, fedora, mandrake
69 #HTTPD_RESTART = /etc/init.d/httpd restart
71 #HTTPD_RESTART = /usr/local/etc/rc.d/apache.sh stop || true; sleep 10; /usr/local/etc/rc.d/apache.sh start
73 #HTTPD_RESTART = kill -TERM `cat /var/www/logs/httpd.pid`; sleep 10; /usr/sbin/httpd -u -DSSL
75 #HTTPD_RESTART = /usr/local/apache/bin/apachectl stop; sleep 10; /usr/local/apache/bin/apachectl startssl
77 #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf)
79 #APACHE_CONF = /etc/apache2/conf.d
80 #debian unstable/8.0+, apache2.4
81 #APACHE_CONF = /etc/apache2/conf-available
82 APACHE_CONF := $(shell [ ${APACHE_VERSION} = '2.4' ] && echo '/etc/apache2/conf-available' || echo '/etc/apache2/conf.d')
84 INSSERV_OVERRIDE = /etc/insserv/overrides
86 FREESIDE_RESTART = ${INIT_FILE} restart
88 #deb, redhat, fedora, mandrake, suse, others?
93 #edit the stuff below to have the daemons start
98 SELFSERVICE_USER = fs_selfservice
99 #never run on the same machine in production!!!
100 SELFSERVICE_MACHINES =
101 # SELFSERVICE_MACHINES = www.example.com
102 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
104 #user with sudo access on SELFSERVICE_MACHINES for automated self-service
106 SELFSERVICE_INSTALL_USER = ivan
107 SELFSERVICE_INSTALL_USERADD = /usr/sbin/useradd
108 #SELFSERVICE_INSTALL_USERADD = "/usr/sbin/pw useradd"
112 RT_DOMAIN = example.com
113 RT_TIMEZONE = US/Pacific
114 #RT_TIMEZONE = US/Eastern
115 FREESIDE_URL = "http://localhost/freeside/"
117 #for now, same db as specified in DATASOURCE... eventually, otherwise?
118 RT_DB_DATABASE = freeside
122 # for auto-version updates, so we can "make release" more things automatically
123 RPM_SPECFILE = rpm/freeside.spec
130 #only used for dev kludge now, not a big deal
131 FREESIDE_PATH = `pwd`
132 PERL_INC_DEV_KLUDGE = /usr/local/share/perl/5.14.2/
134 VERSION := `grep '^$$VERSION' FS/FS.pm | cut -d\' -f2`
135 TAG := freeside_`grep '^$$VERSION' FS/FS.pm | cut -d\' -f2 | perl -pe 's/\./_/g'`
137 #DEBVERSION = `echo ${VERSION} | perl -pe 's/(\d)([a-z])/\1~\2/'`-1
139 TEXMFHOME := "\$$TEXMFHOME"
148 @echo "supported targets:"
149 @echo " create-database create-config"
150 @echo " install deploy"
151 @echo " configure-rt create-rt"
154 @echo " install-docs install-perl-modules"
155 @echo " install-init install-apache"
156 @echo " install-rt install-texmf"
157 @echo " install-selfservice update-selfservice"
159 @echo " dev dev-docs dev-perl-modules"
161 @echo " masondocs alldocs docs"
163 @echo " perl-modules"
165 #@echo " upload-docs release"
168 masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
170 cp -pr httemplate masondocs
179 chmod a+rx ./bin/pod2x
183 #ancient attempt to avoid overwriting customer modifications directly to production web files that's overlived its usefulness
184 #[ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
185 #cp -r masondocs ${FREESIDE_DOCUMENT_ROOT}
186 [ -h ${FREESIDE_DOCUMENT_ROOT} ] && rm ${FREESIDE_DOCUMENT_ROOT} || true
187 mkdir -p ${FREESIDE_DOCUMENT_ROOT}
188 cp -r masondocs/* masondocs/.htaccess ${FREESIDE_DOCUMENT_ROOT}
189 chown -R freeside:freeside ${FREESIDE_DOCUMENT_ROOT}
190 install -D htetc/handler.pl ${MASON_HANDLER}
192 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
193 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
194 " ${MASON_HANDLER} || true
195 mkdir -p ${FREESIDE_EXPORT}/profile
196 chown freeside ${FREESIDE_EXPORT}/profile
197 cp htetc/htpasswd.logout ${FREESIDE_CONF}
200 chown -R freeside ${MASONDATA}
203 [ -e ${FREESIDE_DOCUMENT_ROOT} ] && mv ${FREESIDE_DOCUMENT_ROOT} ${FREESIDE_DOCUMENT_ROOT}.`date +%Y%m%d%H%M%S` || true
204 ln -s ${FREESIDE_PATH}/httemplate ${FREESIDE_DOCUMENT_ROOT}
205 cp htetc/handler.pl ${MASON_HANDLER}
207 s'###use Module::Refresh;###'use Module::Refresh;'; \
208 s'###Module::Refresh->refresh;###'Module::Refresh->refresh;'; \
209 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
210 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
211 " ${MASON_HANDLER} || true
215 [ -e Makefile ] || perl Makefile.PL; \
218 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
219 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
220 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
221 s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
222 s'%%%RT_PATH%%%'${RT_PATH}'g; \
223 s'%%%MASONDATA%%%'${MASONDATA}'g;\
224 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
227 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
228 s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
229 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
230 " blib/lib/FS/Cron/*.pm;\
232 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
233 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
234 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
235 " blib/lib/FS/part_export/*.pm;\
237 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
238 " blib/lib/FS/cust_main/*.pm blib/lib/FS/cust_pkg/*.pm;\
240 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
241 " blib/lib/FS/Daemon/*.pm;\
243 s|%%%FREESIDE_CONF%%%|${FREESIDE_CONF}|g;\
244 s|%%%FREESIDE_LOG%%%|${FREESIDE_LOG}|g;\
245 s|%%%FREESIDE_LOCK%%%|${FREESIDE_LOCK}|g;\
246 s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
247 s|%%%FREESIDE_EXPORT%%%|${FREESIDE_EXPORT}|g;\
248 s|%%%DIST_CONF%%%|${DIST_CONF}|g;\
251 install-perl-modules: perl-modules install-rt-initialdata
252 [ -L ${PERL_INC_DEV_KLUDGE}/FS ] \
253 && rm ${PERL_INC_DEV_KLUDGE}/FS \
254 && mv ${PERL_INC_DEV_KLUDGE}/FS.old ${PERL_INC_DEV_KLUDGE}/FS \
257 make install UNINST=1
258 #install this for freeside-setup
259 install -d $(DIST_CONF)
260 #install conf/[a-z]* $(DEFAULT_CONF)
262 install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
264 dev-perl-modules: perl-modules
265 [ -d ${PERL_INC_DEV_KLUDGE}/FS -a ! -L ${PERL_INC_DEV_KLUDGE}/FS ] \
266 && mv ${PERL_INC_DEV_KLUDGE}/FS ${PERL_INC_DEV_KLUDGE}/FS.old \
269 rm -rf ${PERL_INC_DEV_KLUDGE}/FS
270 ln -sf ${FREESIDE_PATH}/FS/blib/lib/FS ${PERL_INC_DEV_KLUDGE}/FS
273 install -D -o freeside -m 444 etc/*.sty \
274 /usr/local/share/texmf/tex/latex/
275 texhash /usr/local/share/texmf
278 #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
279 install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE}
281 s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\
282 s/%%%API_USER%%%/${API_USER}/g;\
283 s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\
284 s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
289 [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true
290 [ -d ${APACHE_CONF} ] && \
291 ( install -o root -m 755 htetc/freeside-base2.conf ${APACHE_CONF} && \
292 ( [ ${RT_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-rt.conf ${APACHE_CONF} || true ) && \
293 ( [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -m 755 htetc/freeside-torrus.conf ${APACHE_CONF} || true ) && \
295 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
296 s'%%%FREESIDE_CONF%%%'${FREESIDE_CONF}'g; \
297 s'%%%MASON_HANDLER%%%'${MASON_HANDLER}'g; \
298 " ${APACHE_CONF}/freeside-*.conf \
300 [ -d ${APACHE_CONF} ] && [ -x /usr/sbin/a2enconf ] && ( /usr/sbin/a2enconf freeside-base${APACHE_VERSION} ) || true
301 [ -d ${APACHE_CONF} ] && [ ${APACHE_VERSION} = '2.4' ] && [ -x /usr/sbin/a2disconf ] && ( /usr/sbin/a2disconf freeside-base2 ) || true
302 [ -d ${APACHE_CONF} ] && [ -x /usr/sbin/a2enconf ] && [ ${RT_ENABLED} -eq 1 ] && ( /usr/sbin/a2enconf freeside-rt ) || true
303 [ -d ${INSSERV_OVERRIDE} ] && [ -x /sbin/insserv ] && ( install -o root -m 755 init.d/insserv-override-apache2 ${INSSERV_OVERRIDE}/apache2 && insserv -d ) || true
306 [ -e ~freeside ] || cp -pr /etc/skel ~freeside && chown -R freeside ~freeside
307 [ -e ~freeside/.ssh/id_rsa.pub ] || su - freeside -c 'ssh-keygen'
308 for MACHINE in ${SELFSERVICE_MACHINES}; do \
309 scp -r fs_selfservice/FS-SelfService ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
310 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; perl Makefile.PL && make" ;\
311 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
312 scp ~freeside/.ssh/id_rsa.pub ${SELFSERVICE_INSTALL_USER}@$$MACHINE:. ;\
313 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" ;\
314 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "sudo install -o freeside -d /usr/local/freeside" ;\
318 for MACHINE in ${SELFSERVICE_MACHINES}; do \
319 RSYNC_RSH=ssh rsync -rlptz fs_selfservice/FS-SelfService/ ${SELFSERVICE_INSTALL_USER}@$$MACHINE:FS-SelfService ;\
320 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; make clean; perl Makefile.PL && make" ;\
321 ssh ${SELFSERVICE_INSTALL_USER}@$$MACHINE "cd FS-SelfService; sudo make install" ;\
325 chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
326 chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
327 chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
329 install: install-perl-modules install-docs install-init install-apache install-rt install-torrus install-texmf install-chown
335 dev: dev-perl-modules dev-docs
338 perl -e 'use DBIx::DataSource qw( create_database ); create_database( "${DATASOURCE}", "${DB_USER}", "${DB_PASSWORD}" ) or die $$DBIx::DataSource::errstr;'
340 create-config: install-perl-modules
341 [ -e ${FREESIDE_CONF} ] && mv ${FREESIDE_CONF} ${FREESIDE_CONF}.`date +%Y%m%d%H%M%S` || true
342 install -d -o freeside ${FREESIDE_CONF}
344 touch ${FREESIDE_CONF}/secrets
345 chown freeside ${FREESIDE_CONF}/secrets
346 chmod 600 ${FREESIDE_CONF}/secrets
348 /bin/echo -e "${DATASOURCE}\n${DB_USER}\n${DB_PASSWORD}" >${FREESIDE_CONF}/secrets
349 chmod 600 ${FREESIDE_CONF}/secrets
350 chown freeside ${FREESIDE_CONF}/secrets
352 mkdir "${FREESIDE_CACHE}/counters.${DATASOURCE}"
353 chown freeside "${FREESIDE_CACHE}/counters.${DATASOURCE}"
355 mkdir "${FREESIDE_CACHE}/cache.${DATASOURCE}"
356 chown freeside "${FREESIDE_CACHE}/cache.${DATASOURCE}"
358 mkdir "${FREESIDE_EXPORT}/export.${DATASOURCE}"
359 chown freeside "${FREESIDE_EXPORT}/export.${DATASOURCE}"
361 #install this for freeside-setup
362 install -d $(DIST_CONF)
363 #install conf/[a-z]* $(DEFAULT_CONF)
365 install `ls -d conf/[a-z]* | grep -v CVS | grep -v '^conf/registries'` $(DIST_CONF)
370 cp config.layout.in config.layout; \
372 s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
373 s'%%%MASONDATA%%%'${MASONDATA}'g;\
375 ./configure --enable-layout=Freeside\
376 --with-db-type=${DB_TYPE} \
377 --with-db-dba=${DB_USER} \
378 --with-db-database=${RT_DB_DATABASE} \
379 --with-db-rt-user=${DB_USER} \
380 --with-db-rt-pass="${DB_PASSWORD}" \
381 --with-web-user=freeside \
382 --with-web-group=freeside \
383 --with-rt-group=freeside \
384 --with-web-handler=modperl2
386 create-rt: configure-rt
387 [ -d /opt ] || mkdir /opt #doh
388 [ -d /opt/rt3 ] || mkdir /opt/rt3 #
389 [ -d /opt/rt3/share ] || mkdir /opt/rt3/share #
391 rt/sbin/rt-setup-database --dba '${DB_USER}' \
392 --dba-password '${DB_PASSWORD}' \
395 rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
397 && rt/sbin/rt-setup-database --dba-password '${DB_PASSWORD}' \
399 --datafile ${RT_PATH}/etc/initialdata \
403 if [ ${RT_ENABLED} -eq 1 ]; then ( cd rt; make install ); fi
404 if [ ${RT_ENABLED} -eq 1 ]; then cp -r rt/share/static/images ${FREESIDE_DOCUMENT_ROOT}/rt/NoAuth/ ;fi
405 if [ ${RT_ENABLED} -eq 1 ]; then perl -p -i -e "\
406 s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
407 s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
408 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
409 " ${RT_PATH}/etc/RT_SiteConfig.pm; fi
410 if [ ${RT_ENABLED} -eq 1 ]; then \
411 chown -R freeside:freeside ${RT_PATH}/etc; fi
413 install-rt-initialdata:
414 if [ ${RT_ENABLED} -eq 1 ] && [ -d ${RT_PATH} ]; then \
415 chown -R freeside:freeside ${RT_PATH}/etc; \
416 install -D -o freeside -g freeside -m 0440 rt/etc/initialdata \
417 ${RT_PATH}/etc/initialdata; fi
421 torrus_user=freeside var_user=freeside var_group=freeside ./configure
424 if [ ${TORRUS_ENABLED} -eq 1 ]; then ( cd torrus; \
428 s'%%%FREESIDE_URL%%%'${FREESIDE_URL}'g;\
429 " /usr/local/etc/torrus/conf/torrus-siteconfig.pl; \
435 rm -rf httemplate/docs/man
440 -cd fs_selfservice/FS-SelfService; \
443 #these are probably only useful if you're me...
445 #release: upload-docs
448 # Update the changelog
450 #cvs commit -m "Updated for ${VERSION}" ChangeLog
452 # Update the RPM specfile
453 #cvs edit ${RPM_SPECFILE}
454 #perl -p -i -e "s/\d+[^\}]+/${VERSION}/ if /%define\s+version\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
455 #perl -p -i -e "s/\d+[^\}]+/1/ if /%define\s+release\s+(\d+[^\}]+)\}/;" ${RPM_SPECFILE}
456 #cvs commit -m "Updated for ${VERSION}" ${RPM_SPECFILE}
458 # Update the Debian changelog
459 #cvs edit debian/changelog
460 #dch -v ${DEBVERSION} -p "New upstream release"
461 #cvs commit -m "Updated for ${VERSION}" debian/changelog
463 # Make sure other people's changes are pulled in!
470 git archive --prefix=freeside-${VERSION}/ ${TAG} | gzip -9 >freeside-${VERSION}.tar.gz
472 scp freeside-${VERSION}.tar.gz ivan@freeside.biz:/var/www/www.freeside.biz/freeside/
473 mv freeside-${VERSION}.tar.gz ..
475 #these things failing should not make release target fail, so: "|| true"
477 #kick off vmware update
478 #./BUILD_VMWARE_APPLIANCE ${$TAG} || true
480 #kick off deb package update
482 #kick off rpm package update too?
486 #update web demo self-service?