Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
createDataset.sh 3.21 KiB
#! /bin/bash
#############################
# This script imports data (e.g. from the road network of bolzano) that is
# downloaded from osm (OpenStreetMap) and then imported into available
# databases (neo4j_spatial, postgis and spatialite).
#
# In difference to importData.sh this only imports a given dataset with the
# given SRIDs.
#
# Note that you need some synlinks in directoy /opt/ (to isochrone-datamodel
# and isochrone-tools project) for this script to work correctly.
#############################

if [ "$EUID" -ne "0" ]; then
	echo '- This script must be run as root!'
	exit 1
fi

########################################################################
# Config import (so we can override some things like working directory #
########################################################################

SCRIPT="$(readlink -f ${BASH_SOURCE[0]})"
CURRENT_DIR="$(dirname ${SCRIPT})"
SCRIPT_DIR="${CURRENT_DIR}/../bootstrap"
if [ ! -f "${SCRIPT_DIR}/config.sh" ]; then
	# If config.properties is not besides the bash-script (most likely because vagrant uploaded it into the guest)
	# we will try to find it in the shared folder
	SCRIPT_DIR="/vagrant/bootstrap"
fi
if [ ! -f "${SCRIPT_DIR}/config.sh" ]; then
	echo '- No variable declarations found (config.properties file not found)!'
	exit 1;
fi
source "${SCRIPT_DIR}/config.sh"

############################
# Precondition checks      #
############################


if ! $AVAILABLE_ISOCHRONE_DATAMODEL; then
	echo " - Project folder isochrone-datamodel not present in directory '${DEPLOY_DIR}'"
	exit 1
fi

if ! $AVAILABLE_ISOCHRONE_TOOLS; then
	echo " - Project archive isochrone-tools not present in directory '${DEPLOY_DIR}'"
	exit 1
fi

if ! $AVAILABLE_POSTGRES; then
	echo " - PostgreSQL database not installed on this system"
	exit 1
fi

if ! $AVAILABLE_POSTGIS; then
	echo " - Postgis extension not installed on this system"
	exit 1
fi

############################
# Variable definitions     #
############################

DATASET_SRID="${1}"
DATASET_CITY="${2}"
PG_DB_USER="${3}"
PG_DB_PASSWORD="${4}"
UPDATE_DATA=true
WORKING_DIR="${CURRENT_DIR}"

source "${SCRIPT_DIR}/importData.sh" "${PG_DB_USER}" "${PG_DB_PASSWORD}" "false" "false"

################
# Data import  #
################

echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Creating datasets ($(date +%H:%M:%S)):"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

START=$(date +%s)

mkdir -p "${DATA_DIR}"
mkdir -p "${DOWNLOAD_DIR}"
mkdir -p "${WORKING_DIR}"
cd "${WORKING_DIR}"

# Delete old log files
find . -type f -name "*.log" -delete

# Create datasets
CITY_ARR=(${DATASET_CITY//,/ })
SRID_ARR=(${DATASET_SRID//,/ })
for CURRENT_CITY in "${CITY_ARR[@]}"; do
	for CURRENT_SRID in "${SRID_ARR[@]}"; do
		fn_import_dataset_postgis "${CURRENT_CITY}" "${CURRENT_SRID}"
	done
done

END=$(date +%s)
TOTAL=$(( $END - $START ))

echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Datasets created in directory '${DATA_DIR}'"
echo " Imports with last srid specified are still present in the database"
printf ' Time to import the datasets: %dh:%dm:%ds\n' $(($TOTAL/3600)) $(($TOTAL%3600/60)) $(($TOTAL%60))
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"