diff --git a/README.md b/README.md index 288724b..13325a5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to [Piwigo](http://piwigo.org) is a photo gallery software for the web, built by an active community of users and developers. Extensions make Piwigo easily customizable. -**Shipped version:** 11.3.0 +**Shipped version:** 11.5.0~ynh1 ## Screenshots diff --git a/YEP.md b/YEP.md deleted file mode 100644 index 779d381..0000000 --- a/YEP.md +++ /dev/null @@ -1,118 +0,0 @@ -#### [Level 0](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-0) -[YEP 1.1 - Nommer son app et son dépot](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) -`Validated` -[YEP 1.2 - Inscrire l'app sur un "répertoire" connu](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-12) -`Validated` - -#### [Level 1](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-1) -[YEP 2.2 - Utiliser bash pour les scripts principaux](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-22) -`Validated` -[YEP 2.5 - Copier correctement des fichiers](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-25) -`Don't know` -[YEP 2.7 - Donner des permissions suffisantes aux instructions bash](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-27) -`Validated` -[YEP 2.15 - Suivre les instructions d'installation de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-215) -`Validated` - -#### [Level 2](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-2) -[YEP 1.5 - Mettre à jour régulièrement le statut de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) -`Validated` -[YEP 2.18.2 - Gérer l'installation à la racine d’un nom de domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2182) -`Validated` - *Automatically verified.* -[YEP 2.18.3 - Gérer l'installation sur un sous-domaine](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2183) -`Validated` - *Automatically verified.* -[YEP 2.18.4 - Gérer l'installation sur un chemin /path](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2184) -`Validated` - *Automatically verified.* -[YEP 4.6 - Gère le multi-instance](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-11) -`Validated` - *Automatically verified.* - -#### [Level 3](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-3) -[YEP 2.3 - Sauvegarder les réponses lors de l'installation](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-23) -`Validated` - -#### [Level 4](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-4) -[YEP 4.1 - Lier au ldap](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-41) -`Validated` -[YEP 4.2 - Lier l'authentification au sso](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-42) -`Validated` - -#### [Level 5](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-5) -[YEP 1.3 - Indiquer la licence associée au paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13) -`Validated` -[YEP 2.1 - Respecter le format du manifeste](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-21) -`Validated` - *Automatically verified.* -[YEP 2.12 - Utiliser les commandes pratiques (helpers)](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-212) -`Validated` -[YEP 2.18.1 - Lancer le script d'installation d'une webapp correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2181) -`Validated` - -#### [Level 6](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-6) -[YEP 1.4 - Informer sur l'intention de maintenir un paquet](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-14) -`Validated` -[YEP 1.6 - Se tenir informé sur l'évolution du packaging d'apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-16) -`Validated` -[YEP 1.7 - Ajouter l'app à l'organisation YunoHost-Apps](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-17) -`Validated` - *Automatically verified.* -[YEP 1.8 - Publier des demandes de test](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-18) -`Validated` -[YEP 1.9 - Documenter l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-19) -`Validated` -[YEP 1.10 - Garder un historique de version propre](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-110) -`Validated` -[YEP 2.9 - Enlever toutes traces de l'app lors de la suppression](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-29) -`Validated` -[YEP 3.3 - Faciliter le contrôle de l'intégrité des sources](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-33) -`Validated` -[YEP 3.5 - Suivre les recommendations de la documentation de l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-35) -`Partially validated` (no automated installation supported, forms install/upgrade forced in installer) - -[YEP 3.6 - Mettre à jour les versions contenant des CVE](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-36) -`Validated` -[YEP 4.3 - Fournir un script de sauvegarde YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-43) -`Validated` - *Automatically verified.* -[YEP 4.4 - Fournir un script de restauration YunoHost fonctionnel](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-44) -`Validated` - *Automatically verified.* - -#### [Level 7](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-7) -[YEP 2.6 - Annuler l'action si les valeurs d'entrées sont incorrectes](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-26) -`Validated` -[YEP 3.2 - Ouvrir un port correctement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-32) -`Not applicable` - -#### [Level 8](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-8) -[YEP 2.4 - Détecter et gérer les erreurs](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-24) -`Validated` -[YEP 2.8 - Modifier correctement une configuration système](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-28) -`Validated` -[YEP 2.16 - Vérifier la disponibilité des dépendances sur ARM, x86 et x64](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-216) -`Validated` - *Will be automatically verified.* -[YEP 2.18.5 - Gérer la tuile YunoHost pour faciliter la navigation entre les applications](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-2185) -`Validated` -[YEP 3.4 - Isoler l'app](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-34) -`Validated` -[YEP 4.5 - Utiliser les hooks](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-45) -`Not applicable` - -#### [Level 9](https://github.com/YunoHost/doc/blob/master/packaging_apps_levels_fr.md#niveau-9) -[YEP 2.10 - Configurer les logs de l'application](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-210) -`Not applicable` -[YEP 2.11 - Utiliser une variable plutôt que l'app id directement](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-211) -`Validated` -[YEP 2.13 - Traduire le paquet en anglais](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-213) -`Not yet validated` -[YEP 2.14 - Remplir correctement un fichier de conf](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-214) -`Not yet validated` -[YEP 2.17 - Prendre en compte la version d'origine lors des mises à jour](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-217) -`Validated` -[YEP 4.2.1 - Déconnexion](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-421) -`Not applicable` (No disconnection link given) - -#### Other YEP -[YEP 3.1 - Ne pas demander ou stocker de mot de passe LDAP](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-31) -`Validated` -[YEP 4.7 - Ajouter un module à la CLI](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-47) -`Not applicable` -[YEP 4.8 - Ajouter un module à l'admin web](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-48) -`Not applicable` - -State of each YEP can be one of these: `Validated`, `Partially validated`, `Not yet validated`, `Not applicable`, `Don't know`. diff --git a/check_process b/check_process index 050f061..3fac6e1 100644 --- a/check_process +++ b/check_process @@ -1,10 +1,10 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) + domain="domain.tld" + path="/path" + admin="john" language="fr" - is_public=1 (PUBLIC|public=1|private=0) + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/conf/app.src b/conf/app.src index e0244d4..6d61b68 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://piwigo.org/download/dlcounter.php?code=11.3.0 -SOURCE_SUM=07b0a364484c85acecf9abd6ac2b87e9c8793795b760134b4fab96be99228943 +SOURCE_URL=https://piwigo.org/download/dlcounter.php?code=11.5.0 +SOURCE_SUM=bfecdd743c62cdb4e1936662178d019af264ea763d26c8c832da836fbe09652d SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/conf/database.inc.php b/conf/database.inc.php index 9001a57..7e3a2cb 100644 --- a/conf/database.inc.php +++ b/conf/database.inc.php @@ -1,7 +1,7 @@ = 4.1.0" + "yunohost": ">= 4.1.3" }, "multi_instance": true, "services": [ @@ -28,38 +28,22 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for Piwigo", - "fr": "Choisissez un nom de domaine pour Piwigo" - }, "example": "domain.org" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Piwigo", - "fr": "Choisissez un chemin pour Piwigo" - }, "example": "/piwigo", "default": "/piwigo" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l'administrateur" - }, "example": "homer" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, "default": true }, { diff --git a/scripts/_common.sh b/scripts/_common.sh index 4a013c1..b44136a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,8 +6,13 @@ YNH_PHP_VERSION="7.3" +# dependencies used by the app pkg_dependencies="php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-imagick imagemagick" +#================================================= +# PERSONAL HELPERS +#================================================= + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 9791cc8..9cf719f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # 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 @@ -23,10 +24,11 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +datapath=$(ynh_app_setting_get --app=$app --key=datapath) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -51,13 +53,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_print_info --message="Backing up the MySQL database..." - -ynh_mysql_dump_db --database="$db_name" > db.sql - #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= @@ -69,10 +64,17 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" # BACKUP THE DATA DIRECTORY #================================================= -ynh_backup --src_path="/home/yunohost.app/$app/upload" --is_big +ynh_backup --src_path="$datapath" --is_big + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for Piwigo. (YunoHost will then actually copy those files to the archive)." +ynh_print_info --message="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 9533ac5..243e746 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -59,7 +59,7 @@ if [ $change_path -eq 1 ] then # Make a backup of the original NGINX config file if modified ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for nginx helper + # Set global variables for NGINX helper domain="$old_domain" path_url="$new_path" # Create a dedicated NGINX config @@ -77,7 +77,7 @@ then fi #================================================= -# GENERIC FINALIZATION +# GENERIC FINALISATION #================================================= # RELOAD NGINX #================================================= @@ -89,4 +89,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for Piwigo" --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 63de718..9905e2e 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -57,10 +57,18 @@ ynh_app_setting_set --app=$app --key=language --value=$language #================================================= ynh_script_progression --message="Installing dependencies..." --weight=40 -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies #================================================= -# CREATE A MYSQL DB +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=3 + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." @@ -85,28 +93,6 @@ mkdir -p $tmpdir/plugins/Ldap_Login ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=3 - -# Create a system user -ynh_system_user_create --username=$app - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP -#================================================= -# COPY FILES TO $FINAL_PATH -#================================================= - # sets extended pattern matching options in the bash shell shopt -s extglob @@ -127,12 +113,26 @@ cp -Rp $tmpdir/_data/. $final_path/_data cp -Rp $tmpdir/upload/. $final_path/upload cp -Rp $tmpdir/galleries/. $final_path/galleries -chown -R $app: $final_path -chown -R $app: $datapath -chmod 755 -R $final_path/_data +chmod 750 "$datapath" +chmod -R o-rwx "$datapath" +chown -R $app:www-data "$datapath" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + +ynh_app_setting_set --app=$app --key=datapath --value=$datapath ynh_secure_remove --file="$tmpdir" +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." + +# Create a dedicated NGINX config +ynh_add_nginx_config + #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -142,12 +142,16 @@ ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 ynh_add_fpm_config phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#================================================= +# SPECIFIC SETUP #================================================= # SETUP APPLICATION WITH CURL #================================================= -ynh_script_progression --message="Installing Piwigo with cURL..." --weight=5 +ynh_script_progression --message="Setuping application with CURL..." --weight=5 -# Set the app as temporarily public for cURL call +# Set the app as temporarily public for curl call +ynh_script_progression --message="Configuring SSOwat..." +# Making the app public for curl ynh_permission_update --permission="main" --add="visitors" # Reload NGINX @@ -167,7 +171,7 @@ fi mail="$(ynh_user_get_info --username=$admin --key=mail)" # Installation with cURL -ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_name" "dbpasswd=$db_pwd" "dbname=$db_name" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail" +ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbhost=127.0.0.1" "dbuser=$db_user" "dbpasswd=$db_pwd" "dbname=$db_name" "prefix=" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail" #================================================= # CONFIGURE PIWIGO @@ -175,16 +179,14 @@ ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_n ynh_script_progression --message="Configuring Piwigo..." # Change local config -cp ../conf/config.inc.php $final_path/local/config/ - -# Calculate and store the config file checksum -ynh_store_file_checksum --file="$final_path/local/config/config.inc.php" +ynh_add_config --template="../conf/config.inc.php" --destination="$final_path/local/config/config.inc.php" # Setup database in local/config/database.inc.php ynh_add_config --template="../conf/database.inc.php" --destination="$final_path/local/config/database.inc.php" -# Calculate and store the database config file checksum -ynh_store_file_checksum --file="$final_path/local/config/database.inc.php" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # ADD LDAP PLUGIN @@ -212,8 +214,13 @@ UPDATE piwigo_ldap_login_config SET value='' WHERE param = 'ld_binddn'; UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'allow_new_users'; UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'ld_group_user_active';" +# Remove the public access +ynh_permission_update --permission="main" --remove="visitors" + #================================================= -# CONFIGURE FAIL2BAN +# GENERIC FINALIZATION +#================================================= +# SETUP FAIL2BAN #================================================= ynh_script_progression --message="Configuring Fail2Ban..." --weight=6 @@ -226,17 +233,17 @@ chown $app: "/var/log/${app}FailedLogins.log" ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=" --max_retry=6 -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." # Make app public if necessary -if [ $is_public -eq 0 ] +if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --remove="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= @@ -250,4 +257,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of Piwigo completed" --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index c63a0b9..c6ebafb 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -18,10 +18,19 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Removing the MySQL database..." + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + #================================================= # REMOVE DEPENDENCIES #================================================= @@ -30,18 +39,10 @@ ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_name --db_name=$db_name - #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing Piwigo main directory..." +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -67,6 +68,7 @@ ynh_remove_fpm_config #================================================= ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=8 +# Remove the dedicated Fail2Ban config ynh_remove_fail2ban_config #================================================= @@ -83,4 +85,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of Piwigo completed" --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index b267c64..00d0ac4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # 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 @@ -25,10 +26,11 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +datapath=$(ynh_app_setting_get --app=$app --key=datapath) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -45,51 +47,46 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring Piwigo main directory..." - -ynh_restore_file --origin_path="$final_path" - -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=2 - -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql - #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring app main directory..." + +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=10 +ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=10 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= -# RESTORE THE FAIL2BAN CONFIGURATION +# RESTORE FAIL2BAN CONFIGURATION #================================================= ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=7 -ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" - touch "/var/log/${app}FailedLogins.log" chown $app: "/var/log/${app}FailedLogins.log" +ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" +ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban #================================================= @@ -100,7 +97,16 @@ ynh_systemd_action --action=restart --service_name=fail2ban ynh_script_progression --message="Reinstalling dependencies..." --weight=40 # Define and install dependencies -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=2 + +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 #================================================= # RESTORE THE DATA DIRECTORY @@ -108,20 +114,14 @@ ynh_install_app_dependencies "$pkg_dependencies" ynh_script_progression --message="Restoring data directory..." # Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. -ynh_restore_file --origin_path="/home/yunohost.app/$app/upload" --not_mandatory +ynh_restore_file --origin_path="$datapath" --not_mandatory # Create app folders mkdir -p /home/yunohost.app/$app/upload -# Create temporary data folder -mkdir -p /home/yunohost.app/$app/_data - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -chown -R $app: $final_path -chown -R $app: /home/yunohost.app/$app +chmod 750 "$datapath" +chmod -R o-rwx "$datapath" +chown -R $app:www-data "$datapath" #================================================= # GENERIC FINALIZATION @@ -137,4 +137,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for Piwigo" --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index d840c9a..db37df7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -23,15 +23,33 @@ is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name admin_pwd=$(ynh_app_setting_get --app=$app --key=admin_pwd) db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=6 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -78,44 +96,68 @@ fi # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public fi #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Backing up Piwigo before upgrading (may take a while)..." --weight=6 +ynh_script_progression --message="Making sure dedicated system user exists..." -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path -#================================================= -# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +# sets extended pattern matching options in the bash shell +shopt -s extglob + +datapath=/home/yunohost.app/$app + if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=3 # Create tmp directory and fetch app inside - tmpdir="$(ynh_smart_mktemp --min_size=300)" - ynh_setup_source --dest_dir="$tmpdir" + tmpdir="$(ynh_smart_mktemp --min_size=300)" + ynh_setup_source --dest_dir="$tmpdir" - # Fetch needed plugins - mkdir -p $tmpdir/plugins/Ldap_Login - ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin - ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin + # Fetch needed plugins + mkdir -p $tmpdir/plugins/Ldap_Login + ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin + ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin + + # Install files and set permissions + cp -a $tmpdir/!(upload|_data|galleries) $final_path + + # Backward compatibility: + # If the _data subdirectory wasn't already moved to /home/yunohost.app/$app, + # then move it there + if [ ! -h $final_path/_data ] ; then + mv $final_path/_data $datapath + ln -sd $datapath/_data $final_path/_data + fi + + # Backward compatibility: + # If the galleries subdirectory wasn't already moved to /home/yunohost.app/$app, + # then move it there + if [ ! -h $final_path/galleries ] ; then + mv $final_path/galleries $datapath + ln -sd $datapath/galleries $final_path/galleries + fi + + ynh_secure_remove --file="$tmpdir" fi +chmod 750 "$datapath" +chmod -R o-rwx "$datapath" +chown -R $app:www-data "$datapath" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -131,14 +173,6 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=6 ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -149,43 +183,6 @@ ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE -#================================================= -# COPY FILES TO $FINAL_PATH -#================================================= - -# sets extended pattern matching options in the bash shell -shopt -s extglob - -datapath=/home/yunohost.app/$app - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - # Install files and set permissions - cp -a $tmpdir/!(upload|_data|galleries) $final_path - - # Backward compatibility: - # If the _data subdirectory wasn't already moved to /home/yunohost.app/$app, - # then move it there - if [ ! -h $final_path/_data ] ; then - mv $final_path/_data $datapath - ln -sd $datapath/_data $final_path/_data - fi - - # Backward compatibility: - # If the galleries subdirectory wasn't already moved to /home/yunohost.app/$app, - # then move it there - if [ ! -h $final_path/galleries ] ; then - mv $final_path/galleries $datapath - ln -sd $datapath/galleries $final_path/galleries - fi - - ynh_secure_remove --file="$tmpdir" -fi - -chown -R $app: $final_path -chown -R $app: $datapath -chmod 755 -R $final_path/_data - #================================================= # UPGRADE APPLICATION WITH CURL #================================================= @@ -214,22 +211,15 @@ ynh_local_curl "/upgrade.php?language=$applanguage&now=true" "language=$applangu #================================================= ynh_script_progression --message="Configuring Piwigo..." -# Make a backup of the original config file if modified -ynh_backup_if_checksum_is_different --file="$final_path/local/config/config.inc.php" - # Change local config -cp ../conf/config.inc.php $final_path/local/config/ - -# Calculate and store the config file checksum -ynh_store_file_checksum --file="$final_path/local/config/config.inc.php" - -# Make a backup of the original database config file if modified -ynh_backup_if_checksum_is_different --file="$final_path/local/config/database.inc.php" +ynh_add_config --template="../conf/config.inc.php" --destination="$final_path/local/config/config.inc.php" +# Setup database in local/config/database.inc.php ynh_add_config --template="../conf/database.inc.php" --destination="$final_path/local/config/database.inc.php" -# Calculate and store the database config file checksum -ynh_store_file_checksum --file="$final_path/local/config/database.inc.php" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # CONFIGURE LDAP PLUGIN @@ -262,6 +252,11 @@ if [ -f $final_path/plugins/Ldap_Login/data.dat ] ; then ynh_secure_remove --file=$final_path/plugins/Ldap_Login/data.dat fi +# Remove the public access +ynh_permission_update --permission="main" --remove="visitors" + +#================================================= +# GENERIC FINALIZATION #================================================= # UPGRADE FAIL2BAN #================================================= @@ -282,13 +277,13 @@ ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex= ynh_script_progression --message="Configuring permissions..." # Make app public if necessary -if [ $is_public -eq 0 ] +if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --remove="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= @@ -300,4 +295,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of Piwigo completed" --last +ynh_script_progression --message="Upgrade of $app completed" --last