diff --git a/Makefile b/Makefile index be1b7bfa..c1b310c8 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,20 @@ GWEB_STATEDIR = /var/lib/ganglia-web # Gmetad rootdir (parent location of rrd folder) GMETAD_ROOTDIR = /var/lib/ganglia -APACHE_USER = www-data +#APACHE_USER = www-data +#APACHE_GROUP = www-data ########################################################## +ifndef APACHE_USER +$(info APACHE_USER is not set using www-data) +APACHE_USER = www-data +endif + +ifndef APACHE_GROUP +$(info APACHE_GROUP is not set, using $(APACHE_USER)) +APACHE_GROUP = $(APACHE_USER) +endif + # Gweb version GWEB_VERSION = 3.7.0 @@ -23,56 +34,127 @@ DIST_NAME = ganglia-web DIST_DIR = $(DIST_NAME)-$(GWEB_VERSION) DIST_TARBALL = $(DIST_DIR).tar.gz -TARGETS = conf_default.php ganglia-web.spec version.php apache.conf +# TARGETS: Files that needs to be patched with user chosen variables +TARGETS = conf_default.php conf_redirect.php apache.conf + +# DIST_GZIP_TARGETS targets that needs to be patched once before dist-gzip +# basicaly version and default values. +DIST_GZIP_TARGETS = ganglia-web.spec version.php all: default default: $(TARGETS) clean: - rm -rf $(TARGETS) $(DIST_DIR) $(DIST_TARBALL) rpmbuild + @echo -n "Cleaning build files ............................... " + @rm -rf $(TARGETS) $(DIST_DIR) $(DIST_TARBALL) rpmbuild + @echo "DONE." conf_default.php: conf_default.php.in - sed -e "s|@vargmetadir@|$(GMETAD_ROOTDIR)|" -e "s|@vargwebstatedir@|$(GWEB_STATEDIR)|g" conf_default.php.in > conf_default.php + @echo -n "Generating conf_default.php ........................ " + @sed -e "s|@vargmetadir@|$(GMETAD_ROOTDIR)|" -e "s|@vargwebdir@|$(GWEB_STATEDIR)|g" conf_default.php.in > conf_default.php + @echo "DONE." + +conf_redirect.php: conf_redirect.php.in + @echo -n "Generating conf_redirect.php ....................... " + @sed -e "s|@etcdir@|$(GCONFDIR)|" conf_redirect.php.in > conf_redirect.php + @echo "DONE." ganglia-web.spec: ganglia-web.spec.in - sed -e s/@GWEB_VERSION@/$(GWEB_VERSION)/ -e "s|@vargwebdir@|$(GWEB_STATEDIR)|" -e "s|@varapacheuser@|$(APACHE_USER)|g" -e "s|@etcdir@|$(GCONFDIR)|g" ganglia-web.spec.in > ganglia-web.spec + @echo -n "Generating ganglia-web.spec ........................ " + @sed -e s/@GWEB_VERSION@/$(GWEB_VERSION)/ -e "s|@vargwebdir@|$(GWEB_STATEDIR)|" -e "s|@GDESTDIR@|$(GDESTDIR)|g" -e "s|@etcdir@|$(GCONFDIR)|g" ganglia-web.spec.in > ganglia-web.spec + @echo "DONE." version.php: version.php.in - sed -e s/@GWEB_VERSION@/$(GWEB_VERSION)/ version.php.in > version.php + @echo -n "Generating version.php ............................. " + @sed -e s/@GWEB_VERSION@/$(GWEB_VERSION)/ version.php.in > version.php + @echo "DONE." apache.conf: apache.conf.in - sed -e "s|@GDESTDIR@|$(GDESTDIR)|g" apache.conf.in > apache.conf + @echo -n "Generating apache.conf ............................. " + @sed -e "s|@GDESTDIR@|$(GDESTDIR)|g" apache.conf.in > apache.conf + @echo "DONE." dist-dir: default - rsync --exclude "rpmbuild" --exclude "*.gz" --exclude "Makefile" --exclude "*debian*" --exclude "$(DIST_DIR)" --exclude ".git*" --exclude "*.in" --exclude "*~" --exclude "#*#" --exclude "ganglia-web.spec" --exclude "apache.conf" -a . $(DIST_DIR) - -install: dist-dir - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/compiled && \ - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/cache && \ - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR) && \ - rsync -a $(DIST_DIR)/conf $(DESTDIR)/$(GWEB_STATEDIR) && \ - mkdir -p $(DESTDIR)/$(GDESTDIR) && \ - rsync --exclude "conf" -a $(DIST_DIR)/* $(DESTDIR)/$(GDESTDIR) && \ - chown -R $(APACHE_USER):$(APACHE_USER) $(DESTDIR)/$(GWEB_STATEDIR) - -dist-gzip: dist-dir - if [ -f $(DIST_TARBALL) ]; then \ - rm -rf $(DIST_TARBALL) ;\ - fi ;\ - tar -czf $(DIST_TARBALL) $(DIST_DIR)/* + @echo -n "Filling dist dir ................................... " + @rsync --exclude "rpmbuild" \ + --exclude "debian/ganglia-webfrontend" \ + --exclude "*.gz" \ + --exclude "$(DIST_DIR)" \ + --exclude ".git*" \ + --exclude "version.php.in" \ + --exclude "ganglia-web.spec.in" \ + --exclude "apache.conf" \ + --exclude "conf_default.php" \ + --exclude "*~" \ + --exclude "#*#" \ + -a . $(DIST_DIR) + @echo "DONE." + +install: install-files + @echo -n "Setting ownership to the sharedstattedir files ..... " + @chown -R $(APACHE_USER):$(APACHE_GROUP) $(DESTDIR)/$(GWEB_STATEDIR) + @echo "DONE." + + +install-files: dist-dir + @echo -n "Creating dwoo sharedstattedir tree ................. " + @mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/compiled + @mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/cache + @mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/filters + @echo "DONE." + @echo -n "Installing ganglia-webfrontend low level conf ...... " + @rsync -a $(DIST_DIR)/conf $(DESTDIR)/$(GWEB_STATEDIR) + @echo "DONE." + @echo -n "Installing php files ............................... " + @mkdir -p $(DESTDIR)/$(GDESTDIR) + @rsync --exclude "conf" \ + --exclude conf_redirect.php \ + --exclude "*.in" \ + --exclude "*.spec" \ + -a $(DIST_DIR)/* $(DESTDIR)/$(GDESTDIR) + @echo "DONE." + @echo -n "Intalling redirect conf.php ........................ " + @# so it can be seen as a config file under debian packages. + @# Do the same for all distro to avoid specific case for debian. + @cp -f conf_redirect.php $(DESTDIR)/$(GDESTDIR)/conf.php + @echo "DONE." + @echo -n "Installing the generated conf_default.php file ..... " + @cp -f conf_default.php $(DESTDIR)/$(GDESTDIR)/conf_default.php + @echo "DONE." + @echo -n "Creating the etc/ganglia-webfrontend directory ..... " + @mkdir -p $(DESTDIR)/$(GCONFDIR) + @echo "DONE." + @echo -n "Installing apache.conf ............................. " + @cp -f apache.conf $(DESTDIR)/$(GCONFDIR)/ + @echo "DONE." + @echo -n "Installing the editable copy of conf_default.php ... " + @cp -f conf_default.php $(DESTDIR)/$(GCONFDIR)/conf.php + @echo "DONE." + +dist-gzip: dist-dir $(DIST_GZIP_TARGETS) + @echo -n "Creating tarball ................................... " + @if [ -f $(DIST_TARBALL) ]; then \ + rm -rf $(DIST_TARBALL) ;\ + fi + @cp -pf $(DIST_GZIP_TARGETS) $(DIST_DIR) + @tar -czf $(DIST_TARBALL) $(DIST_DIR)/* + @echo "DONE." rpm: dist-gzip ganglia-web.spec apache.conf - rm -rf rpmbuild - mkdir rpmbuild - mkdir rpmbuild/SOURCES - mkdir rpmbuild/BUILD - mkdir rpmbuild/RPMS - mkdir rpmbuild/SRPMS - cp $(DIST_TARBALL) rpmbuild/SOURCES - cp apache.conf rpmbuild/SOURCES - rpmbuild --define '_topdir $(PWD)/rpmbuild' --define 'custom_web_prefixdir $(GDESTDIR)' -bb ganglia-web.spec + @echo -n "Creating binary rpm ................................ " + @rm -rf rpmbuild + @mkdir rpmbuild + @mkdir rpmbuild/SOURCES + @mkdir rpmbuild/BUILD + @mkdir rpmbuild/RPMS + @mkdir rpmbuild/SRPMS + @ln -s ../../$(DIST_TARBALL) rpmbuild/SOURCES/$(DIST_TARBALL) + @rpmbuild --define '_topdir $(PWD)/rpmbuild' --define 'web_prefixdir $(GDESTDIR)' -bb ganglia-web.spec + @echo "DONE." uninstall: + @echo -n "Uninstalling ganglia-web. (conf files untouched) ... " rm -rf $(DESTDIR)/$(GDESTDIR) $(DESTDIR)/$(GWEB_STATEDIR) + @echo "DONE." diff --git a/conf_default.php.in b/conf_default.php.in index f12186b7..d7baa382 100644 --- a/conf_default.php.in +++ b/conf_default.php.in @@ -10,7 +10,7 @@ # Gmetad-webfrontend version. Used to check for updates. # $conf['gweb_root'] = dirname(__FILE__); -$conf['gweb_confdir'] = "@vargwebstatedir@"; +$conf['gweb_confdir'] = "@vargwebdir@"; include_once $conf['gweb_root'] . "/version.php"; diff --git a/conf_redirect.php.in b/conf_redirect.php.in new file mode 100644 index 00000000..e3908841 --- /dev/null +++ b/conf_redirect.php.in @@ -0,0 +1,5 @@ + diff --git a/debian/apache.conf b/debian/apache.conf deleted file mode 100644 index 88b4c4bf..00000000 --- a/debian/apache.conf +++ /dev/null @@ -1,9 +0,0 @@ -Alias /ganglia /usr/share/ganglia-webfrontend - - - AllowOverride All - Order allow,deny - Allow from all - Deny from none - - diff --git a/debian/conf_debian.php b/debian/conf_debian.php deleted file mode 100644 index a0fdc625..00000000 --- a/debian/conf_debian.php +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/debian/rules b/debian/rules index b9623dc2..c6b619b1 100755 --- a/debian/rules +++ b/debian/rules @@ -26,9 +26,4 @@ override_dh_auto_install: dh_installdirs # Add here commands to install the package into debian/ganglia. $(MAKE) install APACHE_USER=www-data DESTDIR=$(CURDIR)/debian/ganglia-webfrontend - # Install webfrontend - mkdir -p debian/ganglia-webfrontend/etc/apache2/conf.d/ - cp -f debian/apache.conf \ - debian/ganglia-webfrontend/etc/ganglia-webfrontend - cp -f debian/conf_debian.php \ - debian/ganglia-webfrontend/usr/share/ganglia-webfrontend/conf.php + #mkdir -p debian/ganglia-webfrontend/etc/apache2/conf.d/ diff --git a/ganglia-web.spec.in b/ganglia-web.spec.in index 6207ffa8..873df81c 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -1,3 +1,25 @@ + +# The following options are supported: +# --define 'httpd_user ' # defaults to: apache +# --define 'httpd_group ' # defaults to: apache +#  --define 'web_prefixdir ' # defaults to: @GDESTDIR@ +#  --define 'gweb_statedir ' # defaults to: @vargwebdir@ +#  --define 'gweb_confdir ' # defaults to: @etcdir@ + +# example: rpmbuild -tb ganglia-web-3.5.12.tar.gz --define 'httpd_user www-data' --define 'httpd_group www-data' --define 'web_prefixdir /srv/www/ganglia' + +# Default values for Above variables. +%if 0%{?suse_version} +%{!?web_prefixdir: %define web_prefixdir /srv/www/htdocs/ganglia} +%else +%{!?web_prefixdir: %define web_prefixdir /usr/share/ganglia-webfrontend} +%endif + +%{!?httpd_user: %define httpd_user apache} +%{!?httpd_group: %define httpd_group apache} +%{!?gweb_statedir: %define gweb_statedir @vargwebdir@} +%{!?gweb_confdir: %define gweb_confdir @etcdir@} + Summary: Ganglia Web Frontend Name: ganglia-web Version: @GWEB_VERSION@ @@ -7,19 +29,9 @@ License: BSD Vendor: Ganglia Development Team Group: System Environment/Base Source: %{name}-%{version}.tar.gz -Source1: apache.conf Buildroot: %{_tmppath}/%{name}-%{version}-buildroot Obsoletes: ganglia-webfrontend Requires: php >= 5, php-gd -%if 0%{?suse_version} -%define web_prefixdir /srv/www/htdocs/ganglia -%else -%define web_prefixdir %{custom_web_prefixdir} -%endif - -%{!?custom_web_prefixdir: %define web_prefixdir /var/www/html/ganglia} - -Prefix: %{web_prefixdir} BuildArchitectures: noarch %description @@ -28,39 +40,39 @@ ganglia, and to provide historical graphs of collected metrics. This website is written in the PHP5 language and uses the Dwoo templating engine. %prep -%setup -n %{name}-%{version} -%__cp %{SOURCE1} . +%setup -q -n %{name}-%{version} %build +# Update all needed files +%__make GDESTDIR=%{web_prefixdir} \ + APACHE_USER=%{httpd_user} \ + APACHE_GROUP=%{httpd_group} \ + GWEB_STATEDIR=%{gweb_statedir} \ + GCONFDIR=%{gweb_confdir} %install # Flush any old RPM build root %__rm -rf $RPM_BUILD_ROOT -%__mkdir -p $RPM_BUILD_ROOT/%{web_prefixdir} -%__cp -rf * $RPM_BUILD_ROOT/%{web_prefixdir} -%__rm -rf $RPM_BUILD_ROOT/%{web_prefixdir}/conf -%__rm -rf $RPM_BUILD_ROOT/%{web_prefixdir}/apache.conf -%__install -d -m 0755 $RPM_BUILD_ROOT@vargwebdir@/filters -%__install -d -m 0755 $RPM_BUILD_ROOT@vargwebdir@/conf -%__cp -rf conf/* $RPM_BUILD_ROOT@vargwebdir@/conf -%__install -d -m 0755 $RPM_BUILD_ROOT@vargwebdir@/dwoo -%__install -d -m 0755 $RPM_BUILD_ROOT@vargwebdir@/dwoo/compiled -%__install -d -m 0755 $RPM_BUILD_ROOT@vargwebdir@/dwoo/cache -%__install -d -m 0755 $RPM_BUILD_ROOT@etcdir@ -%__cp -f apache.conf $RPM_BUILD_ROOT@etcdir@/ +%__make install-files GDESTDIR=%{web_prefixdir} \ + APACHE_USER=%{httpd_user} \ + APACHE_GROUP=%{httpd_group} \ + GWEB_STATEDIR=%{gweb_statedir} \ + GCONFDIR=%{gweb_confdir} \ + DESTDIR=$RPM_BUILD_ROOT %files %defattr(-,root,root) -%attr(0755,nobody,nobody)@vargwebdir@/filters -%dir %attr(0755,@varapacheuser@,@varapacheuser@)@vargwebdir@/conf -%dir %attr(0755,@varapacheuser@,@varapacheuser@)@vargwebdir@/dwoo -%attr(0755,@varapacheuser@,@varapacheuser@)@vargwebdir@/dwoo/compiled -%attr(0755,@varapacheuser@,@varapacheuser@)@vargwebdir@/dwoo/cache -%{web_prefixdir}/ -%config(noreplace) %{web_prefixdir}/conf_default.php -@vargwebdir@/conf/* -%config(noreplace) @etcdir@/apache.conf +%dir %attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir} +%dir %attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir}/filters +%dir %attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir}/conf +%{gweb_statedir}/conf/* +%dir %attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir}/dwoo +%attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir}/dwoo/compiled +%attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir}/dwoo/cache +%{web_prefixdir}/* +%config(noreplace) %{gweb_confdir}/apache.conf +%config(noreplace) %{gweb_confdir}/conf.php %clean %__rm -rf $RPM_BUILD_ROOT @@ -70,18 +82,23 @@ written in the PHP5 language and uses the Dwoo templating engine. %triggerin -- httpd if [ $1 -eq 1 -a $2 -eq 1 ]; then if [ ! -e /etc/httpd/conf.d/ganglia-web.conf ] ; then - ln -s @etcdir@/apache.conf /etc/httpd/conf.d/ganglia-web.conf + ln -s %{gweb_confdir}/apache.conf /etc/httpd/conf.d/ganglia-web.conf fi fi %triggerun -- httpd if [ $2 -eq 0 ]; then - if [ -h /etc/httpd/conf.d/ganglia-web -a "`readlink /etc/httpd/conf/httpd.conf`" = "@etcdir@/apache.conf" ]; then + if [ -h /etc/httpd/conf.d/ganglia-web -a "`readlink /etc/httpd/conf/httpd.conf`" = "%{gweb_confdir}/apache.conf" ]; then rm /etc/httpd/conf.d/ganglia-web.conf fi fi %changelog +* Fri Feb 28 2014 Olivier Lahaye +- Added the ability to change Makefile variables using --define switch for the + following variables: + httpd_user, httpd_group, web_prefixdir, gweb_confdir, gweb_statedir +- Also fixed a bug that prevented to fix the web_prefixdir on SuSE Linux. * Tue Jun 04 2013 Wesley Hirsch - Added default apache configuration * Thu Mar 17 2011 Bernard Li