From 68b0ffff95a267964f36efc8ac0a5d31ff33cf6e Mon Sep 17 00:00:00 2001 From: olahaye74 Date: Fri, 28 Feb 2014 11:43:39 +0100 Subject: [PATCH 1/5] Source1 not needed. apache.conf already in current directory. No need to %__cp %SOURCE1 as well. More over, using more than one source prevent a build from tarball using rpmbuild -tb ganglia-web-3.5.12.tar.gz for instance. --- ganglia-web.spec.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/ganglia-web.spec.in b/ganglia-web.spec.in index 6207ffa8..380d5114 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -7,7 +7,6 @@ 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 @@ -29,7 +28,6 @@ written in the PHP5 language and uses the Dwoo templating engine. %prep %setup -n %{name}-%{version} -%__cp %{SOURCE1} . %build From c20d87874c30eebef32f5649cc5dc180995680c9 Mon Sep 17 00:00:00 2001 From: olahaye74 Date: Fri, 28 Feb 2014 23:50:45 +0100 Subject: [PATCH 2/5] [build & packaging] Reworked the install and packaging so it results in the same installation whatever the build is (manual, deb pkg or rpm pkg) - Use Makefile to make install for deb and rpm as well including config files. - Include specfile in the dist-gzip so a rpmbuild -tb (tarbuild) can be used - Added customization for rpmbuild using --with tags (see spec file for usage and more details). - Use adequate default values for rpm. The apache_user is not www-data. it's apache... - Use /etc/ganglia-webfrontend to store conf.php what ever the distro is. Make sure that a link is set to apache config dir using triggers or postinstall. - Use /etc/ganglia-webfrontend to store conf.php what ever the distro is. Use a generic conf.php in /usr/share/ganglia-webfrontend to load the file from /etc/ganglia-webfrontend. - Replaced vargwebstatedir with vargwebdir in conf_default.php.in and Makefile. - filters dir was not created under debian pkg or manual make install - Added possibility to have a httpd_group different from user. For instance you can choose to install files under apache.daemon identity. If not specified, a group with the same name as the user is used. - Added comment in the install section of the Makefile so it's clear. - Reworked dist-gzip target so version.php and spec file are generated while other .in files remain so they can be tuned by make or make install. - Make sure that sharedstatedir is not owned by rpm package (conflict on fc-18+), and updated %file section accordingly. - Removed the manual install and specific config files in debian packaging. Using standard make install DESTDIR=... --- Makefile | 83 +++++++++++++++++++++++++------- conf_default.php.in | 2 +- conf_redirect.php.in | 5 ++ debian/apache.conf | 9 ---- debian/conf_debian.php | 5 -- debian/rules | 7 +-- ganglia-web.spec.in | 106 ++++++++++++++++++++++++++++------------- 7 files changed, 147 insertions(+), 70 deletions(-) create mode 100644 conf_redirect.php.in delete mode 100644 debian/apache.conf delete mode 100644 debian/conf_debian.php diff --git a/Makefile b/Makefile index 4a8d46b7..cf3f3209 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 +$(warning APACHE_USER is not set using www-data) +APACHE_USER = www-data +endif + +ifndef APACHE_GROUP +$(warning APACHE_GROUP is not set, using $(APACHE_USER)) +APACHE_GROUP = $(APACHE_USER) +endif + # Gweb version GWEB_MAJOR_VERSION = 3 GWEB_MINOR_VERSION = 5 @@ -27,7 +38,12 @@ 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 @@ -37,10 +53,13 @@ clean: rm -rf $(TARGETS) $(DIST_DIR) $(DIST_TARBALL) rpmbuild 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 + sed -e "s|@vargmetadir@|$(GMETAD_ROOTDIR)|" -e "s|@vargwebdir@|$(GWEB_STATEDIR)|g" conf_default.php.in > conf_default.php + +conf_redirect.php: conf_redirect.php.in + sed -e "s|@etcdir@|$(GCONFDIR)|" conf_redirect.php.in > conf_redirect.php 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 + 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 version.php: version.php.in sed -e s/@GWEB_VERSION@/$(GWEB_VERSION)/ version.php.in > version.php @@ -49,21 +68,52 @@ apache.conf: apache.conf.in sed -e "s|@GDESTDIR@|$(GDESTDIR)|g" apache.conf.in > apache.conf 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) + 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) 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 + # Create dwoo sharedstattedir tree + mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/compiled + mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/cache + mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/filters + # Install ganglia-webfrontend low level conf + rsync -a $(DIST_DIR)/conf $(DESTDIR)/$(GWEB_STATEDIR) + # Set apache daemon ownership to the sharedstattedir files. + chown -R $(APACHE_USER):$(APACHE_GROUP) $(DESTDIR)/$(GWEB_STATEDIR) + # Install php files + mkdir -p $(DESTDIR)/$(GDESTDIR) + rsync --exclude "conf" \ + --exclude conf_redirect.php \ + --exclude "*.in" \ + --exclude "*.spec" \ + -a $(DIST_DIR)/* $(DESTDIR)/$(GDESTDIR) + # Intall file that redirect conf.php to /etc/ganglia-webfrontend + # 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 + # Install the generated conf_default.php file. + cp -f conf_default.php $(DESTDIR)/$(GDESTDIR)/conf_default.php + # Create the /etc/ganglia-webfrontend directory. + mkdir -p $(DESTDIR)/$(GCONFDIR) + cp -f apache.conf $(DESTDIR)/$(GCONFDIR)/ + # Install the editable copy of conf_default.php + cp -f conf_default.php $(DESTDIR)/$(GCONFDIR)/conf.php + +dist-gzip: dist-dir $(DIST_GZIP_TARGETS) if [ -f $(DIST_TARBALL) ]; then \ rm -rf $(DIST_TARBALL) ;\ fi ;\ + cp -pf $(DIST_GZIP_TARGETS) $(DIST_DIR) tar -czf $(DIST_TARBALL) $(DIST_DIR)/* rpm: dist-gzip ganglia-web.spec apache.conf @@ -73,9 +123,8 @@ rpm: dist-gzip ganglia-web.spec apache.conf 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 + ln -s $(DIST_TARBALL) rpmbuild/SOURCES + rpmbuild --define '_topdir $(PWD)/rpmbuild' --with web_prefixdir=$(GDESTDIR) -bb ganglia-web.spec uninstall: rm -rf $(DESTDIR)/$(GDESTDIR) $(DESTDIR)/$(GWEB_STATEDIR) diff --git a/conf_default.php.in b/conf_default.php.in index 68e3c134..7cb575cc 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 380d5114..6d1f0527 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -1,3 +1,33 @@ + +# The following options are supported: +# --with httpd_user= # defaults to: apache +# --with httpd_group= # defaults to: apache +#  --with web_prefixdir= # defaults to: @GDESTDIR@ +#  --with gweb_statedir= # defaults to: @vargwebdir@ +#  --with gweb_confdir= # defaults to: @etcdir@ + +# example: rpmbuild -tb ganglia-web-3.5.12.tar.gz --with httpd_user=www-data --with httpd_group=www-data --with web_prefixdir=/srv/www/ganglia + +# Default value for web_prefixdir depending on distro. +%if 0%{?suse_version} +%define web_prefixdir /srv/www/htdocs/ganglia +%else +%define web_prefixdir @GDESTDIR@ +%endif + +# Default value for httpd user and group. +%define httpd_user apache +%define httpd_group apache +%define gweb_statedir @vargwebdir@ +%define gweb_confdir @etcdir@ + +# Read the provided --with tags if any (overriding default values). +%{?_with_httpd_user:%define httpd_user %(set -- %{_with_httpd_user}; echo $1 | grep -v with | sed 's/=//')} +%{?_with_httpd_group:%define httpd_group %(set -- %{_with_httpd_group}; echo $1 | grep -v with | sed 's/=//')} +%{?_with_web_prefixdir:%define web_prefixdir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} +%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} +%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} + Summary: Ganglia Web Frontend Name: ganglia-web Version: @GWEB_VERSION@ @@ -10,15 +40,6 @@ Source: %{name}-%{version}.tar.gz 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 @@ -30,35 +51,49 @@ written in the PHP5 language and uses the Dwoo templating engine. %setup -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 GDESTDIR=%{web_prefixdir} \ + APACHE_USER=%{httpd_user} \ + APACHE_GROUP=%{httpd_group} \ + GWEB_STATEDIR=%{gweb_statedir} \ + GCONFDIR=%{gweb_confdir} \ + DESTDIR=$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@/ %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 @@ -68,18 +103,25 @@ 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 --with switch for the + following variables: + httpd_user, httpd_group, web_prefixdir, gweb_confdir, gweb_statedir +- Reworked the web_prefixdir setup from the rpmbuild command line. Moved from + --define '%custom_web_prefixdir ' to --with web_prefixdir= + 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 From 3e6bbc0cfced6013eb115a3c706e4ce6eb0bf10d Mon Sep 17 00:00:00 2001 From: olahaye74 Date: Wed, 5 Mar 2014 19:33:11 +0100 Subject: [PATCH 3/5] Fix --with values unwanted dashes conversion to underscores. --- ganglia-web.spec.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ganglia-web.spec.in b/ganglia-web.spec.in index 6d1f0527..8f32e415 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -22,11 +22,11 @@ %define gweb_confdir @etcdir@ # Read the provided --with tags if any (overriding default values). -%{?_with_httpd_user:%define httpd_user %(set -- %{_with_httpd_user}; echo $1 | grep -v with | sed 's/=//')} -%{?_with_httpd_group:%define httpd_group %(set -- %{_with_httpd_group}; echo $1 | grep -v with | sed 's/=//')} -%{?_with_web_prefixdir:%define web_prefixdir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} -%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} -%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_web_prefixdir}; echo $1 | grep -v with | sed 's/=//')} +%{?_with_httpd_user:%define httpd_user %(set -- %{_with_httpd_user}; echo $2 | cut -d= -f2)} +%{?_with_httpd_group:%define httpd_group %(set -- %{_with_httpd_group}; echo $2 | cut -d= -f2)} +%{?_with_web_prefixdir:%define web_prefixdir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} +%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} +%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} Summary: Ganglia Web Frontend Name: ganglia-web From 576664243839878f00961d38dc8616e6c49813b6 Mon Sep 17 00:00:00 2001 From: olahaye74 Date: Wed, 5 Mar 2014 19:41:15 +0100 Subject: [PATCH 4/5] fix a stupid copy-past error from me. --- ganglia-web.spec.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ganglia-web.spec.in b/ganglia-web.spec.in index 8f32e415..e55bae53 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -25,8 +25,8 @@ %{?_with_httpd_user:%define httpd_user %(set -- %{_with_httpd_user}; echo $2 | cut -d= -f2)} %{?_with_httpd_group:%define httpd_group %(set -- %{_with_httpd_group}; echo $2 | cut -d= -f2)} %{?_with_web_prefixdir:%define web_prefixdir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} -%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} -%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} +%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_gweb_statedir}; echo $2 | cut -d= -f2)} +%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_gweb_confdir}; echo $2 | cut -d= -f2)} Summary: Ganglia Web Frontend Name: ganglia-web From 316e2e132bf8af250fed6400c71cde6d21ea0362 Mon Sep 17 00:00:00 2001 From: olahaye74 Date: Tue, 22 Jul 2014 14:28:39 +0200 Subject: [PATCH 5/5] [Makefile + rpm spec file] Make Makefile more smart and more verbose, adapted specfile for this. Now Makefile has a rule that install files without setting ownership. this permit to build an rpm without being root. using --define magro for specfile tunning. --- Makefile | 125 ++++++++++++++++++++++++++++---------------- ganglia-web.spec.in | 57 ++++++-------------- 2 files changed, 96 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index ab172f2f..c1b310c8 100644 --- a/Makefile +++ b/Makefile @@ -18,12 +18,12 @@ GMETAD_ROOTDIR = /var/lib/ganglia ########################################################## ifndef APACHE_USER -$(warning APACHE_USER is not set using www-data) +$(info APACHE_USER is not set using www-data) APACHE_USER = www-data endif ifndef APACHE_GROUP -$(warning APACHE_GROUP is not set, using $(APACHE_USER)) +$(info APACHE_GROUP is not set, using $(APACHE_USER)) APACHE_GROUP = $(APACHE_USER) endif @@ -46,25 +46,38 @@ 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|@vargwebdir@|$(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 - sed -e "s|@etcdir@|$(GCONFDIR)|" conf_redirect.php.in > conf_redirect.php + @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|@GDESTDIR@|$(GDESTDIR)|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" \ + @echo -n "Filling dist dir ................................... " + @rsync --exclude "rpmbuild" \ --exclude "debian/ganglia-webfrontend" \ --exclude "*.gz" \ --exclude "$(DIST_DIR)" \ @@ -76,52 +89,72 @@ dist-dir: default --exclude "*~" \ --exclude "#*#" \ -a . $(DIST_DIR) - -install: dist-dir - # Create dwoo sharedstattedir tree - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/compiled - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/dwoo/cache - mkdir -p $(DESTDIR)/$(GWEB_STATEDIR)/filters - # Install ganglia-webfrontend low level conf - rsync -a $(DIST_DIR)/conf $(DESTDIR)/$(GWEB_STATEDIR) - # Set apache daemon ownership to the sharedstattedir files. - chown -R $(APACHE_USER):$(APACHE_GROUP) $(DESTDIR)/$(GWEB_STATEDIR) - # Install php files - mkdir -p $(DESTDIR)/$(GDESTDIR) - rsync --exclude "conf" \ + @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) - # Intall file that redirect conf.php to /etc/ganglia-webfrontend - # 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 - # Install the generated conf_default.php file. - cp -f conf_default.php $(DESTDIR)/$(GDESTDIR)/conf_default.php - # Create the /etc/ganglia-webfrontend directory. - mkdir -p $(DESTDIR)/$(GCONFDIR) - cp -f apache.conf $(DESTDIR)/$(GCONFDIR)/ - # Install the editable copy of conf_default.php - cp -f conf_default.php $(DESTDIR)/$(GCONFDIR)/conf.php + @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) - if [ -f $(DIST_TARBALL) ]; then \ - rm -rf $(DIST_TARBALL) ;\ - fi ;\ - cp -pf $(DIST_GZIP_TARGETS) $(DIST_DIR) - tar -czf $(DIST_TARBALL) $(DIST_DIR)/* + @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 - ln -s $(DIST_TARBALL) rpmbuild/SOURCES - rpmbuild --define '_topdir $(PWD)/rpmbuild' --with 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/ganglia-web.spec.in b/ganglia-web.spec.in index e55bae53..873df81c 100644 --- a/ganglia-web.spec.in +++ b/ganglia-web.spec.in @@ -1,32 +1,24 @@ # The following options are supported: -# --with httpd_user= # defaults to: apache -# --with httpd_group= # defaults to: apache -#  --with web_prefixdir= # defaults to: @GDESTDIR@ -#  --with gweb_statedir= # defaults to: @vargwebdir@ -#  --with gweb_confdir= # defaults to: @etcdir@ +# --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 --with httpd_user=www-data --with httpd_group=www-data --with web_prefixdir=/srv/www/ganglia +# 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 value for web_prefixdir depending on distro. +# Default values for Above variables. %if 0%{?suse_version} -%define web_prefixdir /srv/www/htdocs/ganglia +%{!?web_prefixdir: %define web_prefixdir /srv/www/htdocs/ganglia} %else -%define web_prefixdir @GDESTDIR@ +%{!?web_prefixdir: %define web_prefixdir /usr/share/ganglia-webfrontend} %endif -# Default value for httpd user and group. -%define httpd_user apache -%define httpd_group apache -%define gweb_statedir @vargwebdir@ -%define gweb_confdir @etcdir@ - -# Read the provided --with tags if any (overriding default values). -%{?_with_httpd_user:%define httpd_user %(set -- %{_with_httpd_user}; echo $2 | cut -d= -f2)} -%{?_with_httpd_group:%define httpd_group %(set -- %{_with_httpd_group}; echo $2 | cut -d= -f2)} -%{?_with_web_prefixdir:%define web_prefixdir %(set -- %{_with_web_prefixdir}; echo $2 | cut -d= -f2)} -%{?_with_gweb_statedir:%define gweb_statedir %(set -- %{_with_gweb_statedir}; echo $2 | cut -d= -f2)} -%{?_with_gweb_confdir:%define gweb_confdir %(set -- %{_with_gweb_confdir}; echo $2 | cut -d= -f2)} +%{!?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 @@ -48,7 +40,7 @@ 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} +%setup -q -n %{name}-%{version} %build # Update all needed files @@ -62,26 +54,13 @@ written in the PHP5 language and uses the Dwoo templating engine. # Flush any old RPM build root %__rm -rf $RPM_BUILD_ROOT -%__make install GDESTDIR=%{web_prefixdir} \ +%__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 -#%__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@/ - %files %defattr(-,root,root) %dir %attr(0755,%{httpd_user},%{httpd_group})%{gweb_statedir} @@ -116,12 +95,10 @@ fi %changelog * Fri Feb 28 2014 Olivier Lahaye -- Added the ability to change Makefile variables using --with switch for the +- Added the ability to change Makefile variables using --define switch for the following variables: httpd_user, httpd_group, web_prefixdir, gweb_confdir, gweb_statedir -- Reworked the web_prefixdir setup from the rpmbuild command line. Moved from - --define '%custom_web_prefixdir ' to --with web_prefixdir= - Also fixed a bug that prevented to fix the web_prefixdir on SuSE Linux. +- 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