mirror of
https://github.com/YunoHost-Apps/ulogger_ynh.git
synced 2024-10-01 13:34:45 +02:00
Fix
This commit is contained in:
parent
68f84b91f9
commit
eb49af7335
6 changed files with 65 additions and 125 deletions
|
@ -39,10 +39,6 @@
|
|||
"example": "/ulogger",
|
||||
"default": "/ulogger"
|
||||
},
|
||||
{
|
||||
"name": "admin",
|
||||
"type": "user"
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
|
@ -59,8 +55,16 @@
|
|||
"en": "Choose the application language",
|
||||
"fr": "Choisissez la langue de l'application"
|
||||
},
|
||||
"choices": ["fr", "en", "pl", "de", "hu", "it" ],
|
||||
"choices": ["de", "en", "fr", "hu", "it", "pl"],
|
||||
"default": "en"
|
||||
},
|
||||
{
|
||||
"name": "admin",
|
||||
"type": "user"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"type": "password"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
YNH_PHP_VERSION="7.3"
|
||||
|
||||
pkg_dependencies="php${YNH_PHP_VERSION}-mysql"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
@ -17,86 +19,3 @@ YNH_PHP_VERSION="7.3"
|
|||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Send an email to inform the administrator
|
||||
#
|
||||
# usage: ynh_send_readme_to_admin app_message [recipients]
|
||||
# | arg: app_message - The message to send to the administrator.
|
||||
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
|
||||
# example: "root admin@domain"
|
||||
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
|
||||
# example: "root admin@domain user1 user2"
|
||||
ynh_send_readme_to_admin() {
|
||||
local app_message="${1:-...No specific information...}"
|
||||
local recipients="${2:-root}"
|
||||
|
||||
# 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
|
||||
recipients="$recipients $mail"
|
||||
else
|
||||
# But replace an user name without a domain after by its email
|
||||
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
|
||||
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
|
||||
|
||||
# Send the email to the recipients
|
||||
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
|
||||
}
|
||||
|
||||
ynh_smart_mktemp () {
|
||||
local min_size="${1:-300}"
|
||||
# Transform the minimum size from megabytes to kilobytes
|
||||
min_size=$(( $min_size * 1024 ))
|
||||
|
||||
# Check if there's enough free space in a directory
|
||||
is_there_enough_space () {
|
||||
local free_space=$(df --output=avail "$1" | sed 1d)
|
||||
test $free_space -ge $min_size
|
||||
}
|
||||
|
||||
if is_there_enough_space /tmp; then
|
||||
local tmpdir=/tmp
|
||||
elif is_there_enough_space /var; then
|
||||
local tmpdir=/var
|
||||
elif is_there_enough_space /; then
|
||||
local tmpdir=/
|
||||
elif is_there_enough_space /home; then
|
||||
local tmpdir=/home
|
||||
else
|
||||
ynh_die "Insufficient free space to continue..."
|
||||
fi
|
||||
|
||||
echo "$(mktemp --directory --tmpdir="$tmpdir")"
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ path_url=$YNH_APP_ARG_PATH
|
|||
admin=$YNH_APP_ARG_ADMIN
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
language=$YNH_APP_ARG_LANGUAGE
|
||||
password=$(ynh_string_random 12)
|
||||
password=$YNH_APP_ARG_PASSWORD
|
||||
admin_pwd=$(openssl passwd -1 -salt xyz $password)
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
|
@ -53,6 +54,13 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||
ynh_app_setting_set --app=$app --key=language --value=$language
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
|
@ -80,14 +88,6 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..."
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -97,6 +97,14 @@ ynh_script_progression --message="Configuring PHP-FPM..."
|
|||
ynh_add_fpm_config
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..."
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
|
@ -107,17 +115,15 @@ chown -R $app: $final_path
|
|||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||
|
||||
cp "../conf/config.php" "$final_path/config.php"
|
||||
ynh_add_config --template="../conf/config.php" --destination="$final_path/config.php"
|
||||
|
||||
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/config.php"
|
||||
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/config.php"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/config.php"
|
||||
chmod 400 "$final_path/config.php"
|
||||
chown $app:$app "$final_path/config.php"
|
||||
|
||||
ynh_replace_string --match_string="\$enabled = false;" --replace_string="\$enabled = true;" --target_file="$final_path/scripts/setup.php"
|
||||
|
||||
admin_pwd=$(openssl passwd -1 -salt xyz $password)
|
||||
|
||||
# Replace variables in SQL scripts
|
||||
ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="../conf/admin.sql"
|
||||
ynh_replace_string --match_string="__ADMIN_PWD__" --replace_string="$admin_pwd" --target_file="../conf/admin.sql"
|
||||
|
@ -126,6 +132,7 @@ ynh_replace_string --match_string="__ADMIN_PWD__" --replace_string="$admin_pwd"
|
|||
# SETUP APPLICATION WITH CURL
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Configuring SSOwat..."
|
||||
# Set the app as temporarily public for cURL call
|
||||
ynh_permission_update --permission="main" --add="visitors"
|
||||
|
||||
|
@ -137,9 +144,9 @@ ynh_script_progression --message="Finalizing installation..."
|
|||
ynh_local_curl "/scripts/setup.php" "command=setup"
|
||||
|
||||
#Add the admin account to the database
|
||||
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/admin.sql"
|
||||
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < "../conf/admin.sql"
|
||||
#Disable setup for security
|
||||
ynh_replace_string "^\$enabled = true;" "\$enabled = false;" "$final_path/scripts/setup.php"
|
||||
ynh_replace_string --match_string="^\$enabled = true;" --replace_string="\$enabled = false;" --target_file="$final_path/scripts/setup.php"
|
||||
|
||||
#=================================================
|
||||
# STORE THE CONFIG FILE CHECKSUM
|
||||
|
@ -169,6 +176,8 @@ ynh_script_progression --message="Configuring permissions..."
|
|||
# Make app public if necessary or protect it
|
||||
if [ $is_public -eq 0 ]
|
||||
then
|
||||
# Everyone can access the app.
|
||||
# The "main" permission is automatically created before the install script.
|
||||
ynh_permission_update --permission="main" --remove="visitors"
|
||||
fi
|
||||
|
||||
|
@ -179,21 +188,6 @@ ynh_script_progression --message="Reloading NGINX web server..."
|
|||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# SEND A README FOR THE ADMIN
|
||||
#=================================================
|
||||
|
||||
message=" $app was successfully installed :)
|
||||
|
||||
Please open your $app domain: https://$domain$path_url
|
||||
|
||||
The admin username is: $admin
|
||||
The admin password is: $password
|
||||
|
||||
If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/ulogger_ynh/issues"
|
||||
|
||||
ynh_send_readme_to_admin "$message"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
|
|
@ -53,6 +53,14 @@ ynh_script_progression --message="Removing PHP-FPM configuration"
|
|||
# Remove the dedicated php-fpm config
|
||||
ynh_remove_fpm_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies..."
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
|
|
@ -64,13 +64,12 @@ chmod -R o-rwx "$final_path"
|
|||
chown -R $app:www-data "$final_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the MySQL database..."
|
||||
ynh_script_progression --message="Reinstalling dependencies..."
|
||||
|
||||
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
|
@ -86,6 +85,15 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
|
|||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the MySQL database..."
|
||||
|
||||
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
|
|
@ -104,6 +104,13 @@ then
|
|||
ynh_secure_remove --file="$tmpdir"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..."
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue