Index: branches/1.0/Makefile
===================================================================
--- branches/1.0/Makefile	(revision 840)
+++ branches/1.0/Makefile	(revision 841)
@@ -2,14 +2,22 @@
 #
 TMPDIR = /tmp
-DESTDIR = /usr/local
+
+# Where to install
+DESTDIR = 
+
+# Install prefix
+PREFIX = /usr/local
+
+# What is the location of the Ganglia web frontend
+# i.e.: where to we install Job Monarch's web frontend addon
+# 
+GANGLIA_ROOT = $(PREFIX)/ganglia
+
+# Where jobarchived RRDS are stored
+JOBARCHIVE_RRDS = $(PREFIX)/jobmonarch
 
 # Clear this if you don't want to use ${FAKEROOT}
 #
 FAKEROOT = fakeroot
-
-# What is the location of the Ganglia web frontend
-# i.e.: where to we install Job Monarch's web frontend addon
-# 
-WEBDIR = /var/www/ganglia
 
 VERSION = 1.0
@@ -25,5 +33,5 @@
 tarball:	tarball-gzip tarball-bzip
 
-tarball-gzip:	${REQUIRED} rpmspec
+tarball-gzip:	${REQUIRED} ./pkg/rpm/jobmonarch.spec
 	mkdir -p ${TMPDIR}/.monarch_buildroot/ganglia_jobmonarch-${VERSION}
 	( rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php \
@@ -32,5 +40,5 @@
 	mv ${TMPDIR}/.monarch_buildroot/ganglia_jobmonarch-${VERSION}.tar.gz ..
 
-tarball-bzip:	${REQUIRED} rpmspec
+tarball-bzip:	${REQUIRED} ./pkg/rpm/jobmonarch.spec
 	mkdir -p ${TMPDIR}/.monarch_buildroot/ganglia_jobmonarch-${VERSION}
 	( rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php \
@@ -39,9 +47,11 @@
 	mv ${TMPDIR}/.monarch_buildroot/ganglia_jobmonarch-${VERSION}.tar.bz2 ..
 
-rpmspec: pkg/rpm/jobmonarch.spec.in
-	sed -e 's/__VERSION__/$(VERSION)/g' -e 's/__RELEASE__/$(RELEASE)/g' ./pkg/rpm/jobmonarch.spec.in > jobmonarch.spec
+rpmspec: ./pkg/rpm/jobmonarch.spec
 
-debpkgdir: pkg/deb/debian
-	rsync -a --exclude=.svn pkg/deb/debian debian
+./pkg/rpm/jobmonarch.spec: pkg/rpm/jobmonarch.spec.in
+	sed -e 's/__VERSION__/$(VERSION)/g' -e 's/__RELEASE__/$(RELEASE)/g' ./pkg/rpm/jobmonarch.spec.in > ./pkg/rpm/jobmonarch.spec
+
+debian: pkg/deb/debian
+	rsync -a --exclude=.svn pkg/deb/debian ./
 	sed -i -e 's/^Version:.*$//Version: $(VERSION)-$(RELEASE)/g' ./debian/control
 
@@ -49,16 +59,33 @@
 	rpmbuild -tb ../ganglia_jobmonarch-${VERSION}.tar.bz2
 
-deb: debpkgdir
+deb: debian
 	dpkg-buildpackage -b
 
 install:
-	# Files in SBIN_DIR
-	install -m 0755 -d $(DESTDIR)/usr/sbin
-	install -m 0755 jobmond/jobmond.py $(DESTDIR)/usr/sbin/
-	install -m 0755 jobarchived/jobarchived.py $(DESTDIR)/usr/sbin/
-	(cd $(DESTDIR)/usr/sbin/; ln -s jobmond.py jobmond; ln -s jobarchived.py jobarchived)
-	#
-	# Files specific to distros if /etc/sysconfig => rpm else (/etc/default => debian)
-	if test -d /etc/sysconfig; then \
+	@#
+	@# Set the correct GANGLIA_PATH.
+	@#
+	@echo "\nUsing $(GANGLIA_ROOT) as Ganglia root installation path. If it's not what"
+	@echo "you want, use make GANGLIA_ROOT=/path/to/your/ganglia/root ."
+	@sed -i -e 's|/var/www/ganglia/|$(GANGLIA_ROOT)/|g' web/addons/job_monarch/conf.php
+	@#
+	@# Set the correct JOBARCHIVE_RRDS in jobarchve.conf and ganglia conf.php
+	@#
+	@echo "\nUsing $(JOBARCHIVE_RRDS) as jobarchive path to  store rrds files. If it's not what"
+	@echo "you want, use make JOBARCHIVE_RRDS=/path/to/you/jobarchived/rrdsfiles ."
+	@sed -i -e 's|/var/lib/jobarchive|$(JOBARCHIVE_RRDS)|g' jobarchived/jobarchived.conf web/addons/job_monarch/conf.php
+	@#
+	@# Files in SBIN_DIR
+	@#
+	@echo "\nInstalling jobmond.py and jobarchived.py to $(PREFIX)/sbin"
+	@install -m 0755 -d $(DESTDIR)$(PREFIX)/sbin
+	@install -m 0755 jobmond/jobmond.py $(DESTDIR)$(PREFIX)/sbin/
+	@install -m 0755 jobarchived/jobarchived.py $(DESTDIR)$(PREFIX)/sbin/
+	@(cd $(DESTDIR)$(PREFIX)/sbin/; ln -s jobmond.py jobmond; ln -s jobarchived.py jobarchived)
+	@#
+	@# Files specific to distros if /etc/sysconfig => rpm else (/etc/default => debian)
+	@#
+	@echo "\nInstalling service files in $(DESTDIR)/etc"
+	@if test -d /etc/sysconfig; then \
 		install -m 0755 -d $(DESTDIR)/etc/rc.d/init.d; \
 		install -m 0755 pkg/rpm/init.d/jobmond $(DESTDIR)/etc/rc.d/init.d/; \
@@ -75,38 +102,35 @@
 		install -m 0755 pkg/deb/default/jobarchived $(DESTDIR)/etc/default; \
 	fi
-	#
-	# Files in /etc
-	#
-	install -m 0644 jobmond/jobmond.conf $(DESTDIR)/etc; \
-	install -m 0644 jobarchived/jobarchived.conf $(DESTDIR)/etc; \
-	#
-	# Files in /usr/share
-	#
-	install -m 0755 -d $(DESTDIR)/usr/share/jobarchived/
-	install -m 0755 jobarchived/job_dbase.sql $(DESTDIR)/usr/share/jobarchived/
-	#
-	# Create the /var/lib/jobarchive directory where rrds are stored.
-	#
-	install -m 0755 -d $(DESTDIR)/var/lib/jobarchive/
-	#
-	# Files for ganglia (adapt to rpm or deb or unknown ganglia packaging)
-	#
-	if test -d /etc/sysconfig; then \
-		install -m 0755 -d $(DESTDIR)/usr/share/ganglia; \
-		(cd web; rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php . $(DESTDIR)/usr/share/ganglia); \
-	elif test -d /etc/default; then \
-		install -m 0755 -d $(DESTDIR)/usr/share/ganglia-webfrontend; \
-		(cd web; rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php . $(DESTDIR)/usr/share/ganglia-webfrontend); \
-	else \
-		install -m 0755 -d $(DESTDIR)/$(WEBDIR); \
-		(cd web; rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php . $(DESTDIR)/$(WEBDIR)); \
-	fi
-
+	@#
+	@# Files in /etc
+	@#
+	@echo "\nInstalling config files jobmond.conf jobarchived.conf in $(DESTDIR)/etc"
+	@install -m 0644 jobmond/jobmond.conf $(DESTDIR)/etc
+	@install -m 0644 jobarchived/jobarchived.conf $(DESTDIR)/etc
+	@#
+	@# Files in /usr/share
+	@#
+	@echo "\nInstalling job_dbase.sql in $(PREFIX)/share/jobarchived"
+	@install -m 0755 -d $(DESTDIR)$(PREFIX)/share/jobarchived
+	@install -m 0755 jobarchived/job_dbase.sql $(DESTDIR)$(PREFIX)/share/jobarchived/
+	@#
+	@# Create the /var/lib/jobarchive directory where rrds are stored.
+	@#
+	@echo "\nCreating the directory where RRDs will be stored: $(JOBARCHIVE_RRDS)"
+	@install -m 0755 -d $(DESTDIR)$(JOBARCHIVE_RRDS)
+	@#
+	@# Files for ganglia (adapt to rpm or deb or unknown ganglia packaging)
+	@#
+	@echo "\nInstalling Ganglia web interface to $(GANGLIA_ROOT) ."
+	@install -m 0755 -d $(DESTDIR)$(GANGLIA_ROOT)
+	@(cd web; rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php . $(DESTDIR)$(GANGLIA_ROOT)/)
+	@#
+	@echo "\nInstallation complete.\n"
 
 deb-webfrontend:	${REQUIRED}
 	mkdir -p ${TMPDIR}/.monarch_buildroot/jobmonarch-webfrontend_${VERSION}-${RELEASE}/DEBIAN >/dev/null
-	mkdir -p ${TMPDIR}/.monarch_buildroot/jobmonarch-webfrontend_${VERSION}-${RELEASE}/${WEBDIR} >/dev/null
+	mkdir -p ${TMPDIR}/.monarch_buildroot/jobmonarch-webfrontend_${VERSION}-${RELEASE}/${GANGLIA_ROOT} >/dev/null
 	( cd web; rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php \
-	. ${TMPDIR}/.monarch_buildroot/jobmonarch-webfrontend_${VERSION}-${RELEASE}/${WEBDIR} )
+	. ${TMPDIR}/.monarch_buildroot/jobmonarch-webfrontend_${VERSION}-${RELEASE}/${GANGLIA_ROOT} )
 	( cd pkg/deb/web/DEBIAN; \
 	rsync -a --exclude=.svn --exclude=*_test* --exclude=*-example.php \
@@ -165,4 +189,4 @@
 clean:
 	rm -rf ${TMPDIR}/.monarch_buildroot
-	rm -rf ./jobmonarch.spec
+	rm -rf ./pkg/rpm/jobmonarch.spec
 	rm -rf ./debian
Index: branches/1.0/jobarchived/jobarchived.conf
===================================================================
--- branches/1.0/jobarchived/jobarchived.conf	(revision 840)
+++ branches/1.0/jobarchived/jobarchived.conf	(revision 841)
@@ -76,5 +76,5 @@
 #
 JOB_SQL_DBASE			: localhost/jobarchive
-JOB_SQL_USER            : jobarchive
+JOB_SQL_USER                    : jobarchive
 
 #JOB_SQL_PASSWORD        : 
Index: branches/1.0/pkg/rpm/jobmonarch.spec.in
===================================================================
--- branches/1.0/pkg/rpm/jobmonarch.spec.in	(revision 840)
+++ branches/1.0/pkg/rpm/jobmonarch.spec.in	(revision 841)
@@ -52,7 +52,8 @@
 Requires: postgresql >= 8.1.22
 Requires: postgresql-server >= 8.1.22
+Requires: ganglia-gmond
 Requires: python >= 2.5
-Requires: python-rrdtool
 Requires: python-psycopg2
+Requires: rrdtool-python rrdtool
 
 %description -n jobmonarch-jobarchived
@@ -67,4 +68,5 @@
 Requires: python >= 2.5
 Requires: pbs_python
+Requires: ganglia-gmetad
 # Requires: lsf_python
 
@@ -75,6 +77,8 @@
 %package -n jobmonarch-webfrontend
 Summary: webfrontend is the ganglia webfrontend for jobmonarch.
-Requires: ganglia-gmetad >= 3.5.0 ganglia-web >= 3.5.7
+Requires: ganglia-web >= 3.5.7
 Requires: jobmonarch-jobmond = 1.0
+Requires: php-gd
+Requires: php-pgsql
 
 %description -n jobmonarch-webfrontend
@@ -92,40 +96,15 @@
 rm -rf $RPM_BUILD_ROOT
 
-# Set the correct GANGLIA_PATH.
-sed -i -e 's|/var/www/ganglia/|%{gangliaroot}/|g' web/addons/job_monarch/conf.php
 
 # Fix rrdtool web link in footer:
-sed -i -e 's|http:/www.rrdtool.com/|http:/oss.oetiker.ch/rrdtool/|g' ./web/addons/job_monarch/templates/footer.tpl
-
-%__make install DESTDIR=$RPM_BUILD_ROOT
-
-# Create the directory structure.
-#install -m 0755 -d $RPM_BUILD_ROOT/%{_sbindir}
-#install -m 0755 -d $RPM_BUILD_ROOT%{_initrddir}
-#install -m 0755 -d $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
-#install -m 0755 -d $RPM_BUILD_ROOT%{gangliatemplatedir}
-#install -m 0755 -d $RPM_BUILD_ROOT%{gangliaaddonsdir}
-#install -m 0755 -d $RPM_BUILD_ROOT%{_datadir}/jobarchived/
-#install -m 0755 -d $RPM_BUILD_ROOT%{_sharedstatedir}/jobarchived/
-
-# Install jobmond files
-#install -m 0644 jobmond/jobmond.conf $RPM_BUILD_ROOT%{_sysconfdir}/
-#install -m 0755 jobmond/jobmond.py $RPM_BUILD_ROOT/%{_sbindir}/
-#install -m 0755 pkg/rpm/init.d/jobmond $RPM_BUILD_ROOT%{_initrddir}/
-#install -m 0755 pkg/rpm/sysconfig/jobmond $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
-#(cd $RPM_BUILD_ROOT/%{_sbindir}/; ln -s jobmond.py jobmond)
-
-# Install jobarchived files
-#install -m 0644 jobarchived/jobarchived.conf $RPM_BUILD_ROOT%{_sysconfdir}/
-#install -m 0755 jobarchived/jobarchived.py $RPM_BUILD_ROOT/%{_sbindir}/
-#install -m 0755 pkg/rpm/init.d/jobarchived $RPM_BUILD_ROOT%{_initrddir}/
-#install -m 0755 pkg/rpm/sysconfig/jobarchived $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
-#install -m 0755 jobarchived/job_dbase.sql $RPM_BUILD_ROOT%{_datadir}/jobarchived/
-#(cd $RPM_BUILD_ROOT/%{_sbindir}/; ln -s jobarchived.py jobarchived)
-
-# Install gangliaweb interface
-#cp %{gangliatemplatedir}/default/images/logo.jpg web/templates/job_monarch/images
-#cp -r web/templates/job_monarch $RPM_BUILD_ROOT%{gangliatemplatedir}/job_monarch
-#cp -r web/addons/job_monarch $RPM_BUILD_ROOT%{gangliaaddonsdir}/job_monarch
+#sed -i -e 's|http:/www.rrdtool.com/|http:/oss.oetiker.ch/rrdtool/|g' ./web/addons/job_monarch/templates/footer.tpl
+
+# Install files in RPM_BUILD_ROOT
+%__make install \
+        PREFIX=/usr \
+        GANGLIA_ROOT=%{gangliaroot} \
+        JOBARCHIVE_RRDS=%{_sharedstatedir}/jobarchive \
+        DESTDIR=$RPM_BUILD_ROOT
+
 
 %clean
@@ -133,17 +112,42 @@
 
 %post -n jobmonarch-jobmond
-if [ -x /sbin/chkconfig ]; then
+# $1 = 1 => install ($1 = 2 => upgrade)
+if [ "$1" = 1 ]; then
     /sbin/chkconfig --add jobmond
+    /sbin/service jobmond start
+elif [ "$1" = 2 ]; then
+    /sbin/service jobmond restart
 fi
 
 %post -n jobmonarch-jobarchived
-if [ -x /sbin/chkconfig ]; then
-    if [ ! -d /var/lib/pgsql/data/base ]; then
-        /sbin/service postgresql initdb
+# $1 = 1 => install ($1 = 2 => upgrade)
+if [ "$1" = 1 ]; then
+    if [ -x /usr/sbin/systemctl ]; then
+        if [ ! -d %{_sharedstatedir}/pgsql/data/base ]; then
+            %{_bindir}/postgresql-setup initdb
+        fi
+        %{_sbindir}/systemctl enable postgresql
+        %{_sbindir}/systemctl start postgresql
+    elif [ -x /sbin/chkconfig ]; then
+        if [ ! -d %{_sharedstatedir}/pgsql/data/base ]; then
+            /sbin/service postgresql initdb
+        fi
+	/sbin/chkconfig --level 235 postgresql on
+        /sbin/service postgresql start
     fi
-    /sbin/service postgresql start
-    su -l postgres -c "/usr/bin/createdb jobarchive"
-    su -l postgres -c "/usr/bin/psql -f /usr/share/jobarchived/job_dbase.sql jobarchive"
+    # Generate a 8 char password for the database:
+    export DB_PASSWD=$(tr -dc A-Za-z0-9_< /dev/urandom |head -c 8 | xargs)
+    # Set the password in the SQL script 
+    sed -i -e '/^.*modify me:.*$/d' -e 's/^#CREATE/CREATE/g' -e "s/'';/'$DB_PASSWD';/g" %{_datadir}/jobarchived/job_dbase.sql
+    # Set the password in the jobarchived config.
+    sed -i -s "s/^#JOB_SQL_PASSWORD.*$/JOB_SQL_PASSWORD\t\t: $DB_PASSWD/g" %{_sysconfdir}/jobarchived.conf
+    # Create the database
+    su -l postgres -c "%{_bindir}/createdb jobarchive"
+    # Ccreate the tables.
+    su -l postgres -c "%{_bindir}/psql -f %{_datadir}/jobarchived/job_dbase.sql jobarchive"
     /sbin/chkconfig --add jobarchived
+    /sbin/service jobarchived start
+elif [ "$1" = 2 ]; then
+    /sbin/service jobarchived restart
 fi
 
@@ -174,6 +178,6 @@
     echo "Make sure to set your Ganglia template to previous config now"
     echo ""
-    echo "In your Ganglia conf.php, remove this line:"
-    echo "\$template_name = \"job_monarch\";"
+    echo "In your Ganglia conf.php, restore your previous template:"
+    echo "\$template_name = \"default\";"
 fi
 
@@ -183,5 +187,5 @@
 %files -n jobmonarch-jobmond
 %doc jobmond/examples
-%config %{_sysconfdir}/jobmond.conf
+%config(noreplace) %{_sysconfdir}/jobmond.conf
 %{_sysconfdir}/sysconfig/jobmond
 %{_initrddir}/jobmond
@@ -191,5 +195,5 @@
 %files -n jobmonarch-jobarchived
 %doc jobarchived/examples
-%config %{_sysconfdir}/jobarchived.conf
+%config(noreplace) %{_sysconfdir}/jobarchived.conf
 %{_sysconfdir}/sysconfig/jobarchived
 %{_initrddir}/jobarchived
@@ -207,5 +211,5 @@
 %dir %{gangliatemplatedir}/job_monarch/images
 %{gangliatemplatedir}/job_monarch/images/logo.jpg
-%config %{gangliaaddonsdir}/job_monarch/conf.php
+%config(noreplace) %{gangliaaddonsdir}/job_monarch/conf.php
 %{gangliaaddonsdir}/job_monarch/ajax-loader.gif
 %{gangliaaddonsdir}/job_monarch/cal.gif
@@ -375,4 +379,5 @@
 - Fix the correct gangliaroot path
 - Fix the correct jobarchive rrd file path.
+- Generate a password for the database and update config files accordingly.
 
 * Tue Apr 23 2013 Olivier Lahaye <olivier.lahaye@free.fr> 1.0-2
