mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
_common.sh tiny rewrite
This commit is contained in:
parent
c9b88d65be
commit
d3b14342bd
1 changed files with 16 additions and 16 deletions
|
@ -11,7 +11,7 @@
|
||||||
# | arg: pwd - the user password
|
# | arg: pwd - the user password
|
||||||
# | arg: db - the database to connect to
|
# | arg: db - the database to connect to
|
||||||
ynh_psql_connect_as() {
|
ynh_psql_connect_as() {
|
||||||
ynh_die "ynh_psql_connect_as is not yet implemented"
|
ynh_die "ynh_psql_connect_as is not yet implemented"
|
||||||
}
|
}
|
||||||
|
|
||||||
# # Execute a command as root user
|
# # Execute a command as root user
|
||||||
|
@ -20,7 +20,9 @@ ynh_psql_connect_as() {
|
||||||
# | arg: sql - the SQL command to execute
|
# | arg: sql - the SQL command to execute
|
||||||
# | arg: db - the database to connect to
|
# | arg: db - the database to connect to
|
||||||
ynh_psql_execute_as_root () {
|
ynh_psql_execute_as_root () {
|
||||||
su -c "psql" - postgres <<< ${1}
|
sql="$1"
|
||||||
|
db="$2"
|
||||||
|
psql "${db}" <<< "${sql}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute a command from a file as root user
|
# Execute a command from a file as root user
|
||||||
|
@ -29,7 +31,7 @@ ynh_psql_execute_as_root () {
|
||||||
# | arg: file - the file containing SQL commands
|
# | arg: file - the file containing SQL commands
|
||||||
# | arg: db - the database to connect to
|
# | arg: db - the database to connect to
|
||||||
ynh_psql_execute_file_as_root() {
|
ynh_psql_execute_file_as_root() {
|
||||||
ynh_die "ynh_psql_execute_file_as_root is not yet implemented"
|
ynh_die "ynh_psql_execute_file_as_root is not yet implemented"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a database and grant optionnaly privilegies to a user
|
# Create a database and grant optionnaly privilegies to a user
|
||||||
|
@ -37,16 +39,10 @@ ynh_psql_execute_file_as_root() {
|
||||||
# usage: ynh_psql_create_db db [user [pwd]]
|
# usage: ynh_psql_create_db db [user [pwd]]
|
||||||
# | arg: db - the database name to create
|
# | arg: db - the database name to create
|
||||||
# | arg: user - the user to grant privilegies
|
# | arg: user - the user to grant privilegies
|
||||||
# | arg: pwd - the password to identify user by
|
|
||||||
ynh_psql_create_db() {
|
ynh_psql_create_db() {
|
||||||
db=$1
|
db="$1"
|
||||||
# grant all privilegies to user
|
user="$2"
|
||||||
if [[ $# -gt 1 ]]; then
|
createdb --owner="${user}" "${db}"
|
||||||
ynh_psql_create_user ${2} "${3}"
|
|
||||||
su -c "createdb -O ${2} $db" - postgres
|
|
||||||
else
|
|
||||||
su -c "createdb $db" - postgres
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Drop a database
|
# Drop a database
|
||||||
|
@ -54,7 +50,8 @@ ynh_psql_create_db() {
|
||||||
# usage: ynh_psql_drop_db db
|
# usage: ynh_psql_drop_db db
|
||||||
# | arg: db - the database name to drop
|
# | arg: db - the database name to drop
|
||||||
ynh_psql_drop_db() {
|
ynh_psql_drop_db() {
|
||||||
su -c "dropdb ${1}" - postgres
|
db="$1"
|
||||||
|
dropdb "${db}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dump a database
|
# Dump a database
|
||||||
|
@ -65,7 +62,7 @@ ynh_psql_drop_db() {
|
||||||
# | arg: db - the database name to dump
|
# | arg: db - the database name to dump
|
||||||
# | ret: the psqldump output
|
# | ret: the psqldump output
|
||||||
ynh_psql_dump_db() {
|
ynh_psql_dump_db() {
|
||||||
ynh_die "ynh_psql_dump_db is not yet implemented"
|
ynh_die "ynh_psql_dump_db is not yet implemented"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,8 +72,10 @@ ynh_psql_dump_db() {
|
||||||
# | arg: user - the user name to create
|
# | arg: user - the user name to create
|
||||||
# | arg: pwd - the password to identify user by
|
# | arg: pwd - the password to identify user by
|
||||||
ynh_psql_create_user() {
|
ynh_psql_create_user() {
|
||||||
|
user="$1"
|
||||||
|
pwd="$2"
|
||||||
ynh_psql_execute_as_root \
|
ynh_psql_execute_as_root \
|
||||||
"CREATE USER ${1} WITH PASSWORD '${2}';"
|
"CREATE USER '${user}' WITH PASSWORD '${pwd}';"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Drop a user
|
# Drop a user
|
||||||
|
@ -84,5 +83,6 @@ ynh_psql_create_user() {
|
||||||
# usage: ynh_psql_drop_user user
|
# usage: ynh_psql_drop_user user
|
||||||
# | arg: user - the user name to drop
|
# | arg: user - the user name to drop
|
||||||
ynh_psql_drop_user() {
|
ynh_psql_drop_user() {
|
||||||
su -c "dropuser ${1}" - postgres
|
user="$1"
|
||||||
|
dropuser "${user}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue