2015-11-01 19:50:55 +05:30
|
|
|
#!/bin/sh
|
2017-02-15 11:09:50 +05:30
|
|
|
set -e
|
2015-11-01 19:50:55 +05:30
|
|
|
|
|
|
|
dbname=gitlab_production
|
|
|
|
|
2017-02-15 11:06:52 +05:30
|
|
|
# Take gitlab_user from envornment variable or use gitlab
|
2017-02-15 18:04:28 +05:30
|
|
|
gitlab_user=${gitlab_user:-gitlab}
|
2017-02-15 11:06:52 +05:30
|
|
|
|
2015-11-03 18:15:04 +05:30
|
|
|
# If gitlab user cannot access gitlab_production,
|
|
|
|
# then it means the gitlab role does not exist
|
2017-02-15 11:06:52 +05:30
|
|
|
if ! su ${gitlab_user} -c 'psql gitlab_production -c ""'
|
2015-11-01 19:50:55 +05:30
|
|
|
then
|
2017-02-15 11:06:52 +05:30
|
|
|
echo "Create ${gitlab_user} user with create database privillege..."
|
2017-02-15 11:09:50 +05:30
|
|
|
su postgres -c "psql -c \"CREATE USER ${gitlab_user} CREATEDB;\""
|
2015-11-01 19:50:55 +05:30
|
|
|
fi
|
|
|
|
|
2015-11-03 18:15:04 +05:30
|
|
|
# By default the gitlab_prodcution is not owned by gitlab user
|
2017-02-15 11:06:52 +05:30
|
|
|
echo "Make ${gitlab_user} user owner of $dbname database..."
|
2017-02-15 11:09:50 +05:30
|
|
|
su postgres -c "psql -c \"ALTER DATABASE $dbname OWNER to ${gitlab_user};\""
|
2015-11-01 19:50:55 +05:30
|
|
|
|
2017-02-15 11:06:52 +05:30
|
|
|
echo "Grant all privileges to ${gitlab_user} user..."
|
2017-02-15 11:09:50 +05:30
|
|
|
su postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE template1 to ${gitlab_user};\""
|
2016-06-02 21:00:27 +05:30
|
|
|
|
|
|
|
# enable the pg_trgm extension
|
2017-02-15 11:09:50 +05:30
|
|
|
su postgres -c "psql -d $dbname -c \"CREATE EXTENSION IF NOT EXISTS pg_trgm;\""
|