debian-mirror-gitlab/debian/grantpriv.sh

31 lines
824 B
Bash
Raw Normal View History

#!/bin/sh
user=gitlab
dbname=gitlab_production
2015-11-03 18:15:04 +05:30
# If gitlab user cannot access gitlab_production,
# then it means the gitlab role does not exist
2016-01-29 21:37:47 +05:30
if ! su gitlab -c 'psql gitlab_production -c ""'
then
echo "Create $user user with create database privillege..."
2016-01-29 21:57:02 +05:30
su postgres -c "psql -c \"CREATE USER $user CREATEDB;\"" || {
exit 1
}
fi
2015-11-03 18:15:04 +05:30
# By default the gitlab_prodcution is not owned by gitlab user
echo "Make $user user owner of $dbname database..."
2016-01-29 21:57:02 +05:30
su postgres -c "psql -c \"ALTER DATABASE $dbname OWNER to $user;\"" || {
exit 1
}
echo "Grant all privileges to $user user..."
2016-01-29 22:24:20 +05:30
su postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE template1 to $user;\"" || {
exit 1
}
2016-06-02 21:00:27 +05:30
# enable the pg_trgm extension
su postgres -c "psql -d $dbname -c \"CREATE EXTENSION IF NOT EXISTS pg_trgm;\"" || {
2016-06-02 21:00:27 +05:30
exit 1
}