Skip to content

Instantly share code, notes, and snippets.

@rnix
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnix/85c7cc53b800fcef8b71 to your computer and use it in GitHub Desktop.
Save rnix/85c7cc53b800fcef8b71 to your computer and use it in GitHub Desktop.
PostGIS Tiger Build - Fixes the horribleness that is the PostGIS Tiger script generation
#!/bin/bash
export STARTD=${PWD}
SELFD=$(cd $(dirname ${0}) >/dev/null 2>&1; pwd)
if [ -d 85c7cc53b800fcef8b71 ]; then (
cd 85c7cc53b800fcef8b71
git stash
git stash drop
git pull
) else (
git clone https://gist.github.com/85c7cc53b800fcef8b71.git
) fi
export PGUSER=${PGUSER:-postgres}
export PGHOST=${PGHOST:-localhost}
export PGDATABASE=${PGDATABASE:-postgres}
bash 85c7cc53b800fcef8b71/install-national.sh ${@}
#!/bin/bash
export STARTD=${STARTD:-$(cd $(dirname ${0}) >/dev/null 2>&1; pwd)}
SELFD=$(cd $(dirname ${0}) >/dev/null 2>&1; pwd)
SELF=$(basename ${0})
SELFN=$(basename ${SELFD})
SELFU=${SELF%.*}
SELFZ=${SELFD}/${SELF}
NOW=$(date +%Y%m%dt%H%M%S)
UNQ=${NOW}.${RANDOM}
LOG=${STARTD}/${SELFU}.log
exec 3>&1 4>&2
exec 1>${LOG} 2>&1
date
set
set -o verbose
set -o errtrace
set -o xtrace
set -o nounset
export GISDATA=${GISDATA:-${PWD}}
[ -d "${GISDATA}" ] || mkdir "${GISDATA}"
cd "${GISDATA}" || {
echo "Can not access '${GISDATA}' directory" >&4
exit ${LINENO}
}
(
cat ${SELFD}/new-header.sh
psql -At -c "select tiger.loader_generate_nation_script('sh');" 2>nation_generator.err \
| sed -n '/^cd \/gisdata/,$p' \
| perl -pi -e 's|/gisdata|"\${GISDATA}"|g;s/^(export )?[A-Z]+=.*$//g;s/^wget/\${WGETTOOL}/g;'
) >nation_generator.sh
[ -f nation_generator.sh ] || {
echo "Failed to generate nation_generator.sh" >&4
exit ${LINENO}
}
set -o pipefail
bash -xv ./nation_generator.sh 2>&1 | tee nation_generator.log || exit ${?}
(( ${#} > 0 )) && bash -xv ${SELFD}/install-states.sh ${@}
#!/bin/bash
export STARTD=${STARTD:-$(cd $(dirname ${0}) >/dev/null 2>&1; pwd)}
SELFD=$(cd $(dirname ${0}) >/dev/null 2>&1; pwd)
SELF=$(basename ${0})
SELFN=$(basename ${SELFD})
SELFU=${SELF%.*}
SELFZ=${SELFD}/${SELF}
NOW=$(date +%Y%m%dt%H%M%S)
UNQ=${NOW}.${RANDOM}
LOG=${STARTD}/${SELFU}.log
exec 3>&1 4>&2
exec 1>${LOG} 2>&1
date
set
set -o verbose
#set -o errexit
set -o errtrace
set -o xtrace
set -o nounset
STATE_LIST=$(IFS='_'; echo "${*}")
STATE_SQL=$(A=($(printf " '%s'" "${@}")); IFS=','; echo "${A[*]}")
LOADER=loader_script_${STATE_LIST}
(
cat ${SELFD}/new-header.sh
psql -At -c "select tiger.loader_generate_script(ARRAY[${STATE_SQL}], 'sh');" 2>${LOADER}.err \
| sed -n '/^cd \/gisdata/,$p' \
| perl -pi -e 's|/gisdata|"\${GISDATA}"|g;s/^(export )?[A-Z]+=.*$//g;s/^wget/\${WGETTOOL}/g;'
) >${LOADER}.sh
[ -f ${LOADER}.sh ] || {
echo "Failed to generate ${LOADER}.sh" >&4
exit ${LINENO}
}
set -o pipefail
[ "${TEST:-}" ] || {
bash -xv ./${LOADER}.sh 2>&1 | tee ${LOADER}.log
}
#!/bin/bash
TMPDIR="${GISDATA}/temp/"
UNZIPTOOL=$(which unzip)
[ -x "${UNZIPTOOL}" ] || {
echo "Missing unzip" >&2
exit ${LINENO}
}
WGETTOOL=$(which wget)
[ -x "${WGETTOOL}" ] || {
echo "Missing wget" >&2
exit ${LINENO}
}
export PGBIN=$(pg_config --bindir)
export PGPORT=${PGPORT:-5432}
[ "${PGHOST}" ] || {
echo "export PGHOST before calling this script" >&2
exit ${LINENO}
}
[ "${PGUSER}" ] || {
echo "export PGUSER before calling this script" >&2
exit ${LINENO}
}
[ "${PGDATABASE}" ] || {
echo "export PGDATABASE before calling this script" >&2
psql -l
exit ${LINENO}
}
psql -c 'select 1' >/dev/null 2>&1 || {
echo "Can not connect to ${PGHOST}:${PGPORT}@${PGDATABASE}/${PGUSER}" >&2
exit ${LINENO}
}
search_path=$(psql -tc 'show search_path;' |tee .${PGUSER}.search_path)
psql -c 'alter user '"${PGUSER}"' set search_path = tiger,tiger_data,pg_catalog,public;'
trap psql -c "alter ${PGUSER} set search_path = ${search_path};" 0 1 2 3
PSQL=${PGBIN}/psql
SHP2PGSQL=${PGBIN}/shp2pgsql
[ -x ${PSQL} ] || {
echo "Missing ${PSQL}. You need to run this script on a host with postgresql-client installed." >&2
exit ${LINENO}
}
[ -x ${SHP2PGSQL} ] || {
echo "Missing ${SHP2PGSQL}. You need to run this script on a host with POSTGIS installed." >&2
exit ${LINENO}
}
set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment