#!/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' postgres
su -s /bin/sh -c 'createdb -O nobody nobodydb' postgres

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

su -s /bin/sh -c 'psql 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 -c "select * from phone" nobodydb' nobody
