From 2a94086ced1a634d81ea06a3e0d904be6460dad3 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 7 Oct 2014 17:53:51 +0200 Subject: [PATCH] Add simple configure script It lets you set TCP ports of database, sql-api and map-api. --- .gitignore | 3 +- configure | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index 4b90bcc322..59f9083a37 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ app/assets/stylesheets/tmp/ db/schema.rb *.pyc bin/ +config.status config/database.yml .idea/* config/app_config.yml @@ -47,4 +48,4 @@ lib/build/dist lib/build/node_modules lib/build/grunt-aws.json lib/build/app_config.js -rubygems \ No newline at end of file +rubygems diff --git a/configure b/configure new file mode 100755 index 0000000000..81883e60cf --- /dev/null +++ b/configure @@ -0,0 +1,88 @@ +#!/bin/sh + +# +# This script creates config/app_config.yml and config/database.yml +# from the corresponding .sample files as input and performing +# settings substitutions. +# +# It relies on a known format of the .yml.sample files which haven't +# been made easier to parse to still let humans copy them manually and +# do further editing or leave them as such to get the same setup as before +# the introduction of this script. +# +# The script is a work in progress. Available switches are printed +# by invoking with the --help switch. More switches will be added +# as the need/request for them arises. +# +# --strk(2014-10-07) +# + +STATUS="$0 $*" + +APPCONFIG=`dirname $0`/config/app_config.yml +DBCONFIG=`dirname $0`/config/database.yml + +if [ -z "$PGPORT" ]; then + PGPORT=`grep -w "port:" ${DBCONFIG}.sample | head -1 | cut -d: -f2 | sed 's/^\s*//;s/\s*$//'` +fi + +if [ -z "$SQLAPI_PORT" ]; then + SQLAPI_PORT=`cat ${APPCONFIG}.sample | grep -A10 sql_api: | grep port: | head -1 | cut -d: -f2 | sed 's/^\s*//;s/\s*$//'` +fi + +if [ -z "$MAPAPI_PORT" ]; then + MAPAPI_PORT=`cat ${APPCONFIG}.sample | grep -A10 tiler: | grep port: | head -1 | cut -d: -f2 | sed 's/^\s*["'\'']\?//;s/["'\'']\?\s*$//'` +fi + +#PGPORT=`node -e "console.log(require('${ENVEX}').postgres.port)"` + +usage() { + echo "Usage: $0 [OPTION]" + echo + echo "Configuration:" + echo " --help display this help and exit" + echo " --with-pgport=NUM access PostgreSQL server on TCP port NUM [$PGPORT]" + echo " --with-mapapi-port=NUM access MAP-API server on TCP port NUM [$MAPAPI_PORT]" + echo " --with-sqlapi-port=NUM access SQL-API server on TCP port NUM [$SQLAPI_PORT]" +} + +while test -n "$1"; do + case "$1" in + --help|-h) + usage + exit 0 + ;; + --with-pgport=*) + PGPORT=`echo "$1" | cut -d= -f2` + ;; + --with-sqlapi-port=*) + SQLAPI_PORT=`echo "$1" | cut -d= -f2` + ;; + --with-mapapi-port=*) + MAPAPI_PORT=`echo "$1" | cut -d= -f2` + ;; + *) + echo "Unused option '$1'" >&2 + #usage >&2 + #exit 1 + esac + shift +done + +echo "PGPORT: $PGPORT" +echo "SQLAPI_PORT: $SQLAPI_PORT" +echo "MAPAPI_PORT: $MAPAPI_PORT" + + +echo "Writing ${APPCONFIG}" +# Relies on known values in the .sample file +cat ${APPCONFIG}.sample | sed "s/8080/${SQLAPI_PORT}/;s/8181/${MAPAPI_PORT}/" > "${APPCONFIG}" + +echo "Writing ${DBCONFIG}" +# Relies on known values in the .sample file +cat ${DBCONFIG}.sample | sed "s/5432/${PGPORT}/" > "${DBCONFIG}" + +STATUSFILE=config.status +echo "Writing ${STATUSFILE}" +echo ${STATUS} > ${STATUSFILE} && chmod +x ${STATUSFILE} +