Skip to content
Snippets Groups Projects
gen_pop_data.sh 1.5 KiB
Newer Older
# Function to display help
function show_help() {
Riccardo Boero's avatar
Riccardo Boero committed
    echo "Usage: $0 [<host> <user> <password>]"
    echo ""
    echo "This script sets up the database and loads the data."
    echo ""
Riccardo Boero's avatar
Riccardo Boero committed
    echo "Arguments (optional if environment variables are set):"
    echo "  host       Database host (or set DB_HOST)"
    echo "  user       Database user (or set DB_USER)"
    echo "  password   Database password (or set DB_PASSWORD)"
}

# Check if help is requested
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
    show_help
    exit 0
fi

Riccardo Boero's avatar
Riccardo Boero committed
# Check if all three arguments are provided or fallback to environment variables
if [[ $# -eq 3 ]]; then
    HOST=$1
    USER=$2
    PASSWORD=$3
else
    # Check for environment variables
    HOST=${DB_HOST}
    USER=${DB_USER}
    PASSWORD=${DB_PASSWORD}
    
    # If either arguments or environment variables are missing, display help
    if [[ -z "$HOST" || -z "$USER" || -z "$PASSWORD" ]]; then
        echo "Error: Missing arguments or environment variables."
        show_help
        exit 1
    fi
./inputs/setup_db.sh "$HOST" "$USER" "$PASSWORD"

# load vector data into DB
./inputs/load_vector_data.sh "$HOST" "$USER" "$PASSWORD"

# load NUTS objects into DB
./inputs/load_table_data.sh "$HOST" "$USER" "$PASSWORD"
# modify tables to include states and countries data and to be indexed on them
./inputs/modify_tables.sh "$HOST" "$USER" "$PASSWORD"

# dump data and drop database on 'local' instance
./inputs/dump_and_drop.sh "$HOST" "$USER" "$PASSWORD"