stud/II/Referatas/managedb

55 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-05-22 10:19:17 +03:00
#!/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
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
;;
2020-05-22 19:28:10 +03:00
"")
exports
psql
;;
2020-05-22 10:19:17 +03:00
*)
>&2 echo "Unknown command: '$*'"
exit 1
;;
esac
}
2020-05-22 19:28:10 +03:00
exports() {
export PGHOST=127.0.0.1
export PGUSER=osm
export PGDATABASE=osm
}
2020-05-22 10:19:17 +03:00
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
if [[ $# != 0 ]]; then
>&2 echo "Sourcing does not accept arguments: $*"
else
2020-05-22 19:28:10 +03:00
exports
2020-05-22 10:19:17 +03:00
>&2 echo "OK: exported PGUSER, PGHOST and PGDATABASE"
fi
else
set -euo pipefail
export PGHOST=
export PGUSER=
export PGDATABASE=
main "$@"
fi