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

postgressql finition

This commit is contained in:
jean-baptiste 2017-09-19 19:00:11 +02:00
parent ce19b2bbd9
commit 64fa488a6b
3 changed files with 21 additions and 24 deletions

View file

@ -3,15 +3,16 @@
ynh_psql_test_if_first_run() { ynh_psql_test_if_first_run() {
if [ -f /etc/yunohost/pgsql ]; if [ -f /etc/yunohost/psql ];
then then
echo "Postgresql is already installed, no need to create master password" echo "PostgreSQL is already installed, no need to create master password"
else else
pgsql=$(ynh_string_random) pgsql=$(ynh_string_random)
echo "$pgsql" >> /etc/yunohost/pgsql echo "$pgsql" >> /etc/yunohost/psql
psql postgres -c "\\password postgres" < echo "$pgsql" systemctl start postgresql
systemctl service enable postgres sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'"
systemctl service start postgres systemctl enable postgresql
systemctl start postgresql
fi fi
} }
@ -28,7 +29,7 @@ ynh_psql_connect_as() {
user="$1" user="$1"
pwd="$2" pwd="$2"
db="$3" db="$3"
psql "${db}" --username="${user}" --password < echo "${pwd}" su "${user}" -c "psql \"${db}\""
} }
# # Execute a command as root user # # Execute a command as root user
@ -38,8 +39,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"
db="$2" su postgres -c "psql <<< \"$sql\""
psql "${db}" --username="postgres" <<< "${sql}"
} }
# Execute a command from a file as root user # Execute a command from a file as root user
@ -84,16 +84,16 @@ ynh_psql_create_db() {
user="$2" user="$2"
pwd="$3" pwd="$3"
ynh_psql_create_user "$user" "$pwd" ynh_psql_create_user "$user" "$pwd"
createdb --owner="${user}" "${db}" su postgres -c "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
ynh_psql_drop_db() { ynh_psql_remove_db() {
db="$1" db="$1"
dropdb "${db}" su postgres -c "dropdb \"${db}\""
} }
# Dump a database # Dump a database
@ -105,7 +105,7 @@ ynh_psql_drop_db() {
# | ret: the psqldump output # | ret: the psqldump output
ynh_psql_dump_db() { ynh_psql_dump_db() {
db="$1" db="$1"
pg_dump "${db}" su postgres -c "pg_dump \"${db}\""
} }
@ -113,12 +113,9 @@ ynh_psql_dump_db() {
# #
# usage: ynh_psql_create_user user pwd [host] # usage: ynh_psql_create_user user pwd [host]
# | arg: user - the user name to create # | arg: user - the user name to create
# | arg: pwd - the password to identify user by
ynh_psql_create_user() { ynh_psql_create_user() {
user="$1" user="$1"
pwd="$2" su postgres -c "createuser \"${user}\""
ynh_psql_execute_as_root \
"CREATE USER '${user}' WITH PASSWORD '${pwd}';"
} }
# Drop a user # Drop a user
@ -127,5 +124,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"
dropuser "${user}" su postgres -c "dropuser \"${user}\""
} }

View file

@ -73,7 +73,7 @@ ynh_app_setting_set "$app" is_public "$is_public"
ynh_install_app_dependencies libxml2-dev libxslt-dev libfreetype6-dev \ ynh_install_app_dependencies libxml2-dev libxslt-dev libfreetype6-dev \
libjpeg-dev libz-dev libyaml-dev python-dev python-pip python-virtualenv \ libjpeg-dev libz-dev libyaml-dev python-dev python-pip python-virtualenv \
postgresql python-psycopg2 uwsgi postgresql libpq-dev uwsgi
#================================================= #=================================================
# CREATE A PostgreSQL DATABASE # CREATE A PostgreSQL DATABASE
@ -86,9 +86,9 @@ db_user_pwd=$(ynh_string_random)
# Initialize database and store postgres password for upgrade # Initialize database and store postgres password for upgrade
ynh_psql_create_db "$db_name" "$app" "$db_user_pwd" ynh_psql_create_db "$db_name" "$app" "$db_user_pwd"
ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set "$app" psqlpwd "$db_pwd" ynh_app_setting_set "$app" psqlpwd "$db_user_pwd"
systemctl reload postgres systemctl reload postgresql
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -140,7 +140,7 @@ virtualenv "${final_path}/venv"
set +eu set +eu
source "${final_path}/venv/bin/activate" source "${final_path}/venv/bin/activate"
"${final_path}/venv/bin/pip" install Weblate==2.16 "${final_path}/venv/bin/pip" install Weblate==2.16
"${final_path}/venv/bin/pip" install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns "${final_path}/venv/bin/pip" install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns psycopg2
) )
#================================================= #=================================================

View file

@ -37,11 +37,11 @@ fi
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE THE MYSQL DATABASE # REMOVE THE PostgreSQL DATABASE
#================================================= #=================================================
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_name $db_name ynh_psql_remove_db $db_name $db_name
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR