diff --git a/issue_template.md b/.github/ISSUE_TEMPLATE.md similarity index 57% rename from issue_template.md rename to .github/ISSUE_TEMPLATE.md index 2a9be2a..2729a6b 100644 --- a/issue_template.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,6 +1,6 @@ --- name: Bug report -about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. --- @@ -8,15 +8,17 @@ about: Create a report to help us debug, it would be nice to fill the template a 1. *Read this whole template first.* 2. *Determine if you are on the right place:* - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* - - *Otherwise, the issue may be due to framaforms itself. Refer to its documentation or repository for help.* - - *If you have a doubt, post here, we will figure it out together.* + - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* + - *When in doubt, post here and we will figure it out together.* 3. *Delete the italic comments as you write over them below, and remove this guide.* --- -**Describe the bug** +### Describe the bug + *A clear and concise description of what the bug is.* -**Versions** +### Context + - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* - YunoHost version: x.x.x - I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* @@ -25,11 +27,11 @@ about: Create a report to help us debug, it would be nice to fill the template a - Using, or trying to install package version/branch: - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* -**To Reproduce** -*Steps to reproduce the behavior.* +### Steps to reproduce + - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh - sudo yunohost app install framaforms + sudo yunohost app install the_app ``` - *If you used the webadmin, please perform the equivalent command from the CLI first.* - *If the error occurs in your browser, explain what you did:* @@ -38,9 +40,16 @@ about: Create a report to help us debug, it would be nice to fill the template a 3. *Scroll down to '...'* 4. *See error* -**Expected behavior** +### Expected behavior + *A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* -**Logs** -*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + *If applicable and useful, add screenshots to help explain your problem.* diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ef70e18 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Problem + +- *Description of why you made this PR* + +## Solution + +- *And how do you fix that problem* + +## PR Status + +- [ ] Code finished and ready to be reviewed/tested +- [ ] The fix/enhancement were manually tested (if applicable) + +## Automatic tests + +Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) diff --git a/README.md b/README.md index d3b355c..fea324a 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,14 @@ You can modify some configurations using the Framaforms administration panel. Yo ## Documentation * Official documentation: https://docs.framasoft.org/fr/framaforms/ - * YunoHost documentation: https://yunohost.org/#/app_framaforms + * YunoHost documentation: https://yunohost.org/en/app_framaforms ## YunoHost specific features #### Multi-user support -Are LDAP and HTTP auth supported? **Only LDAP** -Can the app be used by multiple users? **Yes** + * Are LDAP and HTTP auth supported? **Only LDAP** + * Can the app be used by multiple users? **Yes** #### Supported architectures diff --git a/check_process b/check_process index 91243cc..0418448 100644 --- a/check_process +++ b/check_process @@ -1,12 +1,10 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file ;; 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 password="password" expiration="0" deletion="0" @@ -18,11 +16,8 @@ setup_private=1 setup_public=1 upgrade=1 - # 1.0.1+200715~ynh4 - upgrade=1 from_commit=25e97123f0e82ec1b9375774f3e86b7d8f5d73cf backup_restore=1 multi_instance=1 - port_already_use=0 change_url=1 ;;; Options Email=ljf+framaforms_ynh@reflexlibre.net diff --git a/conf/app.src b/conf/app.src index a48f4e4..8da0a3b 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ SOURCE_URL=https://framagit.org/framasoft/framaforms/-/archive/1.0.3/framaforms-1.0.3.tar.gz -SOURCE_SUM=325f6735960864500d8c636cd67547666bc3aa07608b8a3c87e2e2a03ddb18cd +SOURCE_SUM=a7b004dac19d761212d49a0e407f5d31c97e49ccefca6443067a9d5da68bf64d SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/yoursite.aliases.drushrc.php b/conf/yoursite.aliases.drushrc.php index 4035f0f..2c91f35 100644 --- a/conf/yoursite.aliases.drushrc.php +++ b/conf/yoursite.aliases.drushrc.php @@ -29,7 +29,7 @@ */ $aliases['__APP__'] = array( 'root' => '__FINALPATH__/app/', - 'uri' => 'https://__DOMAIN____PATH_URL__', + 'uri' => 'https://__DOMAIN____PATH__', 'path-aliases' => array( '%dump-dir' => '/tmp', ), diff --git a/manifest.json b/manifest.json index 9ebfe3d..8a0ac17 100644 --- a/manifest.json +++ b/manifest.json @@ -1,116 +1,96 @@ { - "name": "Framaforms", - "id": "framaforms", - "packaging_format": 1, - "description": { - "en": "Create online webforms and surveys", - "fr": "Créez des formulaires et questionnaires en ligne" - }, - "version": "1.0.3~ynh1", - "url": "https://framagit.org/framasoft/framaforms", - "license": "GPL-2.0-only", - "requirements": { - "yunohost": ">= 3.8.1" - }, - "maintainer": { - "name": "ljf", - "email": "ljf+framaforms_ynh@reflexlibre.net", - "url": "https://reflexlibre.net" - }, - "multi_instance": true, - "services": [ - "nginx", - "php7.0-fpm", - "mysql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain for Framaforms", - "fr": "Choisissez un nom de domaine pour Framaforms" - }, - "example": "domain.org" - }, - { - "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for Framaforms", - "fr": "Choisissez un chemin pour Framaforms" - }, - "example": "/poll", - "default": "/poll" - }, - { - "name": "admin", - "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l’administrateur" - }, - "example": "johndoe" - }, - { - "name": "password", - "type": "password", - "ask": { - "en": "Set the administrator password", - "fr": "Définissez le mot de passe administrateur" - }, - "example": "Choose a password" - }, - { - "name": "language", - "type": "string", - "ask": { - "en": "Choose the application language", - "fr": "Choisissez la langue de l'application" - }, - "choices": ["fr", "en"], - "default": "en" - }, - { - "name": "expiration", - "type": "string", - "ask": { - "en": "After how many weeks do the forms expire?", - "fr": "Après combien de semaines les formulaires expirent-ils ?" - }, - "help": { - "en": "Set 0 to disable expiration", - "fr": "Mettre 0 pour désactiver l'expiration" - }, - "default": "0" - }, - { - "name": "deletion", - "type": "string", - "ask": { - "en": "After how many weeks is the forms deleted?", - "fr": "Après combien de semaines les formulaires sont-ils supprimés ?" - }, - "help": { - "en": "Set 0 to disable deletion", - "fr": "Mettre 0 pour désactiver la suppression" - }, - "default": "0" - }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Are visitors who do not have a YunoHost account on this server allowed to register and create forms?", - "fr": "Les visiteurs qui n'ont pas de compte YunoHost sur ce serveur sont-ils autorisés à s'inscrire et à créer des formulaires ?" - }, - "help": { - "en": "If no, only person with an account on your server will be able to create forms. In all cases, visitors will be able to reply to form.", - "fr": "Si non, seule la personne disposant d'un compte sur votre serveur pourra créer des formulaires. Dans tous les cas, les visiteurs pourront répondre au formulaire." - }, - "default": true - } - ] - } + "name": "Framaforms", + "id": "framaforms", + "packaging_format": 1, + "description": { + "en": "Create online webforms and surveys", + "fr": "Créez des formulaires et questionnaires en ligne" + }, + "version": "1.0.3~ynh2", + "url": "https://framagit.org/framasoft/framaforms", + "license": "GPL-2.0-only", + "requirements": { + "yunohost": ">= 4.2.0" + }, + "maintainer": { + "name": "ljf", + "email": "ljf+framaforms_ynh@reflexlibre.net", + "url": "https://reflexlibre.net" + }, + "multi_instance": true, + "services": [ + "nginx", + "php7.3-fpm", + "mysql" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "example": "domain.org" + }, + { + "name": "path", + "type": "path", + "example": "/poll", + "default": "/poll" + }, + { + "name": "admin", + "type": "user", + "example": "johndoe" + }, + { + "name": "password", + "type": "password", + "example": "Choose a password" + }, + { + "name": "language", + "type": "string", + "ask": { + "en": "Choose the application language", + "fr": "Choisissez la langue de l'application" + }, + "choices": ["de", "en", "es", "fr", "it", "pt"], + "default": "en" + }, + { + "name": "expiration", + "type": "string", + "ask": { + "en": "After how many weeks do the forms expire?", + "fr": "Après combien de semaines les formulaires expirent-ils ?" + }, + "help": { + "en": "Set 0 to disable expiration", + "fr": "Mettre 0 pour désactiver l'expiration" + }, + "default": "0" + }, + { + "name": "deletion", + "type": "string", + "ask": { + "en": "After how many weeks is the forms deleted?", + "fr": "Après combien de semaines les formulaires sont-ils supprimés ?" + }, + "help": { + "en": "Set 0 to disable deletion", + "fr": "Mettre 0 pour désactiver la suppression" + }, + "default": "0" + }, + { + "name": "is_public", + "type": "boolean", + "help": { + "en": "If no, only person with an account on your server will be able to create forms. In all cases, visitors will be able to reply to form.", + "fr": "Si non, seule la personne disposant d'un compte sur votre serveur pourra créer des formulaires. Dans tous les cas, les visiteurs pourront répondre au formulaire." + }, + "default": true + } + ] + } } diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index 3679ea2..0000000 --- a/pull_request_template.md +++ /dev/null @@ -1,18 +0,0 @@ -## Problem -- *Description of why you made this PR* - -## Solution -- *And how do you fix that problem* - -## PR Status -- [ ] Code finished. -- [ ] Tested with Package_check. -- [ ] Fix or enhancement tested. -- [ ] Upgrade from last version tested. -- [ ] Can be reviewed and tested. - -## Package_check results ---- -*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* - -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/framaforms_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/framaforms_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 94ca18f..267d18c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,6 +11,8 @@ YNH_PHP_VERSION="7.3" extra_php_dependencies="php${YNH_PHP_VERSION}-fpm php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-ldap php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-pgsql" +YNH_COMPOSER_VERSION="1.10.17" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 96a1261..7c8e69b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 @@ -28,6 +28,7 @@ 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) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -40,7 +41,11 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" -ynh_backup --src_path="/home/yunohost.app/$app/data" --is_big=1 +#================================================= +# BACKUP THE DATA DIR +#================================================= + +ynh_backup --src_path="$datadir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index d1d91c8..9ddd691 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -32,9 +32,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_print_info --message="Backing up the app before changing its URL (may take a while)..." +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -42,7 +42,7 @@ ynh_clean_setup () { # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -73,19 +73,19 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the nginx config file +# Change the path in the NGINX config file if [ $change_path -eq 1 ] then - # Make a backup of the original nginx config file if modified + # 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 + # Create a dedicated NGINX config ynh_add_nginx_config fi -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -102,13 +102,10 @@ fi #================================================= ynh_script_progression --message="Updating Drush alias..." --weight=1 -drush_aliasconfig="$final_path/.drush/$app.aliases.drushrc.php" -cp -f "../conf/yoursite.aliases.drushrc.php" "$drush_aliasconfig" +domain="$new_domain" +path_url="$new_path" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$new_domain" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$new_path" --target_file="$drush_aliasconfig" +ynh_add_config --template="../conf/yoursite.aliases.drushrc.php" --destination="$final_path/.drush/$app.aliases.drushrc.php" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index ad6db06..230c2e9 100644 --- a/scripts/install +++ b/scripts/install @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_composer__2 -source ynh_exec_as source /usr/share/yunohost/helpers #================================================= @@ -24,13 +22,13 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC -password=$YNH_APP_ARG_PASSWORD -admin=admin language=$YNH_APP_ARG_LANGUAGE +password=$YNH_APP_ARG_PASSWORD expiration=$YNH_APP_ARG_EXPIRATION deletion=$YNH_APP_ARG_DELETION -admin_mail="root@$domain" +admin_mail=$(ynh_user_get_info --username=$admin --key=mail) app=$YNH_APP_INSTANCE_NAME @@ -54,7 +52,6 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain 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=password --value=$password -ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=language --value=$language ynh_app_setting_set --app=$app --key=expiration --value=$expiration ynh_app_setting_set --app=$app --key=deletion --value=$deletion @@ -68,6 +65,14 @@ ynh_script_progression --message="Installing dependencies..." --weight=7 ynh_install_app_dependencies $pkg_dependencies +#================================================= +# 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 POSTGRESQL DATABASE #================================================= @@ -89,6 +94,10 @@ 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/app" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -97,14 +106,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# 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" - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -123,12 +124,11 @@ ynh_script_progression --message="Creating Drush alias..." --weight=2 mkdir -p "$final_path/.drush" drush_aliasconfig="$final_path/.drush/$app.aliases.drushrc.php" -cp -f "../conf/yoursite.aliases.drushrc.php" "$drush_aliasconfig" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$drush_aliasconfig" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$drush_aliasconfig" +ynh_add_config --template="../conf/yoursite.aliases.drushrc.php" --destination="$drush_aliasconfig" + +chmod 400 "$drush_aliasconfig" +chown $app:$app "$drush_aliasconfig" #================================================= # INSTALL COMPOSER @@ -137,7 +137,7 @@ ynh_script_progression --message="Installing Composer..." --weight=31 mkdir -p "$final_path/.composer" -cp -f "../conf/composer.json" "$final_path/.composer/composer.json" +ynh_add_config --template="../conf/composer.json" --destination="$final_path/.composer/composer.json" ynh_install_composer --phpversion="$phpversion" --workdir="$final_path/.composer" @@ -149,12 +149,25 @@ export PATH="$final_path/.composer/vendor/bin:$PATH" ynh_script_progression --message="Initializing tmp and private directory..." --weight=1 mkdir -p "$final_path/app/sites/default/files" -chmod 2775 "$final_path/app/sites/default/files" mkdir -p "$final_path/app/sites/default/files/tmp" -mkdir -p "/home/yunohost.app/$app/data" -chown -R $app: "/home/yunohost.app/$app/data" -chmod 775 "/home/yunohost.app/$app/data" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod 2775 "$final_path/app/sites/default/files" + +#================================================= +# CREATE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Creating a data directory..." + +datadir=/home/yunohost.app/$app +ynh_app_setting_set --app=$app --key=datadir --value=$datadir + +mkdir -p $datadir +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # ADD MISSING IMAGES @@ -168,45 +181,40 @@ chmod 775 "/home/yunohost.app/$app/data" #cp ../sources/partager.png "$final_path/sites/default/files/imgforms/" #================================================= -# MODIFY CONFIG FILES +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Modifying a config file..." --weight=1 +ynh_script_progression --message="Adding a configuration file..." --weight=1 -config_file=$final_path/app/sites/default/settings.php +ynh_add_config --template="../conf/default.settings.php" --destination="$final_path/app/sites/default/settings.php" -cp ../conf/default.settings.php "$config_file" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config_file" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config_file" -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$config_file" +chmod 600 "$final_path/app/sites/default/settings.php" +chown $app:$app "$final_path/app/sites/default/settings.php" #================================================= # INSTALLING FRAMAFORMS WITH DRUSH #================================================= ynh_script_progression --message="Installing database..." --weight=19 -chown -R $app: $final_path - update-alternatives --set php /usr/bin/php$phpversion -ynh_exec_as $app env PATH=$PATH drush @$app site-install framaforms_org install_configure_form.site_contact_url="https://forum.yunohost.org/t/framaforms-create-polls-using-drag-and-drop/8208" install_configure_form.site_default_country=FR -y --locale="$language" --account-name="admin" --account-pass="$password" --site-name="Framaforms" --site-mail="$admin_mail" 2>&1 -ynh_exec_as $app env PATH=$PATH drush @$app variable-set update_notify_emails "$admin_mail" -ynh_exec_as $app env PATH=$PATH drush @$app variable-set file_private_path "/home/yunohost.app/$app/data" 2>&1 -ynh_exec_as $app env PATH=$PATH drush @$app pm-enable framaforms_feature -y --resolve-dependencies 2>&1 -ynh_exec_as $app env PATH=$PATH drush @$app php-eval "module_load_include('inc', 'framaforms', 'includes/framaforms.pages');create_all_pages();" 2>&1 || true +sudo -u $app env PATH=$PATH drush @$app site-install framaforms_org install_configure_form.site_contact_url="https://forum.yunohost.org/t/framaforms-create-polls-using-drag-and-drop/8208" install_configure_form.site_default_country=FR -y --locale="$language" --account-name="admin" --account-pass="$password" --site-name="Framaforms" --site-mail="$admin_mail" 2>&1 +sudo -u $app env PATH=$PATH drush @$app variable-set update_notify_emails "$admin_mail" +sudo -u $app env PATH=$PATH drush @$app variable-set file_private_path "/home/yunohost.app/$app/data" 2>&1 +sudo -u $app env PATH=$PATH drush @$app pm-enable framaforms_feature -y --resolve-dependencies 2>&1 +sudo -u $app env PATH=$PATH drush @$app php-eval "module_load_include('inc', 'framaforms', 'includes/framaforms.pages');create_all_pages();" 2>&1 || true #================================================= # IMPORTING LANGUAGE PACK #================================================= ynh_script_progression --message="Importing language pack..." --weight=5 -sudo -u $app env PATH=$PATH drush @$app pm-download -y drush_language -sudo -u $app env PATH=$PATH drush @$app pm-download -y l10n_update -sudo -u $app env PATH=$PATH drush @$app pm-enable -y l10n_update -sudo -u $app env PATH=$PATH drush @$app language-add $language -y -sudo -u $app env PATH=$PATH drush @$app language-default $language -y -sudo -u $app env PATH=$PATH drush @$app cache-clear drush -y -sudo -u $app env PATH=$PATH drush @$app l10n-update-refresh -y -sudo -u $app env PATH=$PATH drush @$app l10n-update -y +sudo -u $app env PATH=$PATH drush @$app pm-download -y drush_language 2>&1 +sudo -u $app env PATH=$PATH drush @$app pm-download -y l10n_update 2>&1 +sudo -u $app env PATH=$PATH drush @$app pm-enable -y l10n_update 2>&1 +sudo -u $app env PATH=$PATH drush @$app language-add $language -y 2>&1 +sudo -u $app env PATH=$PATH drush @$app language-default $language -y 2>&1 +sudo -u $app env PATH=$PATH drush @$app cache-clear drush -y 2>&1 +sudo -u $app env PATH=$PATH drush @$app l10n-update-refresh -y 2>&1 +sudo -u $app env PATH=$PATH drush @$app l10n-update -y 2>&1 # We don't upgrade module to avoid to erase framaforms change # in drupal core and modules code @@ -224,7 +232,6 @@ sudo -u $app env PATH=$PATH drush @$app vset framaforms_deletion_period_value $d # Remove framaforms footer sudo -u $app env PATH=$PATH drush @$app sql-query "UPDATE block SET region='-1', status=0 WHERE delta='framaforms_footer' AND region='footer'" - #================================================= # CONFIGURING LDAP #================================================= @@ -240,48 +247,31 @@ cat ../conf/ldap.conf | sudo -u $app env PATH=$PATH drush @$app variable-set --f update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." --weight=1 - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config_file" - #================================================= # SETUP THE CRON FILE #================================================= ynh_script_progression --message="Setuping the cron file..." -cp ../conf/cron /etc/cron.d/$app - -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." --weight=1 - -# Set permissions to app files -chown -R $app: $final_path - #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=1 - -ynh_permission_create --permission "admin" --url /admin/ +ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi +# Only the admin can access the admin panel of the app (if the app has an admin panel) +ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/remove b/scripts/remove index 1c72a9e..1b12a17 100644 --- a/scripts/remove +++ b/scripts/remove @@ -47,20 +47,12 @@ ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" -#================================================= -# REMOVE APP DATA DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="/home/yunohost.app/$app" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= @@ -68,11 +60,19 @@ ynh_remove_nginx_config #================================================= ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1 -# Remove the dedicated php-fpm config +# Remove the dedicated PHP-FPM config ynh_remove_fpm_config #================================================= # SPECIFIC REMOVE +#================================================= +# REMOVE APP DATA DIR +#================================================= +ynh_script_progression --message="Removing app data directory..." --weight=1 + +# Remove the app directory securely +ynh_secure_remove --file="/home/yunohost.app/$app" + #================================================= # REMOVE THE CRON FILE #================================================= diff --git a/scripts/restore b/scripts/restore index 172770e..6178f45 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,10 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_composer__2 -source ../settings/scripts/ynh_exec_as source /usr/share/yunohost/helpers #================================================= @@ -22,7 +20,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -33,6 +31,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -53,6 +52,14 @@ ynh_script_progression --message="Restoring the NGINX configuration..." --weight ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -60,26 +67,24 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." --weight=1 - -# Restore permissions on app files -chown -R root: $final_path chmod 2775 "$final_path/app/sites/default/files" -mkdir -p "/home/yunohost.app/$app/data" -chown -R $app: "/home/yunohost.app/$app/data" -chmod 775 "/home/yunohost.app/$app/data" +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." + +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p $datadir + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -90,8 +95,11 @@ ynh_script_progression --message="Restoring PHP-FPM configuration..." --weight=1 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" # Recreate a dedicated php-fpm config -ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" +ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#================================================= +# SPECIFIC RESTORATION #================================================= # RESTORE THE CRON FILE #================================================= @@ -100,8 +108,6 @@ ynh_script_progression --message="Restoring cron file..." --weight=1 # Restore the file first, so it can have a backup if different ynh_restore_file --origin_path="/etc/cron.d/$app" -#================================================= -# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f48a280..ba496e9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_composer__2 -source ynh_exec_as source /usr/share/yunohost/helpers #================================================= @@ -20,10 +18,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) +admin=$(ynh_app_setting_get --app=$app --key=admin) db_name=$(ynh_app_setting_get --app=$app --key=db_name) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK VERSION @@ -32,20 +31,27 @@ ynh_script_progression --message="Checking version..." --weight=1 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=21 + +# 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 #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi - # If db_name doesn't exist, create it if [ -z "$db_name" ]; then db_name=$(ynh_sanitize_dbid --db_name=$app) @@ -58,22 +64,32 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=21 +# If datadir doesn't exist, create it +if [ -z "$datadir" ]; then + final_path=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=final_path --value=$datadir +fi -# 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 +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + +if ! ynh_permission_exists --permission="admin"; then + # Create the required permissions + ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin +fi #================================================= -# STANDARD UPGRADE STEPS +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -86,12 +102,16 @@ then ynh_setup_source --dest_dir="$final_path/app" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= @@ -101,14 +121,6 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=5 ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -119,6 +131,16 @@ ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencie #================================================= # SPECIFIC UPGRADE +#================================================= +# CREATE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Creating a data directory..." + +mkdir -p $datadir +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" + #================================================= # UPGRADE COMPOSER #================================================= @@ -138,60 +160,30 @@ then ynh_backup_if_checksum_is_different --file="$final_path/app/sites/default/settings.php" - chown -R $app: $final_path - update-alternatives --set php /usr/bin/php$phpversion pushd "$final_path" - ynh_exec_as $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 1 - ynh_exec_as $app env PATH=$PATH drush @$app cache-clear all - # ynh_exec_as $app env PATH=$PATH drush @$app pm-update -y drupal - # ynh_exec_as $app env PATH=$PATH drush @$app updatedb -y - ynh_exec_as $app env PATH=$PATH drush @$app cache-clear all - ynh_exec_as $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 0 + sudo -u $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 1 + sudo -u $app env PATH=$PATH drush @$app cache-clear all + # sudo -u $app env PATH=$PATH drush @$app pm-update -y drupal + # sudo -u $app env PATH=$PATH drush @$app updatedb -y + sudo -u $app env PATH=$PATH drush @$app cache-clear all + sudo -u $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 0 popd update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} fi #================================================= -# STORE THE CONFIG FILE CHECKSUM +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Storing the config file checksum..." --weight=1 +ynh_script_progression --message="Updating a configuration file..." -config_file=$final_path/app/sites/default/settings.php - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config_file" - -#================================================= +chmod 600 "$final_path/app/sites/default/settings.php" +chown $app:$app "$final_path/app/sites/default/settings.php" #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." --weight=1 - -# Set permissions on app files -chown -R $app: $final_path - -mkdir -p "/home/yunohost.app/$app/data" -chown -R $app: "/home/yunohost.app/$app/data" -chmod 775 "/home/yunohost.app/$app/data" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi - #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 deleted file mode 100644 index 762b7f7..0000000 --- a/scripts/ynh_composer__2 +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# Execute a command with Composer -# -# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands" -# | arg: -v, --phpversion - PHP version to use with composer -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -c, --commands - Commands to execute. -ynh_composer_exec () { - # Declare an array to define the options of this helper. - local legacy_args=vwc - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) - local phpversion - local workdir - local commands - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-$YNH_PHP_VERSION}" - - COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} "$workdir/composer.phar" $commands \ - -d "$workdir" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# -# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] -# | arg: -v, --phpversion - PHP version to use with composer -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include -ynh_install_composer () { - # Declare an array to define the options of this helper. - local legacy_args=vwa - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args=) - local phpversion - local workdir - local install_args - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-$YNH_PHP_VERSION}" - install_args="${install_args:-}" - - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} -- --quiet --install-dir="$workdir" \ - || ynh_die "Unable to install Composer." - - # update dependencies to create composer.lock - ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \ - || ynh_die "Unable to update core dependencies with Composer." -} diff --git a/scripts/ynh_exec_as b/scripts/ynh_exec_as deleted file mode 100644 index 2e849dc..0000000 --- a/scripts/ynh_exec_as +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -ynh_exec_as() { - local USER=$1 - shift 1 - - if [[ $USER = $(whoami) ]]; then - eval "$@" - else - sudo -u "$USER" "$@" - fi -}