2015-11-01 19:50:55 +05:30
|
|
|
#!/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
|
2015-11-03 18:04:55 +05:30
|
|
|
if ! su gitlab -s /bin/sh -c 'psql gitlab_production -c ""'
|
2015-11-01 19:50:55 +05:30
|
|
|
then
|
|
|
|
echo "Create $user user with create database privillege..."
|
|
|
|
sudo -u postgres 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
|
2015-11-01 19:50:55 +05:30
|
|
|
echo "Make $user user owner of $dbname database..."
|
|
|
|
sudo -u postgres psql -c "ALTER DATABASE $dbname OWNER to $user;" || {
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Grant all privileges to $user user..."
|
|
|
|
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE template1 to $user;"|| {
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|