From 22621f124273e23d1d33e9ed42e40f3d6a9fe068 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?E=CC=81ric=20Gaspar?=
<46165813+ericgaspar@users.noreply.github.com>
Date: Sun, 23 Jun 2024 08:54:47 +0200
Subject: [PATCH] cleaning
---
.gitignore | 3 +++
conf/extra_php-fpm.conf | 4 ----
conf/nginx.conf | 2 +-
config_panel.toml.example | 30 -----------------------
manifest.toml | 1 +
scripts/_common.sh | 16 ++-----------
scripts/backup | 23 ++++++------------
scripts/change_url | 12 +++-------
scripts/config | 36 +++++++++++-----------------
scripts/install | 37 +++++++++++++----------------
scripts/remove | 14 ++++-------
scripts/restore | 30 +++++++++--------------
scripts/upgrade | 50 ++++++++++++++++++---------------------
13 files changed, 85 insertions(+), 173 deletions(-)
create mode 100644 .gitignore
delete mode 100644 conf/extra_php-fpm.conf
delete mode 100644 config_panel.toml.example
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8f144f3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+*.sw[op]
+.DS_Store
diff --git a/conf/extra_php-fpm.conf b/conf/extra_php-fpm.conf
deleted file mode 100644
index 700c37c..0000000
--- a/conf/extra_php-fpm.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-; Additional php.ini defines, specific to this pool of workers.
-
-php_admin_value[upload_max_filesize] = 50M
-php_admin_value[post_max_size] = 50M
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 421381a..093627a 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -21,7 +21,7 @@ location __PATH__/ {
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
- fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
+ fastcgi_pass unix:/var/run/php/php__PHP_VERSION__-fpm-__APP__.sock;
fastcgi_index index.php;
include fastcgi_params;
diff --git a/config_panel.toml.example b/config_panel.toml.example
deleted file mode 100644
index 576a87d..0000000
--- a/config_panel.toml.example
+++ /dev/null
@@ -1,30 +0,0 @@
-version = "1.0"
-
-[main]
-name = "2FAuth configuration"
-
- [main.php_fpm_config]
- name = "PHP-FPM configuration"
-
- [main.php_fpm_config.fpm_footprint]
- ask = "Memory footprint"
- type = "select"
- choices.low = "Low, <= 20Mb per pool"
- choices.medium = "Medium, between 20Mb and 40Mb per pool"
- choices.high = "High, > 40Mb per pool"
- choices.specific = "Use specific value"
- default = "low"
-
- [main.php_fpm_config.fpm_free_footprint]
- visible = "fpm_footprint == 'specific'"
- ask = "Memory footprint of the service?"
- type = "number"
- default = "0"
- help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values."
-
- [main.php_fpm_config.fpm_usage]
- ask = "Expected usage"
- type = "select"
- choices = ["low", "medium", "high"]
- default = "low"
- help = "low: Personal usage, behind the SSO. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
diff --git a/manifest.toml b/manifest.toml
index 6a82ade..51f863f 100644
--- a/manifest.toml
+++ b/manifest.toml
@@ -17,6 +17,7 @@ code = "https://github.com/Bubka/2FAuth"
[integration]
yunohost = ">= 11.2"
+helpers_version = "2.1"
architectures = "all"
multi_instance = true
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 6381490..f50f88a 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -1,20 +1,8 @@
#!/bin/bash
#=================================================
-# COMMON VARIABLES
+# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
# Composer version
-YNH_COMPOSER_VERSION="2.7.7"
-
-#=================================================
-# PERSONAL HELPERS
-#=================================================
-
-#=================================================
-# EXPERIMENTAL HELPERS
-#=================================================
-
-#=================================================
-# FUTURE OFFICIAL HELPERS
-#=================================================
+composer_version="2.7.7"
diff --git a/scripts/backup b/scripts/backup
index b231a48..a673ffa 100755
--- a/scripts/backup
+++ b/scripts/backup
@@ -1,42 +1,33 @@
#!/bin/bash
-#=================================================
-# GENERIC START
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# DECLARE DATA AND CONF FILES TO BACKUP
-#=================================================
-ynh_print_info --message="Declaring files to be backed up..."
+ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
-ynh_backup --src_path="$install_dir"
+ynh_backup "$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
-ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
+ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
-ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
+ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
-ynh_print_info --message="Backing up the MySQL database..."
+ynh_print_info "Backing up the MySQL database..."
-ynh_mysql_dump_db --database="$db_name" > db.sql
+ynh_mysql_dump_db > db.sql
#=================================================
# END OF SCRIPT
#=================================================
-ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
+ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
diff --git a/scripts/change_url b/scripts/change_url
index ab2d658..2678882 100644
--- a/scripts/change_url
+++ b/scripts/change_url
@@ -1,22 +1,16 @@
#!/bin/bash
-#=================================================
-# GENERIC STARTING
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source /usr/share/yunohost/helpers
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
-ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
+ynh_script_progression "Updating NGINX web server configuration..."
-ynh_change_url_nginx_config
+ynh_config_change_url_nginx
#=================================================
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Change of URL completed for $app" --last
+ynh_script_progression "Change of URL completed for $app"
diff --git a/scripts/config b/scripts/config
index 91c2de7..37ef177 100644
--- a/scripts/config
+++ b/scripts/config
@@ -1,11 +1,5 @@
#!/bin/bash
-#=================================================
-# GENERIC STARTING
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source _common.sh
source /usr/share/yunohost/helpers
@@ -15,8 +9,8 @@ ynh_abort_if_errors
# RETRIEVE ARGUMENTS
#=================================================
-phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
-current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+php_version=$(ynh_app_setting_get --key=php_version)
+current_fpm_footprint=$(ynh_app_setting_get --key=fpm_footprint)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
@@ -49,37 +43,35 @@ get__free_footprint() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
-set__fpm_footprint() {
- if [ "$fpm_footprint" != "specific" ]
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | set__fpm_footprint() {
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" != "specific" ]
then
- ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value="$fpm_footprint"
fi
}
-set__fpm_free_footprint() {
- if [ "$fpm_footprint" = "specific" ]
+# REMOVEME ? Everything about fpm_free_footprint is removed in helpers2.1... | set__fpm_free_footprint() {
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ]
then
- ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint"
+# REMOVEME ? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value="$fpm_free_footprint"
fi
}
-#=================================================
-# GENERIC FINALIZATION
#=================================================
ynh_app_config_validate() {
_ynh_app_config_validate
if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then
- # If fpm_footprint is set to 'specific', use $fpm_free_footprint value.
- if [ "$fpm_footprint" = "specific" ]
+# REMOVEME ? Everything about fpm_free_footprint is removed in helpers2.1... | # If fpm_footprint is set to 'specific', use $fpm_free_footprint value.
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ]
then
- fpm_footprint=$fpm_free_footprint
+# REMOVEME ? Everything about fpm_free_footprint is removed in helpers2.1... | fpm_footprint=$fpm_free_footprint
fi
- if [ "$fpm_footprint" == "0" ]
+# REMOVEME ? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" == "0" ]
then
- ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
+ ynh_print_warn "When selecting 'specific', you have to set a footprint value into the field below."
exit 0
fi
@@ -89,7 +81,7 @@ ynh_app_config_validate() {
ynh_app_config_apply() {
_ynh_app_config_apply
- ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
+ ynh_config_add_phpfpm
}
ynh_app_config_run $1
diff --git a/scripts/install b/scripts/install
index 42f837a..cbf80d4 100755
--- a/scripts/install
+++ b/scripts/install
@@ -1,11 +1,5 @@
#!/bin/bash
-#=================================================
-# GENERIC START
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source _common.sh
source /usr/share/yunohost/helpers
@@ -21,12 +15,12 @@ email=$(ynh_user_get_info --username=$admin --key=mail)
# key for the .env __KEY__
key=$(ynh_string_random --length=45 | base64)
-ynh_app_setting_set --app=$app --key=key --value=$key
+ynh_app_setting_set --key=key --value=$key
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
-ynh_script_progression --message="Setting up source files..." --weight=1
+ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
@@ -37,26 +31,27 @@ chown -R $app:www-data "$install_dir"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
-ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
+ynh_script_progression "Configuring PHP-FPM..."
-ynh_add_fpm_config
+ynh_config_add_phpfpm
-ynh_add_nginx_config
+ynh_config_add_nginx
#=================================================
# INSTALL 2FAUTH WITH COMPOSER
#=================================================
-ynh_script_progression --message="Installing $app with Composer..." --weight=15
+ynh_script_progression "Installing $app with Composer..."
-ynh_install_composer --install_args="--prefer-dist --no-scripts --no-dev"
+ynh_composer_install
+ynh_composer_exec install --no-dev --prefer-dist --no-scripts --no-dev
#=================================================
# ADD A CONFIGURATION
#=================================================
-ynh_script_progression --message="Adding a configuration file..." --weight=1
+ynh_script_progression "Adding $app's configuration..."
# Setup application config
-ynh_add_config --template=".env" --destination="$install_dir/.env"
+ynh_config_add --template=".env" --destination="$install_dir/.env"
chmod 640 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
@@ -64,14 +59,14 @@ chown $app:$app "$install_dir/.env"
#=================================================
# BUILDING
#=================================================
-ynh_script_progression --message="Building $app..." --weight=10
+ynh_script_progression "Building $app..."
# Setup application config
pushd $install_dir
- php$phpversion artisan migrate:refresh -n
- php$phpversion artisan passport:install -n
- php$phpversion artisan storage:link -n
- php$phpversion artisan config:cache -n
+ php$php_version artisan migrate:refresh -n
+ php$php_version artisan passport:install -n
+ php$php_version artisan storage:link -n
+ php$php_version artisan config:cache -n
popd
chmod 775 "$install_dir"
@@ -82,4 +77,4 @@ chown -R $app:www-data "$install_dir"
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Installation of $app completed" --last
+ynh_script_progression "Installation of $app completed"
diff --git a/scripts/remove b/scripts/remove
index 5a4ee64..de1a1fe 100755
--- a/scripts/remove
+++ b/scripts/remove
@@ -1,26 +1,20 @@
#!/bin/bash
-#=================================================
-# GENERIC START
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
+ynh_script_progression "Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
-ynh_remove_nginx_config
+ynh_config_remove_nginx
-ynh_remove_fpm_config
+ynh_config_remove_phpfpm
#=================================================
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Removal of $app completed" --last
+ynh_script_progression "Removal of $app completed"
diff --git a/scripts/restore b/scripts/restore
index d5a04cd..a0c5cd2 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -1,11 +1,5 @@
#!/bin/bash
-#=================================================
-# GENERIC START
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
@@ -13,9 +7,9 @@ source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
-ynh_script_progression --message="Restoring the app main directory..." --weight=1
+ynh_script_progression "Restoring the app main directory..."
-ynh_restore_file --origin_path="$install_dir"
+ynh_restore "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
@@ -23,32 +17,30 @@ chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
-ynh_script_progression --message="Restoring the MySQL database..." --weight=1
+ynh_script_progression "Restoring the MySQL database..."
-ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
+ynh_mysql_db_shell < ./db.sql
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
-ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
+ynh_script_progression "Restoring system configurations related to $app..."
-ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
+ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf"
-ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
+ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
-#=================================================
-# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
-ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
+ynh_script_progression "Reloading NGINX web server and $app's service..."
-ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
+ynh_systemctl --service=php$php_version-fpm --action=reload
-ynh_systemd_action --service_name=nginx --action=reload
+ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Restoration completed for $app" --last
+ynh_script_progression "Restoration completed for $app"
diff --git a/scripts/upgrade b/scripts/upgrade
index df01501..0325e1d 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -1,31 +1,26 @@
#!/bin/bash
-#=================================================
-# GENERIC START
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
-ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
+ynh_script_progression "Ensuring downward compatibility..."
+# FIXME: maybe replace with: ynh_app_setting_set_default --key=key --value=$(ynh_string_random --length=45 | base64)
if [ -z "${key:-}" ]; then
key=$(ynh_string_random --length=45 | base64)
- ynh_app_setting_set --app=$app --key=key --value=$key
+ ynh_app_setting_set --key=key --value=$key
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
-ynh_script_progression --message="Upgrading source files..." --weight=3
+ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
-ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="public/storage storage .env"
+ynh_setup_source --dest_dir="$install_dir" --full_replace --keep="public/storage storage .env"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
@@ -33,19 +28,19 @@ chown -R $app:www-data "$install_dir"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
-ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
+ynh_script_progression "Upgrading PHP-FPM configuration..."
-ynh_add_fpm_config
+ynh_config_add_phpfpm
-ynh_add_nginx_config
+ynh_config_add_nginx
#=================================================
# ADD A CONFIGURATION
#=================================================
-ynh_script_progression --message="Upgrading a configuration file..." --weight=1
+ynh_script_progression "Upgrading a configuration file..."
# Setup application config
-ynh_add_config --template=".env" --destination="$install_dir/.env"
+ynh_config_add --template=".env" --destination="$install_dir/.env"
chmod 640 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
@@ -53,31 +48,32 @@ chown $app:$app "$install_dir/.env"
#=================================================
# INSTALL 2FAUTH WITH COMPOSER
#=================================================
-ynh_script_progression --message="Installing $app with Composer..." --weight=15
+ynh_script_progression "Installing $app with Composer..."
-ynh_secure_remove --file=$install_dir/package-lock.json
+ynh_safe_rm $install_dir/package-lock.json
-ynh_install_composer --install_args="--ignore-platform-reqs --prefer-dist --no-scripts --no-dev"
+ynh_composer_install
+ynh_composer_exec install --no-dev --ignore-platform-reqs --prefer-dist --no-scripts --no-dev
#=================================================
# BUILDING
#=================================================
-ynh_script_progression --message="Building..." --weight=10
+ynh_script_progression "Building..."
-ynh_exec_warn_less ynh_composer_exec --commands="update"
+ynh_composer_exec update
# Setup application config
pushd $install_dir
- php$phpversion artisan cache:clear
- php$phpversion artisan config:clear
- php$phpversion artisan migrate -n
- php$phpversion artisan passport:install -n
- php$phpversion artisan config:cache -n
- php$phpversion artisan route:cache
+ php$php_version artisan cache:clear
+ php$php_version artisan config:clear
+ php$php_version artisan migrate -n
+ php$php_version artisan passport:install -n
+ php$php_version artisan config:cache -n
+ php$php_version artisan route:cache
popd
#=================================================
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Upgrade of $app completed" --last
+ynh_script_progression "Upgrade of $app completed"