mirror of
https://github.com/YunoHost-Apps/moodle_ynh.git
synced 2024-09-03 19:46:23 +02:00
Fix for Yunohost 3
This commit is contained in:
parent
7642e9b15f
commit
58e96aa627
8 changed files with 212 additions and 193 deletions
|
@ -1 +1 @@
|
||||||
* * * * * /usr/bin/php7.1 YNH_DOMAIN/admin/cli/cron.php >/dev/null
|
* * * * * /usr/bin/php YNH_DOMAIN/admin/cli/cron.php >/dev/null
|
||||||
|
|
|
@ -30,7 +30,7 @@ group = __USER__
|
||||||
; specific port;
|
; specific port;
|
||||||
; '/path/to/unix/socket' - to listen on a unix socket.
|
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||||
; Note: This value is mandatory.
|
; Note: This value is mandatory.
|
||||||
listen = /var/run/php7.1-fpm-__NAMETOCHANGE__.sock
|
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
|
||||||
|
|
||||||
; Set listen(2) backlog. A value of '-1' means unlimited.
|
; Set listen(2) backlog. A value of '-1' means unlimited.
|
||||||
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
||||||
|
|
|
@ -12,58 +12,59 @@ ynh_delete_file_checksum () {
|
||||||
ynh_app_setting_delete $app $checksum_setting_name
|
ynh_app_setting_delete $app $checksum_setting_name
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_install_php7 () {
|
# Send an email to inform the administrator
|
||||||
|
|
||||||
ynh_package_update
|
|
||||||
ynh_package_install apt-transport-https --no-install-recommends
|
|
||||||
|
|
||||||
wget -q -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
|
|
||||||
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list
|
|
||||||
|
|
||||||
ynh_package_update
|
|
||||||
ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql php7.1-xmlrpc postgresql-9.4
|
|
||||||
sudo update-alternatives --install /usr/bin/php php /usr/bin/php5 70
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_remove_php7 () {
|
|
||||||
sudo rm -f /etc/apt/sources.list.d/php7.list
|
|
||||||
sudo apt-key del 4096R/89DF5277
|
|
||||||
sudo apt-key del 2048R/11A06851
|
|
||||||
ynh_remove_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql php7.1-xmlrpc postgresql-9.4
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Create a dedicated php-fpm config for php7.1
|
|
||||||
#
|
#
|
||||||
# usage: ynh_add_fpm_config
|
# usage: ynh_send_readme_to_admin app_message [recipients]
|
||||||
ynh_add_php7.1-fpm_config () {
|
# | arg: app_message - The message to send to the administrator.
|
||||||
finalphpconf="/etc/php/7.1/fpm/pool.d/$app.conf"
|
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
|
||||||
ynh_backup_if_checksum_is_different "$finalphpconf"
|
# example: "root admin@domain"
|
||||||
sudo cp ../conf/php-fpm.conf "$finalphpconf"
|
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
|
||||||
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
|
# example: "root admin@domain user1 user2"
|
||||||
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
|
ynh_send_readme_to_admin() {
|
||||||
ynh_replace_string "__USER__" "$app" "$finalphpconf"
|
local app_message="${1:-...No specific information...}"
|
||||||
sudo chown root: "$finalphpconf"
|
local recipients="${2:-root}"
|
||||||
ynh_store_file_checksum "$finalphpconf"
|
|
||||||
|
|
||||||
if [ -e "../conf/php-fpm.ini" ]
|
# Retrieve the email of users
|
||||||
|
find_mails () {
|
||||||
|
local list_mails="$1"
|
||||||
|
local mail
|
||||||
|
local recipients=" "
|
||||||
|
# Read each mail in argument
|
||||||
|
for mail in $list_mails
|
||||||
|
do
|
||||||
|
# Keep root or a real email address as it is
|
||||||
|
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
|
||||||
then
|
then
|
||||||
finalphpini="/etc/php/7.1/fpm/conf.d/20-$app.ini"
|
recipients="$recipients $mail"
|
||||||
ynh_backup_if_checksum_is_different "$finalphpini"
|
else
|
||||||
sudo cp ../conf/php-fpm.ini "$finalphpini"
|
# But replace an user name without a domain after by its email
|
||||||
sudo chown root: "$finalphpini"
|
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
|
||||||
ynh_store_file_checksum "$finalphpini"
|
then
|
||||||
|
recipients="$recipients $mail"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "$recipients"
|
||||||
|
}
|
||||||
|
recipients=$(find_mails "$recipients")
|
||||||
|
|
||||||
|
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` has important message for you"
|
||||||
|
|
||||||
|
local mail_message="This is an automated message from your beloved YunoHost server.
|
||||||
|
Specific information for the application $app.
|
||||||
|
$app_message
|
||||||
|
---
|
||||||
|
Automatic diagnosis data from YunoHost
|
||||||
|
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
|
||||||
|
|
||||||
|
# Define binary to use for mail command
|
||||||
|
if [ -e /usr/bin/bsd-mailx ]
|
||||||
|
then
|
||||||
|
local mail_bin=/usr/bin/bsd-mailx
|
||||||
|
else
|
||||||
|
local mail_bin=/usr/bin/mail.mailutils
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo systemctl reload php7.1-fpm
|
# Send the email to the recipients
|
||||||
}
|
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
|
||||||
|
|
||||||
|
|
||||||
# Remove the dedicated php-fpm config for php7.1
|
|
||||||
#
|
|
||||||
# usage: ynh_remove_fpm_config
|
|
||||||
ynh_remove_php7.1-fpm_config () {
|
|
||||||
ynh_secure_remove "/etc/php/7.1/fpm/pool.d/$app.conf"
|
|
||||||
ynh_secure_remove "/etc/php/7.1/fpm/conf.d/20-$app.ini" 2>&1
|
|
||||||
sudo systemctl reload php7.1-fpm
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ ! -e _common.sh ]; then
|
|
||||||
# Get the _common.sh file if it's not in the current directory
|
|
||||||
cp ../settings/scripts/_common.sh ./_common.sh
|
|
||||||
chmod a+rx _common.sh
|
|
||||||
fi
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source psql.sh
|
source psql.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
@ -19,6 +14,10 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
true
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
@ -52,8 +51,8 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
# BACKUP THE PHP-FPM CONFIGURATION
|
# BACKUP THE PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup "/etc/php/7.1/fpm/pool.d/$app.conf"
|
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
ynh_backup "/etc/php/7.1/fpm/conf.d/20-$app.ini"
|
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE PSQL DATABASE
|
# BACKUP THE PSQL DATABASE
|
||||||
|
@ -62,15 +61,8 @@ ynh_backup "/etc/php/7.1/fpm/conf.d/20-$app.ini"
|
||||||
ynh_psql_dump_db "$db_name" > db.sql
|
ynh_psql_dump_db "$db_name" > db.sql
|
||||||
ynh_backup "db.sql"
|
ynh_backup "db.sql"
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC BACKUP
|
# SPECIFIC BACKUP
|
||||||
#=================================================
|
|
||||||
# BACKUP LOGROTATE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_backup "/etc/logrotate.d/$app"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE CRON FILE
|
# BACKUP THE CRON FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -14,6 +14,10 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
true
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ ynh_app_setting_set $app is_public $is_public
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_install_php7
|
ynh_install_app_dependencies php-zip php-mysql php-xml php-intl php-mbstring php-gd php-curl php-soap php-pgsql php-xmlrpc postgresql-9.4
|
||||||
#=================================================
|
#=================================================
|
||||||
# Create postgresql database
|
# Create postgresql database
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -107,8 +111,19 @@ ynh_system_user_create $app
|
||||||
# PHP-FPM CONFIGURATION
|
# PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
### `ynh_add_fpm_config` is used to set up a PHP config.
|
||||||
|
### You can remove it if your app doesn't use PHP.
|
||||||
|
### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini
|
||||||
|
### If you're not using these lines:
|
||||||
|
### - You can remove these files in conf/.
|
||||||
|
### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script
|
||||||
|
### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script
|
||||||
|
### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script
|
||||||
|
### With the reload at the end of the script.
|
||||||
|
### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
|
||||||
|
|
||||||
# Create a dedicated php-fpm config
|
# Create a dedicated php-fpm config
|
||||||
ynh_add_php7.1-fpm_config
|
ynh_add_fpm_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
|
@ -133,7 +148,7 @@ ynh_store_file_checksum "$final_path/config.php"
|
||||||
|
|
||||||
# Create the home directory
|
# Create the home directory
|
||||||
mkdir -p $var_root
|
mkdir -p $var_root
|
||||||
chown -R $app:root $var_root
|
chown -R $app: $var_root
|
||||||
chmod -R 700 $var_root
|
chmod -R 700 $var_root
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -155,13 +170,6 @@ systemctl reload nginx
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown root: $final_path/config.php
|
chown root: $final_path/config.php
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SETUP LOGROTATE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Use logrotate to manage application logfile(s)
|
|
||||||
ynh_use_logrotate
|
|
||||||
|
|
||||||
|
|
||||||
# Set up poller
|
# Set up poller
|
||||||
sudo cp ../conf/cron /etc/cron.d/$app
|
sudo cp ../conf/cron /etc/cron.d/$app
|
||||||
|
|
216
scripts/psql.sh
216
scripts/psql.sh
|
@ -1,99 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
#
|
||||||
# POSTGRES HELPERS
|
# POSTGRES HELPERS
|
||||||
|
#
|
||||||
|
# Point of contact : Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Open a connection as a user
|
# Create a master password and set up global settings
|
||||||
|
# Please always call this script in install and restore scripts
|
||||||
#
|
#
|
||||||
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
|
# usage: ynh_psql_test_if_first_run
|
||||||
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_connect_as user pwd [db]
|
|
||||||
# | arg: user - the user name to connect as
|
|
||||||
# | arg: pwd - the user password
|
|
||||||
# | arg: db - the database to connect to
|
|
||||||
ynh_psql_connect_as() {
|
|
||||||
ynh_die "ynh_psql_connect_as is not yet implemented"
|
|
||||||
}
|
|
||||||
|
|
||||||
# # 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}
|
|
||||||
#TODO support db argument ?
|
|
||||||
}
|
|
||||||
|
|
||||||
# Execute a command from a file as root user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_execute_file_as_root file [db]
|
|
||||||
# | arg: file - the file containing SQL commands
|
|
||||||
# | arg: db - the database to connect to
|
|
||||||
ynh_psql_execute_file_as_root() {
|
|
||||||
file="$1"
|
|
||||||
db="$2"
|
|
||||||
su -c "psql $db" postgres < "$file"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create a database and grant optionnaly privilegies to a user
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
ynh_psql_create_db() {
|
|
||||||
db=$1
|
|
||||||
# grant all privilegies to user
|
|
||||||
if [[ $# -gt 1 ]]; then
|
|
||||||
ynh_psql_create_user ${2} "${3}"
|
|
||||||
sudo su -c "createdb -O ${2} $db" - postgres
|
|
||||||
else
|
|
||||||
sudo su -c "createdb $db" - postgres
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# Drop a database
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_drop_db db
|
|
||||||
# | arg: db - the database name to drop
|
|
||||||
ynh_psql_drop_db() {
|
|
||||||
sudo su -c "dropdb ${1}" - postgres
|
|
||||||
}
|
|
||||||
|
|
||||||
# Dump a database
|
|
||||||
#
|
|
||||||
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_dump_db db
|
|
||||||
# | arg: db - the database name to dump
|
|
||||||
# | ret: the psqldump output
|
|
||||||
ynh_psql_dump_db() {
|
|
||||||
db="$1"
|
|
||||||
su --command="pg_dump \"${db}\"" postgres
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Create a user
|
|
||||||
#
|
|
||||||
# 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() {
|
|
||||||
ynh_psql_execute_as_root \
|
|
||||||
"CREATE USER ${1} WITH PASSWORD '${2}';"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Drop a user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_drop_user user
|
|
||||||
# | arg: user - the user name to drop
|
|
||||||
ynh_psql_drop_user() {
|
|
||||||
sudo su -c "dropuser ${1}" - postgres
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_psql_test_if_first_run() {
|
ynh_psql_test_if_first_run() {
|
||||||
if [ -f /etc/yunohost/psql ];
|
if [ -f /etc/yunohost/psql ];
|
||||||
|
@ -115,11 +32,128 @@ ynh_psql_test_if_first_run() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
systemctl start postgresql
|
systemctl start postgresql
|
||||||
su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres
|
sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres
|
||||||
# we can't use peer since YunoHost create users with nologin
|
|
||||||
|
# force all user to connect to local database using passwords
|
||||||
|
# https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF
|
||||||
|
# Note: we can't use peer since YunoHost create users with nologin
|
||||||
|
# See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user
|
||||||
sed -i '/local\s*all\s*all\s*peer/i \
|
sed -i '/local\s*all\s*all\s*peer/i \
|
||||||
local all all password' "$pg_hba"
|
local all all password' "$pg_hba"
|
||||||
systemctl enable postgresql
|
systemctl enable postgresql
|
||||||
systemctl reload postgresql
|
systemctl reload postgresql
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Open a connection as a user
|
||||||
|
#
|
||||||
|
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
|
||||||
|
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_connect_as user pwd [db]
|
||||||
|
# | arg: user - the user name to connect as
|
||||||
|
# | arg: pwd - the user password
|
||||||
|
# | arg: db - the database to connect to
|
||||||
|
ynh_psql_connect_as() {
|
||||||
|
user="$1"
|
||||||
|
pwd="$2"
|
||||||
|
db="$3"
|
||||||
|
sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db"
|
||||||
|
}
|
||||||
|
|
||||||
|
# # 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 () {
|
||||||
|
sql="$1"
|
||||||
|
sudo --login --user=postgres psql <<< "$sql"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute a command from a file as root user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_execute_file_as_root file [db]
|
||||||
|
# | arg: file - the file containing SQL commands
|
||||||
|
# | arg: db - the database to connect to
|
||||||
|
ynh_psql_execute_file_as_root() {
|
||||||
|
file="$1"
|
||||||
|
db="$2"
|
||||||
|
sudo --login --user=postgres psql "$db" < "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a database, an user and its password. Then store the password in the app's config
|
||||||
|
#
|
||||||
|
# After executing this helper, the password of the created database will be available in $db_pwd
|
||||||
|
# It will also be stored as "psqlpwd" into the app settings.
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_setup_db user name [pwd]
|
||||||
|
# | arg: user - Owner of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
# | arg: pwd - Password of the database. If not given, a password will be generated
|
||||||
|
ynh_psql_setup_db () {
|
||||||
|
db_user="$1"
|
||||||
|
db_name="$2"
|
||||||
|
new_db_pwd=$(ynh_string_random) # Generate a random password
|
||||||
|
# If $3 is not given, use new_db_pwd instead for db_pwd.
|
||||||
|
db_pwd="${3:-$new_db_pwd}"
|
||||||
|
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
|
||||||
|
ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a database and grant privilegies to a user
|
||||||
|
#
|
||||||
|
# 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 user password
|
||||||
|
ynh_psql_create_db() {
|
||||||
|
db="$1"
|
||||||
|
user="$2"
|
||||||
|
pwd="$3"
|
||||||
|
ynh_psql_create_user "$user" "$pwd"
|
||||||
|
sudo --login --user=postgres createdb --owner="$user" "$db"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop a database
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_drop_db db
|
||||||
|
# | arg: db - the database name to drop
|
||||||
|
# | arg: user - the user to drop
|
||||||
|
ynh_psql_remove_db() {
|
||||||
|
db="$1"
|
||||||
|
user="$2"
|
||||||
|
sudo --login --user=postgres dropdb "$db"
|
||||||
|
ynh_psql_drop_user "$user"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Dump a database
|
||||||
|
#
|
||||||
|
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_dump_db db
|
||||||
|
# | arg: db - the database name to dump
|
||||||
|
# | ret: the psqldump output
|
||||||
|
ynh_psql_dump_db() {
|
||||||
|
db="$1"
|
||||||
|
sudo --login --user=postgres pg_dump "$db"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Create a user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_create_user user pwd [host]
|
||||||
|
# | arg: user - the user name to create
|
||||||
|
ynh_psql_create_user() {
|
||||||
|
user="$1"
|
||||||
|
pwd="$2"
|
||||||
|
sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop a user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_drop_user user
|
||||||
|
# | arg: user - the user name to drop
|
||||||
|
ynh_psql_drop_user() {
|
||||||
|
user="$1"
|
||||||
|
sudo --login --user=postgres dropuser "$user"
|
||||||
|
|
|
@ -29,7 +29,6 @@ final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
# Remove metapackage and its dependencies
|
# Remove metapackage and its dependencies
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_app_dependencies
|
||||||
ynh_remove_php7
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE psql DATABASE
|
# REMOVE THE psql DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -53,18 +52,11 @@ ynh_secure_remove "$final_path"
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE PHP-FPM CONFIGURATION for php7.1
|
# REMOVE PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove the dedicated php-fpm config
|
# Remove the dedicated php-fpm config
|
||||||
ynh_remove_php7.1-fpm_config
|
ynh_remove_fpm_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Remove the app-specific logrotate config
|
|
||||||
ynh_remove_logrotate
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC REMOVE
|
# SPECIFIC REMOVE
|
||||||
|
|
|
@ -5,12 +5,6 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ ! -e _common.sh ]; then
|
|
||||||
# Get the _common.sh file if it's not in the current directory
|
|
||||||
cp ../settings/scripts/_common.sh ./_common.sh
|
|
||||||
chmod a+rx _common.sh
|
|
||||||
fi
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source psql.sh
|
source psql.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
@ -19,6 +13,10 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
true
|
||||||
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
@ -82,15 +80,15 @@ ynh_system_user_create $app
|
||||||
chown -R $app: $final_path
|
chown -R $app: $final_path
|
||||||
chown -R root: $final_path/config.php
|
chown -R root: $final_path/config.php
|
||||||
mkdir -p $var_root
|
mkdir -p $var_root
|
||||||
chown -R $app:root $var_root
|
chown -R $app: $var_root
|
||||||
chmod -R 700 $var_root
|
chmod -R 700 $var_root
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE PHP-FPM CONFIGURATION
|
# RESTORE THE PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore_file "/etc/php/7.1/pool.d/$app.conf"
|
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
ynh_restore_file "/etc/php/7.1/conf.d/20-$app.ini"
|
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC RESTORATION
|
# SPECIFIC RESTORATION
|
||||||
|
@ -99,7 +97,7 @@ ynh_restore_file "/etc/php/7.1/conf.d/20-$app.ini"
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Define and install dependencies
|
# Define and install dependencies
|
||||||
ynh_install_php7
|
ynh_install_app_dependencies php-zip php-mysql php-xml php-intl php-mbstring php-gd php-curl php-soap php-pgsql php-xmlrpc postgresql-9.4
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE CRON FILE
|
# RESTORE THE CRON FILE
|
||||||
|
@ -107,17 +105,11 @@ ynh_install_php7
|
||||||
|
|
||||||
ynh_restore_file "/etc/cron.d/$app"
|
ynh_restore_file "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE LOGROTATE CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_restore_file "/etc/logrotate.d/$app"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX AND PHP-FPM
|
# RELOAD NGINX AND PHP-FPM
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl reload php7.1-fpm
|
systemctl reload php5-fpm
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
|
|
Loading…
Reference in a new issue