#!/bin/sh # TODO: port to node, if you really need it ENV='development'; BASEDIR=`cd $(dirname $0)/../; pwd` if test -z "$1"; then echo "Usage: $0 [--env ] [|~]" >&2 echo " environment defaults to 'development'" exit 1 fi username="" token="" while test -n "$1"; do if test "$1" = "--env"; then shift; ENV="$1"; shift elif test -z "$username"; then username="$1"; shift elif test -z "$token"; then token="$1"; shift else echo "Unused option $1" >&2 shift fi done echo "Using environment '${ENV}'" CONFIG="${BASEDIR}/config/environments/${ENV}.js" REDIS_PORT=`node -e "console.log(require('${CONFIG}').redis.port)"` if test $? -ne 0; then exit 1 fi dbname=`redis-cli -p ${REDIS_PORT} -n 5 hget "rails:users:${username}" "database_name"` if test $? -ne 0; then exit 1 fi if test -z "${dbname}"; then echo "Username ${username} unknown by redis on port ${REDIS_PORT} (try CARTODB/script/restore_redis?)" >&2 exit 1 fi echo "Database name for user ${username}: ${dbname}" # only if verbose? if test -n "$token"; then rec=`redis-cli get "map_style|${dbname}|${token}"` if test -z "${rec}"; then echo "${token}: no such map style known by redis on port ${REDIS_PORT}" >&2 exit 1 fi #echo "${rec}" escrec=`echo "${rec}" | sed -e 's/\\\\/\\\\\\\\/g'` #echo "${escrec}" node <