Modify the script with your username, database name, and password:

CREATE USER username WITH PASSWORD 'password';
CREATE DATABASE dbname OWNER username;
GRANT ALL PRIVILEGES ON DATABASE dbname TO username;
\c dbname
GRANT ALL ON SCHEMA public TO username;

Run as superuser (e.g. postgres):

psql -h hostname -p 5432 -U postgres -f init.sql

Or inline:

psql -h hostname -p 5432 -U postgres -c "CREATE USER myuser WITH PASSWORD 'mypass'; CREATE DATABASE mydb OWNER myuser;"