Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked the install and packaging so it results in the same installation whatever the build is (manual, deb pkg or rpm pkg) #231

Merged
merged 7 commits into from
Aug 23, 2014
146 changes: 114 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,148 @@ 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

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."

2 changes: 1 addition & 1 deletion conf_default.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
5 changes: 5 additions & 0 deletions conf_redirect.php.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
if( file_exists( "@etcdir@/conf.php" ) ) {
include_once "@etcdir@/conf.php";
}
?>
9 changes: 0 additions & 9 deletions debian/apache.conf

This file was deleted.

5 changes: 0 additions & 5 deletions debian/conf_debian.php

This file was deleted.

7 changes: 1 addition & 6 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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/
87 changes: 52 additions & 35 deletions ganglia-web.spec.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@

# The following options are supported:
# --define 'httpd_user <username>' # defaults to: apache
# --define 'httpd_group <group>' # defaults to: apache
#  --define 'web_prefixdir <path>' # defaults to: @GDESTDIR@
#  --define 'gweb_statedir <path>' # defaults to: @vargwebdir@
#  --define 'gweb_confdir <path>' # 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@
Expand All @@ -7,19 +29,9 @@ License: BSD
Vendor: Ganglia Development Team <ganglia-developers@lists.sourceforge.net>
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
Expand All @@ -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
Expand All @@ -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 <olivier.lahaye@cea.fr>
- 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 <emperorshishire@gmail.com>
- Added default apache configuration
* Thu Mar 17 2011 Bernard Li <bernard@vanhpc.org>
Expand Down