From 9b6aaec88a0406337968f8147095a3ba299e8cb7 Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 14 Dec 2016 13:15:34 +0100 Subject: [PATCH] [fix] Give db creation right to odoo psql user --- scripts/_common.sh | 19 ++++++++++++++----- scripts/install | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5c77665..a673a1a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,19 +21,28 @@ PKGDIR=$(cd ../; pwd) # Common helpers # +# # Execute a command as root user +# +# usage: ynh_psql_execute_as_root sql [db] +# | arg: sql - the SQL command to execute +# | arg: db - the database to connect to +ynh_psql_execute_as_root () { + sudo su -c "psql" postgres <<< ${1} +} + # Create a user # -# usage: ynh_mysql_create_user user pwd [host] +# usage: ynh_psql_create_user user pwd [host] # | arg: user - the user name to create # | arg: pwd - the password to identify user by ynh_psql_create_user() { - sudo su -c "psql" postgres <<< \ + ynh_psql_execute_as_root \ "CREATE USER ${1} WITH PASSWORD '${2}';" } # Create a database and grant optionnaly privilegies to a user # -# usage: ynh_mysql_create_db db [user [pwd]] +# usage: ynh_psql_create_db db [user [pwd]] # | arg: db - the database name to create # | arg: user - the user to grant privilegies # | arg: pwd - the password to identify user by @@ -51,7 +60,7 @@ ynh_psql_create_db() { # Drop a database # -# usage: ynh_mysql_drop_db db +# usage: ynh_psql_drop_db db # | arg: db - the database name to drop ynh_psql_drop_db() { sudo su -c "dropdb ${1}" postgres @@ -59,7 +68,7 @@ ynh_psql_drop_db() { # Drop a user # -# usage: ynh_mysql_drop_user user +# usage: ynh_psql_drop_user user # | arg: user - the user name to drop ynh_psql_drop_user() { sudo su -c "dropuser ${1}" postgres diff --git a/scripts/install b/scripts/install index 294b8b4..8897538 100644 --- a/scripts/install +++ b/scripts/install @@ -76,6 +76,7 @@ else sudo rm -Rf $DESTDIR ynh_psql_create_db $APPNAME $APPNAME "$dbpass" + ynh_psql_execute_as_root "ALTER USER $APPNAME WITH CREATEDB;" # Set admin password # TODO Support @ in password