stud/contours/managedb

50 lines
940 B
Plaintext
Raw Normal View History

2020-12-11 10:44:26 +02:00
#!/bin/bash
2020-12-15 23:49:25 +02:00
_psql() {
env \
PGPASSWORD=osm \
PGHOST=127.0.0.1 \
PGUSER=osm \
PGDATABASE=osm \
psql "$@"
}
2020-12-11 10:44:26 +02:00
2020-12-15 23:49:25 +02:00
_wait_for_postgres() {
>&2 echo -n "Waiting for postgres"
for _ in $(seq 240); do
if _psql -qc '\q' 2>/dev/null; then
>&2 echo " up"
exit 0
fi
>&2 echo -n .
sleep 1
done
>&2 echo " down"
exit 1
}
name=postgis-contours
case ${1:-} in
2020-12-11 10:44:26 +02:00
start)
2020-12-15 23:49:25 +02:00
docker run -d --rm \
-p 5432:5432 \
-e POSTGRES_DBNAME=osm \
-e POSTGRES_USER=osm \
-e POSTGRES_PASSWORD=osm \
--name "$name" \
postgis/postgis:13-3.0-alpine
_wait_for_postgres
2020-12-11 10:44:26 +02:00
;;
stop)
2020-12-15 23:49:25 +02:00
docker stop "$name"
2020-12-11 10:44:26 +02:00
;;
"" | --)
[[ $# -gt 1 ]] && shift
2020-12-15 23:49:25 +02:00
_psql "$@"
2020-12-11 10:44:26 +02:00
;;
*)
>&2 echo "Unknown command: '$*'"
exit 1
;;
esac