2012-07-20 23:31:10 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2012-07-23 21:10:43 +08:00
|
|
|
#
|
|
|
|
# This script creates config/environments/*.js files using
|
|
|
|
# config/environments/*.js.example files as input and performing
|
|
|
|
# settings substitutions.
|
|
|
|
#
|
|
|
|
# It relies on a known format of the .js.example 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(2012-07-23)
|
|
|
|
#
|
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
ENVDIR=config/environments
|
|
|
|
|
|
|
|
PGPORT=
|
|
|
|
SQLAPI_PORT=
|
2012-11-21 20:23:04 +08:00
|
|
|
MAPNIK_VERSION=
|
2013-07-15 19:59:55 +08:00
|
|
|
ENVIRONMENT=development
|
2012-11-21 20:23:04 +08:00
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
STATUS="$0 $*"
|
|
|
|
|
2012-07-20 23:31:10 +08:00
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [OPTION]"
|
|
|
|
echo
|
|
|
|
echo "Configuration:"
|
2012-11-21 20:23:04 +08:00
|
|
|
echo " --help display this help and exit"
|
|
|
|
echo " --with-pgport=NUM access PostgreSQL server on TCP port NUM [$PGPORT]"
|
2013-07-15 19:55:13 +08:00
|
|
|
echo " --with-sqlapi-port=NUM access SQL-API server on TCP port NUM [$SQLAPI_PORT]"
|
2012-11-21 20:23:04 +08:00
|
|
|
echo " --with-mapnik-version=STRING set mapnik version string [$MAPNIK_VERSION]"
|
2013-07-15 19:59:55 +08:00
|
|
|
echo " --environment=STRING set output environment name [$ENVIRONMENT]"
|
2012-07-20 23:31:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while test -n "$1"; do
|
|
|
|
case "$1" in
|
|
|
|
--help|-h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--with-pgport=*)
|
|
|
|
PGPORT=`echo "$1" | cut -d= -f2`
|
|
|
|
;;
|
2013-07-15 19:55:13 +08:00
|
|
|
--with-sqlapi-port=*)
|
|
|
|
SQLAPI_PORT=`echo "$1" | cut -d= -f2`
|
|
|
|
;;
|
2012-11-21 20:23:04 +08:00
|
|
|
--with-mapnik-version=*)
|
|
|
|
MAPNIK_VERSION=`echo "$1" | cut -d= -f2`
|
|
|
|
;;
|
2013-07-15 19:59:55 +08:00
|
|
|
--environment=*)
|
|
|
|
ENVIRONMENT=`echo "$1" | cut -d= -f2`
|
|
|
|
;;
|
2012-07-20 23:31:10 +08:00
|
|
|
*)
|
|
|
|
echo "Unknown option '$1'" >&2
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
ENVEX=./${ENVDIR}/${ENVIRONMENT}.js.example
|
|
|
|
|
|
|
|
if [ -z "$PGPORT" ]; then
|
|
|
|
PGPORT=`node -e "console.log(require('${ENVEX}').postgres.port)"`
|
|
|
|
fi
|
|
|
|
if [ -z "$SQLAPI_PORT" ]; then
|
|
|
|
SQLAPI_PORT=`node -e "console.log(require('${ENVEX}').sqlapi.port)"`
|
|
|
|
fi
|
|
|
|
|
2012-07-20 23:31:10 +08:00
|
|
|
echo "PGPORT: $PGPORT"
|
2013-07-15 19:59:55 +08:00
|
|
|
echo "SQLAPI_PORT: $SQLAPI_PORT"
|
2012-11-21 20:23:04 +08:00
|
|
|
echo "MAPNIK_VERSION: $MAPNIK_VERSION"
|
2013-07-15 19:59:55 +08:00
|
|
|
echo "ENVIRONMENT: $ENVIRONMENT"
|
2012-07-20 23:31:10 +08:00
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
o=`dirname "${ENVEX}"`/`basename "${ENVEX}" .example`
|
|
|
|
echo "Writing $o"
|
2012-11-21 20:23:04 +08:00
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
# See http://austinmatzko.com/2008/04/26/sed-multi-line-search-and-replace/
|
|
|
|
sed -n "1h;1!H;\${;g;s/\(,postgres: {[^}]*port: *'\?\)[^',]*\('\?,\)/\1$PGPORT\2/;p;}" < "${ENVEX}" \
|
2012-11-21 20:23:04 +08:00
|
|
|
| sed "s/mapnik_version:.*/mapnik_version: '$MAPNIK_VERSION'/" \
|
2013-07-15 19:55:13 +08:00
|
|
|
| sed -n "1h;1!H;\${;g;s/\(,sqlapi: {[^}]*port: *'\?\)[^',]*\('\?,\)/\1$SQLAPI_PORT\2/;p;}" \
|
2012-11-21 20:23:04 +08:00
|
|
|
> "$o"
|
|
|
|
|
2013-11-14 23:21:40 +08:00
|
|
|
STATUSFILE=config.status--${ENVIRONMENT}
|
|
|
|
echo "Writing ${STATUSFILE}"
|
|
|
|
echo ${STATUS} > ${STATUSFILE} && chmod +x ${STATUSFILE}
|
|
|
|
|