Skip to content
Snippets Groups Projects
Commit d5741be5 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Added DB credentials propagation across scripts

parent 3a6cc2f9
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ US data:
## Author
Riccardo Boero - ribo@nilu.no
## License
## Licenses
All the code and the resulting docker images in this project are subject to:
- [![GPL v3](https://www.gnu.org/graphics/gplv3-88x31.png "License Icon")](https://www.gnu.org/licenses/gpl-3.0.en.html#license-text)
......
#!/bin/bash
# Function to display help
function show_help() {
echo "Usage: $0 <host> <user> <password>"
echo ""
echo "This script sets up the database and loads the data."
echo ""
echo "Arguments:"
echo " host Database host"
echo " user Database user"
echo " password Database password"
}
# Check if help is requested
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
exit 0
fi
# Check if all three parameters are provided
if [[ $# -ne 3 ]]; then
echo "Error: Missing arguments."
show_help
exit 1
fi
# Assign parameters to variables
HOST=$1
USER=$2
PASSWORD=$3
# create database
./inputs/setup_db.sh
./inputs/setup_db.sh "$HOST" "$USER" "$PASSWORD"
# load vector data into DB
./inputs/load_vector_data.sh
./inputs/load_vector_data.sh "$HOST" "$USER" "$PASSWORD"
# dump data and drop database on 'local' instance
./inputs/dump_and_drop.sh
./inputs/dump_and_drop.sh "$HOST" "$USER" "$PASSWORD"
#!/bin/bash
# Assign parameters to variables
HOST=$1
USER=$2
PASSWORD=$3
echo "*** Dump database:"
mkdir -p ./dump
mariadb-dump -h "" -u "root" -p --databases FACT_power > ./dump/db_power.sql
mariadb-dump -h "$HOST" -u "$USER" -p"$PASSWORD" --databases FACT_power > ./dump/db_power.sql
echo "*** Drop database:"
mariadb -h "" -u "root" -p < inputs/sql/drop_db.sql
mariadb -h "$HOST" -u "$USER" -p"$PASSWORD" < inputs/sql/drop_db.sql
#!/bin/bash
#!/bin/bash
# Assign parameters to variables
HOST=$1
USER=$2
PASSWORD=$3
# Europe
# Generation
......@@ -6,13 +11,13 @@
mkdir -p ./temp
wget -N 'https://zenodo.org/records/3574566/files/JRC-PPDB-OPEN.ver1.0.zip?download=1' -O ./temp/power.zip
unzip -d ./temp/ ./temp/power.zip
ogr2ogr -f MySQL MySQL:FACT_power,host=,user=root,password= temp/JRC_OPEN_UNITS.csv -oo X_POSSIBLE_NAMES=lon -oo Y_POSSIBLE_NAMES=lat -oo KEEP_GEOM_COLUMNS=NO -nln eu_gen -update -overwrite -lco engine=Aria -skipfailures
ogr2ogr -f MySQL MySQL:FACT_power,host=$HOST,user=$USER,password=$PASSWORD temp/JRC_OPEN_UNITS.csv -oo X_POSSIBLE_NAMES=lon -oo Y_POSSIBLE_NAMES=lat -oo KEEP_GEOM_COLUMNS=NO -nln eu_gen -update -overwrite -lco engine=Aria -skipfailures
rm -r ./temp
# Transmission 2023
mkdir -p ./temp
cp ./inputs/EU_power.zip ./temp/power.zip
unzip -d ./temp/ ./temp/power.zip
ogr2ogr -f MySQL MySQL:FACT_power,host=,user=root,password= ./temp/EU_power_lines.shp -nln eu_trans -update -overwrite -lco engine=Aria -skipfailures
ogr2ogr -f MySQL MySQL:FACT_power,host=$HOST,user=$USER,password=$PASSWORD ./temp/EU_power_lines.shp -nln eu_trans -update -overwrite -lco engine=Aria -skipfailures
rm -r ./temp
# US
......@@ -21,12 +26,12 @@ rm -r ./temp
mkdir -p ./temp
wget -N 'https://hub.arcgis.com/api/v3/datasets/bf5c5110b1b944d299bb683cdbd02d2a_0/downloads/data?format=shp&spatialRefId=3857&where=1%3D1' -O ./temp/power.zip
unzip -d ./temp/ ./temp/power.zip
ogr2ogr -f MySQL MySQL:FACT_power,host=,user=root,password= temp/Power_Plants.shp -nln us_gen -update -overwrite -lco engine=Aria -skipfailures
ogr2ogr -f MySQL MySQL:FACT_power,host=$HOST,user=$USER,password=$PASSWORD temp/Power_Plants.shp -nln us_gen -update -overwrite -lco engine=Aria -skipfailures
rm -r ./temp
# Transmission
# December 11, 2023
mkdir -p ./temp
wget -N 'https://hub.arcgis.com/api/v3/datasets/bd24d1a282c54428b024988d32578e59_0/downloads/data?format=shp&spatialRefId=3857&where=1%3D1' -O ./temp/power.zip
unzip -d ./temp/ ./temp/power.zip
ogr2ogr -f MySQL MySQL:FACT_power,host=,user=root,password= ./temp/Electric_Power_Transmission_Lines.shp -nln us_trans -update -overwrite -lco engine=Aria -skipfailures
ogr2ogr -f MySQL MySQL:FACT_power,host=$HOST,user=$USER,password=$PASSWORD ./temp/Electric_Power_Transmission_Lines.shp -nln us_trans -update -overwrite -lco engine=Aria -skipfailures
rm -r ./temp
#!/bin/bash
# Assign parameters to variables
HOST=$1
USER=$2
PASSWORD=$3
echo "*** Create database:"
mariadb -h "" -u "root" -p < inputs/sql/create_db.sql
mariadb -h "$HOST" -u "$USER" -p"$PASSWORD" < inputs/sql/create_db.sql
#echo "*** Create tables:"
#mariadb -h "" -u "root" -p < inputs/sql/create_tables.sql
#mariadb -h "$HOST" -u "$USER" -p"$PASSWORD" < inputs/sql/create_tables.sql
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