[Fusionforge-commits] FusionForge branch GUM updated. 19c264f353bec13a98342e4ea041bc4b516c1a99

Sylvain Beucler beuc-inria at fusionforge.org
Fri Aug 8 16:26:28 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, GUM has been updated
       via  19c264f353bec13a98342e4ea041bc4b516c1a99 (commit)
      from  c348974524d00ef34814afaa1bd19dfc0a2e3c82 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 19c264f353bec13a98342e4ea041bc4b516c1a99
Author: Sylvain Beucler <sylvain.beucler at inria.fr>
Date:   Fri Aug 8 16:26:02 2014 +0200

    install: base database configuration and initialization

diff --git a/src/GNUmakefile b/src/GNUmakefile
index d2c8852..6ddc2f2 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -18,6 +18,14 @@ install-base-dirs:
 	install -d -m 755 $(DESTDIR)$(config_path)/plugins/
 	install -d -m 755 $(DESTDIR)$(sysconfdir)/cron.d/
 
+# Initial values for generating secrets.ini
+database_host=127.0.0.1
+database_port=5432
+database_name=fusionforge
+database_user=fusionforge
+database_password:=$(shell (head -c100 /dev/urandom; date +"%s:%N") | md5sum | cut -b-32)
+session_key:=$(shell (head -c100 /dev/urandom; date +"%s:%N") | md5sum | cut -b-32)
+
 install-config: install-base-dirs
 #	Install initial configuration without overwriting
 	cp -a --no-clobber etc/config.ini.d/* $(DESTDIR)$(config_path)/config.ini.d/
@@ -29,11 +37,24 @@ install-config: install-base-dirs
 			-e 's, at log_path@,$(log_path),' \
 			> $(DESTDIR)$(config_path)/config.ini; \
 	fi
+	if [ ! -e $(DESTDIR)$(config_path)/config.ini.d/secrets.ini ]; then \
+		sed templates/secrets.ini \
+			-e 's, at database_host@,$(database_host),' \
+			-e 's, at database_port@,$(database_port),' \
+			-e 's, at database_name@,$(database_name),' \
+			-e 's, at database_user@,$(database_user),' \
+			-e 's, at database_password@,$(database_password),' \
+			-e 's, at session_key@,$(session_key),' \
+			> $(DESTDIR)$(config_path)/config.ini.d/secrets.ini; \
+	fi
 #	TODO: httpd.conf.d
 
 install-core: install-base-dirs install-config
 	cp -a VERSION bin common cronjobs db lib templates vendor www $(DESTDIR)$(pkgdatadir)/
 	$(MAKE) -C locale DESTDIR=$(DESTDIR) PREFIX=$(PREFIX) install
+	ln -nfs $(pkgdatadir)/bin/forge_get_config $(DESTDIR)$(prefix)/bin/forge_get_config
+	ln -nfs $(pkgdatadir)/bin/forge_run_jon $(DESTDIR)$(prefix)/bin/forge_run_job
+	ln -nfs $(pkgdatadir)/bin/forge_run_plugin_job $(DESTDIR)$(prefix)/bin/forge_run_plugin_job
 
 PLUGINS:=$(shell utils/list-enabled-plugins.sh)
 PLUGINS_INSTALL_TARGETS=$(addprefix install-plugin-,$(PLUGINS))
@@ -64,24 +85,17 @@ uninstall:
 
 
 ## Step 3: configure & update system
-post-install: post-install-plugins
-	if ! getent passwd $(user); then useradd $(user) -s /bin/false -d $(data_path); fi
-	-service postgresql initdb  # RH
-	service postgresql start
-	su - postgres -c 'createuser -SdR fusionforge'
-	su - postgres -c "createdb --template template0 --encoding UNICODE $(database_name)"
-	if su - postgres -c "createlang -l fusionforge" | grep plpgsql > /dev/null; then \
-		su - postgres -c "createlang plpgsql $(database_name)"; \
-	fi
-#	TODO: use DB credentials rather than assuming user==database_user
-#	su - postgres -c "psql -c \"ALTER ROLE fusionforge PASSWORD 'fusionforge'\""
-	su $(database_user) -s /bin/bash -c 'psql $(database_name) < $(pkgdatadir)/db/1-fusionforge-init.sql'
-	(echo "[core]"; echo "database_user=$(database_user)") > $(config_path)/config.ini.d/secrets.ini
+post-install: post-install-user post-install-db post-install-plugins
+post-install-user:
+	if ! getent passwd $(user) >/dev/null; then useradd $(user) -s /bin/false -d $(data_path); fi
+post-install-db:
+	post-install.d/db-configure.sh
+	post-install.d/db-populate.sh
 	$(pkgdatadir)/bin/upgrade-db.php
 
 PLUGINS_POST_INSTALL_TARGETS=$(addprefix post-install-plugin-,$(PLUGINS))
 post-install-plugins: $(PLUGINS_POST_INSTALL_TARGETS)
-post-install-plugin-%: install-plugin-%
+post-install-plugin-%:
 #	Run plugin-specific DB install/upgrade
 	$(pkgdatadir)/bin/upgrade-db.php $*
 #	Restart apache if there is some change in config
diff --git a/src/GNUmakefile.defaults b/src/GNUmakefile.defaults
index 8591dc6..e138792 100644
--- a/src/GNUmakefile.defaults
+++ b/src/GNUmakefile.defaults
@@ -23,6 +23,5 @@ log_path=$(localstatedir)/log/fusionforge
 
 # No way to detect Apache's distro integration, so let's hard-code:
 httpd_service:=$(shell if [ -e /etc/redhat-release ]; then echo 'httpd'; else echo 'apache2'; fi)
+
 user=fusionforge
-database_name=fusionforge
-database_user=fusionforge
diff --git a/src/post-install.d/db-configure.sh b/src/post-install.d/db-configure.sh
new file mode 100755
index 0000000..357d12b
--- /dev/null
+++ b/src/post-install.d/db-configure.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# Configure PostgreSQL
+
+pg_hba=$(ls /etc/postgresql/*/*/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf 2>/dev/null | head -1)
+
+if [ -z "$pg_hba" ]; then
+    echo "Cannot find pg_hba.conf"
+    return 1
+fi
+
+if [ -e /etc/redhat-release ]; then
+    service postgresql initdb >/dev/null
+    chkconfig postgresql on
+fi
+if ! service postgresql status >/dev/null; then
+    service postgresql start
+fi
+
+# TODO: configure pg_hba.conf
diff --git a/src/post-install.d/db-populate.sh b/src/post-install.d/db-populate.sh
new file mode 100755
index 0000000..de97aec
--- /dev/null
+++ b/src/post-install.d/db-populate.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Create user and database, and import initial data
+
+database_host=$(forge_get_config database_host)
+database_port=$(forge_get_config database_port)
+database_name=$(forge_get_config database_name)
+database_user=$(forge_get_config database_user)
+database_password=$(forge_get_config database_password)
+source_path=$(forge_get_config source_path)
+
+if [ -z "$database_name" ]; then
+    echo "Cannot get database_name"
+    exit 1
+fi
+
+# Abort if db already exists
+if su - postgres -c "psql $database_name" </dev/null 2>/dev/null; then
+    echo "Database '$database_name' already exists, skipping."
+    exit 0
+fi
+
+# Create DB user
+su - postgres -c 'createuser -SDR fusionforge'
+database_password_quoted=$(echo $database_password | sed -e "s/'/''/")
+su - postgres -c psql <<EOF
+ALTER ROLE $database_user WITH PASSWORD '$database_password_quoted' ;
+EOF
+
+# Create database
+su - postgres -c "createdb --template template0 --encoding UNICODE $database_name"
+if ! su - postgres -c "createlang -l $database_name" | grep -q plpgsql; then \
+    su - postgres -c "createlang plpgsql $database_name"; \
+fi
+
+export PGPASSFILE=$(mktemp)
+cat <<EOF > $PGPASSFILE
+$database_host:$database_port:$database_name:$database_user:$database_password
+EOF
+psql -h $database_host -p $database_port -U $database_user $database_name < $source_path/db/1-fusionforge-init.sql
+rm -f $PGPASSFILE
+unset PGPASSFILE
diff --git a/src/templates/secrets.ini b/src/templates/secrets.ini
new file mode 100644
index 0000000..e811862
--- /dev/null
+++ b/src/templates/secrets.ini
@@ -0,0 +1,16 @@
+; This file was generated by the FusionForge installation system.
+; You can edit the values here or move them to other files.
+; These values should not go into world-readable files!
+
+; ATTENTION : these configuration variables may not be used directly
+; by the PHP scripts run by apache.
+; See contents of secrets.inc which is loaded by Apache conf files too
+
+[core]
+database_host=@database_host@
+database_name=@database_name@
+database_user=@database_user@
+database_port=@database_port@
+database_password=@database_password@
+
+session_key=@session_key@

-----------------------------------------------------------------------

Summary of changes:
 src/GNUmakefile                    |   42 ++++++++++++++++++++++++------------
 src/GNUmakefile.defaults           |    3 +--
 src/post-install.d/db-configure.sh |   19 ++++++++++++++++
 src/post-install.d/db-populate.sh  |   41 +++++++++++++++++++++++++++++++++++
 src/templates/secrets.ini          |   16 ++++++++++++++
 5 files changed, 105 insertions(+), 16 deletions(-)
 create mode 100755 src/post-install.d/db-configure.sh
 create mode 100755 src/post-install.d/db-populate.sh
 create mode 100644 src/templates/secrets.ini


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list