-
Notifications
You must be signed in to change notification settings - Fork 1
/
vrt.sh
executable file
·58 lines (48 loc) · 1.82 KB
/
vrt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# support files in each $SOURCEDIR :
# download.list : prescript with wget/curl to download datas
# settings : env vars for this $SOURCEDIR
# onespecificvrt.vrt : describe a source
# onespecificvrt.vrt.sql : sql postscript
# stop if error
set -e
# variables d'environnement pour postgresql
# export PGHOST="127.0.0.1"
# export PGPORT="5432"
# export PGUSER="georchestra"
# export PGDATABASE="georchestra"
# export PGCLIENTENCODING="utf8"
# export PGPASSWORD="georchestra"
# schema cible
# export ACTIVESCHEMA="public"
# export SOURCEDIR=vrts
# horodatage pour commentaires
DATE=$(date "+%A %d/%m/%Y %H:%M:%S")
rm -f ${SOURCEDIR}/vrtbot.log
touch ${SOURCEDIR}/vrtbot.log
if [ -n "$(ls -A $SOURCEDIR 2>/dev/null)" ]
then
cd "${SOURCEDIR}"
params=()
if [[ ${PROMOTE_TO_MULTI:-true} == true ]]; then
params+=(-nlt PROMOTE_TO_MULTI)
fi
# cycle vrt
for vrt in *.vrt;
do
echo "import de ${SOURCEDIR}/${vrt} dans le schema ${ACTIVESCHEMA} de la base ${PGDATABASE}" | tee -a vrtbot.log
/usr/bin/ogr2ogr \
-f Postgresql \
-overwrite \
PG:"active_schema=${ACTIVESCHEMA}" "${vrt}" -lco SCHEMA=${ACTIVESCHEMA} -lco OVERWRITE=yes -lco GEOMETRY_NAME=geometry "${params[@]}" -lco DESCRIPTION="import par ${JOB_NAME}/${BUILD_NUMBER} le ${DATE} - ${SOURCEDIR}/${vrt}" 2>&1 | tee -a vrtbot.log
# post import sql
if [ -f "${vrt}.sql" ]; then
echo "script sql après import trouvé" | tee -a vrtbot.log
source "settings"
psql -f "${vrt}.sql" | tee -a vrtbot.log
echo "script sql après import exécuté" | tee -a vrtbot.log
fi
done
else
echo "${SOURCEDIR} n'existe pas" | tee -a vrtbot.log
fi