1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

finish postgresql integration

This commit is contained in:
jean-baptiste 2017-09-20 03:26:27 +02:00
parent 64fa488a6b
commit 0c17af017f
3 changed files with 19 additions and 10 deletions

View file

@ -11,8 +11,11 @@ ynh_psql_test_if_first_run() {
echo "$pgsql" >> /etc/yunohost/psql echo "$pgsql" >> /etc/yunohost/psql
systemctl start postgresql systemctl start postgresql
sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'" sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'"
# we can't use peer since YunoHost create users with nologin
sed -i '/local\s*all\s*all\s*peer/i \
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
systemctl enable postgresql systemctl enable postgresql
systemctl start postgresql systemctl reload postgresql
fi fi
} }
@ -29,7 +32,7 @@ ynh_psql_connect_as() {
user="$1" user="$1"
pwd="$2" pwd="$2"
db="$3" db="$3"
su "${user}" -c "psql \"${db}\"" sudo -u postgres PGUSER="${user}" PGPASSWORD="${pwd}" psql "${db}"
} }
# # Execute a command as root user # # Execute a command as root user
@ -39,7 +42,7 @@ ynh_psql_connect_as() {
# | arg: db - the database to connect to # | arg: db - the database to connect to
ynh_psql_execute_as_root () { ynh_psql_execute_as_root () {
sql="$1" sql="$1"
su postgres -c "psql <<< \"$sql\"" sudo -u postgres psql <<< "$sql"
} }
# Execute a command from a file as root user # Execute a command from a file as root user
@ -50,7 +53,7 @@ ynh_psql_execute_as_root () {
ynh_psql_execute_file_as_root() { ynh_psql_execute_file_as_root() {
file="$1" file="$1"
db="$2" db="$2"
ynh_psql_connect_as "postgres" "$db" "$(cat /etc/yunohost/pgsql)" <<< "$file" sudo -u postgres psql "$db" <<< "$file"
} }
# Create a database, an user and its password. Then store the password in the app's config # Create a database, an user and its password. Then store the password in the app's config
@ -84,16 +87,19 @@ ynh_psql_create_db() {
user="$2" user="$2"
pwd="$3" pwd="$3"
ynh_psql_create_user "$user" "$pwd" ynh_psql_create_user "$user" "$pwd"
su postgres -c "createdb --owner=\"${user}\" \"${db}\"" sudo -u postgres createdb --owner="${user}" "${db}"
} }
# Drop a database # Drop a database
# #
# 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
# | arg: user - the user to drop
ynh_psql_remove_db() { ynh_psql_remove_db() {
db="$1" db="$1"
su postgres -c "dropdb \"${db}\"" user="$2"
sudo -u postgres dropdb "${db}"
ynh_psql_drop_user "${user}"
} }
# Dump a database # Dump a database
@ -105,7 +111,7 @@ ynh_psql_remove_db() {
# | ret: the psqldump output # | ret: the psqldump output
ynh_psql_dump_db() { ynh_psql_dump_db() {
db="$1" db="$1"
su postgres -c "pg_dump \"${db}\"" sudo -u postgres pg_dump "${db}"
} }
@ -115,7 +121,8 @@ ynh_psql_dump_db() {
# | arg: user - the user name to create # | arg: user - the user name to create
ynh_psql_create_user() { ynh_psql_create_user() {
user="$1" user="$1"
su postgres -c "createuser \"${user}\"" pwd="$2"
sudo -u postgres psql -c"CREATE USER ${user} WITH PASSWORD '${pwd}'"
} }
# Drop a user # Drop a user
@ -124,5 +131,5 @@ ynh_psql_create_user() {
# | arg: user - the user name to drop # | arg: user - the user name to drop
ynh_psql_drop_user() { ynh_psql_drop_user() {
user="$1" user="$1"
su postgres -c "dropuser \"${user}\"" sudo -u postgres dropuser "${user}"
} }

View file

@ -170,9 +170,11 @@ ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7
#========================================== #==========================================
( (
set +eu set +eu
su - weblate
source "${final_path}/venv/bin/activate" source "${final_path}/venv/bin/activate"
export DJANGO_SETTINGS_MODULE="weblate.settings" export DJANGO_SETTINGS_MODULE="weblate.settings"
cd "${final_path}" cd "${final_path}"
# the user needs to be weblate for postgresql
weblate migrate --noinput weblate migrate --noinput
# generate static files # generate static files
weblate collectstatic --noinput weblate collectstatic --noinput

View file

@ -41,7 +41,7 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_psql_remove_db $db_name $db_name ynh_psql_remove_db $db_name $app
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR