#!/bin/sh -e

# Create user nobody, a database 'nobodydb' for him, check the database list
# Then fill nobodydb with some data.

su -s /bin/sh -c 'createuser nobody -D -A --cluster 8.0/pg80' postgres
su -s /bin/sh -c 'createdb --cluster 8.0/pg80 -O nobody nobodydb' postgres

su -s /bin/sh -c 'psql --cluster 8.0/pg80 --version' nobody
su -s /bin/sh -c 'psql --cluster 8.0/pg80 -l' nobody

su -s /bin/sh -c 'psql --cluster 8.0/pg80 nobodydb' nobody <<EOF
create table phone (
  name varchar(255) PRIMARY KEY,
  tel int NOT NULL
);
insert into phone values ('Bob', 1);
insert into phone values ('Alice', 2);
EOF

su -s /bin/sh -c 'psql --cluster 8.0/pg80 -c "select * from phone" nobodydb' nobody

su -s /bin/sh -c 'dropdb --cluster 8.0/pg80 nobodydb' postgres
su -s /bin/sh -c 'dropuser --cluster 8.0/pg80 nobody' postgres
