From c26db786b049b3f70a0f62d9f3f167e4b2a64c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 22 May 2020 20:20:35 +0300 Subject: [PATCH] simplify managedb --- II/Referatas/Makefile | 5 +-- II/Referatas/managedb | 84 +++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 56 deletions(-) diff --git a/II/Referatas/Makefile b/II/Referatas/Makefile index c88d514..d5f2cb6 100644 --- a/II/Referatas/Makefile +++ b/II/Referatas/Makefile @@ -1,5 +1,3 @@ -SHELL = /bin/bash - GEN = zeimena.pdf st-simplify-300.pdf st-simplify-500.pdf st-simplify-1000.pdf mj-referatas.pdf: mj-referatas.tex version.tex bib.bib zeimena-pretty.pdf $(GEN) @@ -12,8 +10,7 @@ st-simplify-%.pdf: db/.faux_st-simplify-% ./layer2img.py --table=douglas_$* --size=74x52 --outfile $@ db/.faux_st-simplify-%: db/.faux_ready st-simplify.sql - . ./managedb ; \ - psql --echo-all -v ON_ERROR_STOP=1 -v tolerance=$* -f st-simplify.sql + ./managedb -- --echo-all -v ON_ERROR_STOP=1 -v tolerance=$* -f st-simplify.sql touch $@ db/.faux_ready: zeimena.gpkg managedb diff --git a/II/Referatas/managedb b/II/Referatas/managedb index 8fb366d..0ff52bf 100755 --- a/II/Referatas/managedb +++ b/II/Referatas/managedb @@ -1,55 +1,35 @@ #!/bin/bash -main() { - PATH=$PATH:/usr/lib/postgresql/12/bin - case ${1:-} in - init) - mkdir -p db && initdb db - mkdir -p db/wal - sed -i "s/.*unix_socket_dir.*/unix_socket_directories = '.\/wal'/" \ - db/postgresql.conf - pg_ctl -D db -l db/logfile start +PATH=$PATH:/usr/lib/postgresql/12/bin +case ${1:-} in + init) + mkdir -p db && initdb db + mkdir -p db/wal + sed -i "s/.*unix_socket_dir.*/unix_socket_directories = '.\/wal'/" \ + db/postgresql.conf + pg_ctl -D db -l db/logfile start - export PGHOST=127.0.0.1 - psql postgres -c 'CREATE ROLE osm WITH SUPERUSER LOGIN' - psql postgres -c 'CREATE DATABASE osm' - psql osm osm -c 'CREATE EXTENSION postgis' - ;; - start) - pg_ctl -D db -l db/logfile start - ;; - stop) - pg_ctl -D db -l db/logfile stop - ;; - "" | --) - [[ $# == 2 ]] && shift - exports - exec psql "$@" - ;; - *) - >&2 echo "Unknown command: '$*'" - exit 1 - ;; - esac -} - -exports() { - export PGHOST=127.0.0.1 - export PGUSER=osm - export PGDATABASE=osm -} - -if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then - if [[ $# != 0 ]]; then - >&2 echo "Sourcing does not accept arguments: $*" - else - exports - >&2 echo "OK: exported PGUSER, PGHOST and PGDATABASE" - fi -else - set -euo pipefail - export PGHOST= - export PGUSER= - export PGDATABASE= - main "$@" -fi + export PGHOST=127.0.0.1 + psql postgres -c 'CREATE ROLE osm WITH SUPERUSER LOGIN' + psql postgres -c 'CREATE DATABASE osm' + psql osm osm -c 'CREATE EXTENSION postgis' + ;; + start) + pg_ctl -D db -l db/logfile start + ;; + stop) + pg_ctl -D db -l db/logfile stop + ;; + "" | --) + [[ $# -gt 1 ]] && shift + exec env \ + PGHOST=127.0.0.1 \ + PGUSER=osm \ + PGDATABASE=osm \ + psql "$@" + ;; + *) + >&2 echo "Unknown command: '$*'" + exit 1 + ;; +esac