Skip to content

Instantly share code, notes, and snippets.

@leblancfg
Last active January 5, 2018 16:21
Show Gist options
  • Save leblancfg/8b5f829e39a9a67971dc2b7178c66404 to your computer and use it in GitHub Desktop.
Save leblancfg/8b5f829e39a9a67971dc2b7178c66404 to your computer and use it in GitHub Desktop.
Installing PostGIS on MinGW / Cygwin
# leblancfg, 4.01.2018
# This script downloads the latest postgreSQL and postGIS
# Windows binaries and installs them embedded, i.e. without admin privileges.
# -----------------
# For use with MinGW and Cygwin,
# Not tested. Use at your own risk.
# See https://gis.stackexchange.com/questions/41060/how-to-install-postgis-On-windows
SQLFN=postgresql-10.1-3-windows-x64-binaries.zip
GISFN=postgis-bundle-pg10-2.4.2x64.zip
SQLURL=http://get.enterprisedb.com/postgresql/
GISURL=http://winnie.postgis.net/download/windows/pg10/buildbot/
# Get PostgreSQL Windows binaries
echo 'Downloading files\n'
if [ ! -e SQLFN ]
then
:
else
curl -O $SQLURL$SQLFN
fi
# Get PostGIS Windows binaries
if [ ! -e GISFN ]
then
:
else
curl -O $GISURL$GISFN
fi
# Unpack and merge the two folders
echo 'Unzipping files'
unzip \*.zip | awk 'BEGIN {ORS=" "} {if(NR%100==0)print "."}'
cp -R -n pgsql/* pgsql/.* . && rm -rf pgsql
cp -R -n postgis-bundle-pg10-2.4.2x64/* . && rm -rf postgis-bundle-pg10-2.4.2x64
# Create two batch files
# This one sets up environment variables
echo '@ECHO ON
@SET PATH="%~dp0bin";%PATH%
@SET PGDATA=%~dp0data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5439
@SET PGLOCALEDIR=%~dp0share\locale
"%~dp0bin\initdb" -U postgres -A trust -E utf8
ECHO "Click enter to exit"
pause' > FirstBatch.bat
# This one starts the db
echo '@ECHO ON
@SET PATH="%~dp0\bin";%PATH%
@SET PGDATA=%~dp0\data
@SET PGDATABASE=geodb
@SET PGUSER=postgres
@SET PGPORT=5439
@SET PGLOCALEDIR=%~dp0\share\locale
"%~dp0bin\pg_ctl" -D "%~dp0data" -l logfile start
ECHO "Click enter to stop"
pause
"%~dp0\bin\pg_ctl" -D "%~dp0/data" stop' > NormalBatch.bat
# Set up the database and start it
echo 'Setting up environment and database, press Enter to continue'
./FirstBatch.bat &> out.log
./NormalBatch.bat > /dev/null 2>&1 &
echo 'Database started'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment