Skip to content
Snippets Groups Projects
Commit 179c8c42 authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

changes for postgresql commands (should allow case-senstive commands)

convertig to one-time provisioning script
parent 72012f12
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,10 @@
# Environment configuration
###########################
if [ -f "/var/vagrant_provision" ]; then
exit 0
fi
IMPORT_OSMDATA=true
IMPORT_OSMDATA_CACHED=true
IMPORT_SCHEDULES=true
......@@ -174,12 +178,12 @@ fn_import_data()
cp $DOWNLOAD_DIR/$SCHEDULE_FILE $DEPLOY_DIR/$SCHEDULE_FILE > /dev/null 2>&1
echo " - importing schedule into postgis database"
gunzip -c $DEPLOY_DIR/$SCHEDULE_FILE | PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost $PG_DB_NAME >> $WORKING_DIR/import_schedule.log 2>&1
gunzip -c $DEPLOY_DIR/$SCHEDULE_FILE | PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost "$PG_DB_NAME" >> $WORKING_DIR/import_schedule.log 2>&1
echo " - fixing schedule permissions"
tables=`PGPASSWORD=$PG_DB_PASSWORD psql -qAt -U $PG_DB_USER -h localhost -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'postgres';" $PG_DB_NAME`
tables=`PGPASSWORD="$PG_DB_PASSWORD" psql -qAt -U "$PG_DB_USER" -h localhost -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'postgres';" "$PG_DB_NAME"`
for tbl in $tables ; do
PGPASSWORD=$PG_DB_PASSWORD psql -qAt -U $PG_DB_USER -h localhost -c "ALTER TABLE $tbl OWNER TO $PG_DB_USER" $PG_DB_NAME;
PGPASSWORD="$PG_DB_PASSWORD" psql -qAt -U "$PG_DB_USER" -h localhost -c "ALTER TABLE $tbl OWNER TO $PG_DB_USER" "$PG_DB_NAME";
done
fi
fi
......@@ -189,7 +193,7 @@ fn_import_data()
$DEPLOY_DIR/osm2pgrouting/build/osm2pgrouting -file "$DEPLOY_DIR/$OSM_FILE_FILTERED" -conf "$OSM2PGROUTING_MAPPING_CONF" -dbname $PG_DB_NAME -user $PG_DB_USER -passwd $PG_DB_PASSWORD -clean -prefixtables $TABLE_PREFIX >> import_osm2pgrouting.log 2>&1
echo " - creating pgRouting topology"
PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost -d $PG_DB_NAME -c "SELECT pgr_createTopology('${TABLE_PREFIX}_ways', $TOPOLOGY_TOLERANCE, 'the_geom', 'gid');" >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost -d "$PG_DB_NAME" -c "SELECT pgr_createTopology('${TABLE_PREFIX}ways', $TOPOLOGY_TOLERANCE, 'the_geom', 'gid');" >> $WORKING_DIR/setup_database.log 2>&1
fi
if $INSTALL_NEO4J_SPATIAL; then
......@@ -568,22 +572,22 @@ fi
if $INSTALL_POSTGRES; then
echo "Creating postgresql database $PG_DB_NAME"
sudo -u postgres psql -d template1 -c "CREATE DATABASE $PG_DB_NAME;" > $WORKING_DIR/setup_database.log 2>&1
sudo -u postgres psql -d $PG_DB_NAME -c "CREATE USER $PG_DB_USER WITH PASSWORD '$PG_DB_PASSWORD';" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u postgres psql -d $PG_DB_NAME -c "ALTER DATABASE $PG_DB_NAME OWNER TO $PG_DB_USER;" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u postgres psql -d $PG_DB_NAME -c "GRANT ALL PRIVILEGES ON DATABASE $PG_DB_NAME to $PG_DB_USER;" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u postgres psql -d $PG_DB_NAME -c "ALTER SCHEMA public OWNER TO $PG_DB_USER;" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u postgres psql -d $PG_DB_NAME -c "ALTER ROLE $PG_DB_USER SUPERUSER;" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d template1 -c "CREATE DATABASE \"$PG_DB_NAME\";" > $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d "$PG_DB_NAME" -c "CREATE USER \"$PG_DB_USER\" WITH PASSWORD '$PG_DB_PASSWORD';" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d "$PG_DB_NAME" -c "ALTER DATABASE \"$PG_DB_NAME\" OWNER TO \"$PG_DB_USER\";" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d "$PG_DB_NAME" -c "GRANT ALL PRIVILEGES ON DATABASE \"$PG_DB_NAME\" TO \"$PG_DB_USER\";" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d "$PG_DB_NAME" -c "ALTER SCHEMA public OWNER TO \"$PG_DB_USER\";" >> $WORKING_DIR/setup_database.log 2>&1
sudo -u "postgres" psql -d "$PG_DB_NAME" -c "ALTER ROLE \"$PG_DB_USER\" SUPERUSER;" >> $WORKING_DIR/setup_database.log 2>&1
fi
if $INSTALL_POSTGIS; then
PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost -d $PG_DB_NAME -c "CREATE EXTENSION postgis;" >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost -d $PG_DB_NAME -f $SHARED_CONF_DIR/pg_procedures.sql >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost -d $PG_DB_NAME -f $SHARED_CONF_DIR/srid_82344_insert.sql >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost -d "$PG_DB_NAME" -c "CREATE EXTENSION postgis;" >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost -d "$PG_DB_NAME" -f $SHARED_CONF_DIR/pg_procedures.sql >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost -d "$PG_DB_NAME" -f $SHARED_CONF_DIR/srid_82344_insert.sql >> $WORKING_DIR/setup_database.log 2>&1
fi
if $INSTALL_PGROUTING; then
PGPASSWORD=$PG_DB_PASSWORD psql -U $PG_DB_USER -h localhost -d $PG_DB_NAME -c "CREATE EXTENSION pgRouting;" >> $WORKING_DIR/setup_database.log 2>&1
PGPASSWORD="$PG_DB_PASSWORD" psql -U "$PG_DB_USER" -h localhost -d "$PG_DB_NAME" -c "CREATE EXTENSION pgRouting;" >> $WORKING_DIR/setup_database.log 2>&1
fi
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
......@@ -621,6 +625,9 @@ if $IMPORT_OSMDATA || $IMPORT_OSMDATA_CACHED; then
fi
fi
# Prevent second provision (done by check at the beginning of this file)
touch /var/vagrant_provision
END=$(date +%s)
TOTAL=$(( $END - $START ))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment