Last active
May 16, 2024 06:11
-
-
Save JoeCrescoll/d6e0628baa24c6fb8ffd258df90f0a6e to your computer and use it in GitHub Desktop.
Installs PostGIS extension on a Homestead box and enables it on a specific PostgreSQL database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# If you would like to do some extra provisioning you may | |
# add any commands you wish to this file and they will | |
# be run after the Homestead machine is provisioned. | |
# | |
# If you have user-specific configurations you would like | |
# to apply, you may also create user-customizations.sh, | |
# which will be run after this script. | |
# Install PostGIS extension (PostgreSQL) | |
# Let's check if postgis is already installed... | |
dpkg -s postgis >/dev/null 2>&1 | |
# ... if it is, then it assumed that so is postgresql-10-postgis package and that | |
# the postgis extension was already created in the database -> bail early | |
if [[ $? -ne 0 ]]; then | |
# Taken from https://elliotwms.github.io/2016/homestead-postgis/ | |
sudo apt-get update | |
sudo apt-get install -y \ | |
postgis \ | |
postgresql-10-postgis-2.4 | |
# Assign the correct values to these variables | |
db_user=homestead | |
db_pass=secret | |
db_name=menufinder_db | |
# Use PGPASSWORD to login without password prompt | |
# https://www.postgresql.org/docs/9.1/static/libpq-envars.html | |
PGPASSWORD=secret psql \ | |
-U $db_user \ | |
-h localhost \ | |
-c "CREATE EXTENSION postgis;" \ | |
$db_name | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great snippet.
To verify that postgis is correctly installed and extension enabled for a db, check the version with
SELECT PostGIS_version();