From a4992b9302e571a4ca1de0e76772c80198c473c4 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 22 May 2021 12:42:26 +0200 Subject: [PATCH 1/6] Apply last example_ynh --- check_process | 14 +- conf/.env | 20 +-- manifest.json | 22 +-- scripts/backup | 4 +- scripts/change_url | 16 +-- scripts/install | 71 ++++------ scripts/remove | 6 +- scripts/restore | 37 +++-- scripts/upgrade | 129 ++++++++---------- scripts/ynh_composer__2 | 61 --------- ...adme_to_admin => ynh_send_readme_to_admin} | 0 11 files changed, 131 insertions(+), 249 deletions(-) delete mode 100644 scripts/ynh_composer__2 rename scripts/{send_readme_to_admin => ynh_send_readme_to_admin} (100%) diff --git a/check_process b/check_process index 9a26695..93b5642 100644 --- a/check_process +++ b/check_process @@ -1,13 +1,8 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/" (PATH) - admin="john" (USER) + domain="domain.tld" + path="/path" + admin="john" is_public=1 (PUBLIC|public=1|private=0) language="fr" dav_support=1 (DAV_SUPPORT|dav_support=1|dav_support=0) @@ -33,9 +28,6 @@ # incorrect_path=1 port_already_use=0 change_url=0 -;;; Levels - # If the level 5 (Package linter) is forced to 1. Please add justifications here. - Level 5=auto ;;; Options Email=anmol@datamol.org Notification=change diff --git a/conf/.env b/conf/.env index 314e600..3aa1046 100644 --- a/conf/.env +++ b/conf/.env @@ -14,7 +14,7 @@ APP_DEBUG=false # this secure otherwise, everyone will be able to access your application. # Must be 32 characters long exactly. # Use `php artisan key:generate` or `pwgen -s 32 1` to generate a random key. -APP_KEY=random_key +APP_KEY=__RANDOM_KEY__ # Prevent information leakage by referring to IDs with hashIds instead of # the actual IDs used in the database. @@ -36,9 +36,9 @@ DB_HOST=127.0.0.1 DB_PORT=3306 # You can use mysql unix socket if available, it overrides DB_HOST and DB_PORT values. #DB_UNIX_SOCKET=/var/run/mysqld/mysqld.sock -DB_DATABASE=yunobase -DB_USERNAME=yunouser -DB_PASSWORD=yunopass +DB_DATABASE=__DB_NAME__ +DB_USERNAME=__DB_USER__ +DB_PASSWORD=__DB_PWD__ DB_PREFIX= DB_TEST_HOST=127.0.0.1 DB_TEST_DATABASE=monica_test @@ -57,18 +57,18 @@ MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION= # Outgoing emails will be sent with these identity -MAIL_FROM_ADDRESS=monica@yunodomain +MAIL_FROM_ADDRESS=monica@__DOMAIN__ MAIL_FROM_NAME="Monica" # New registration notification sent to this email -APP_EMAIL_NEW_USERS_NOTIFICATION=yunomail +APP_EMAIL_NEW_USERS_NOTIFICATION=__EMAIL__ # Default locale used in the application. -APP_DEFAULT_LOCALE=language +APP_DEFAULT_LOCALE=__LANGUAGE__ # Ability to disable signups on your instance. # Can be true or false. Default to false. -APP_DISABLE_SIGNUP=__SIGNUP__ +APP_DISABLE_SIGNUP=__SIGN_BOLEAN__ # Enable user email verification. APP_SIGNUP_DOUBLE_OPTIN=false @@ -132,10 +132,10 @@ AWS_BUCKET= AWS_SERVER= # Allow Two Factor Authentication feature on your instance -MFA_ENABLED=__TWO_FACTOR__ +MFA_ENABLED=__TWOF_BOOLEAN__ # Enable DAV support -DAV_ENABLED=__DAV__ +DAV_ENABLED=__DAV_BOLEAN__ # CLIENT ID and SECRET used for OAuth authentication PASSPORT_PERSONAL_ACCESS_CLIENT_ID=__IDENTITY__ diff --git a/manifest.json b/manifest.json index 5cc62d6..f36e16c 100644 --- a/manifest.json +++ b/manifest.json @@ -14,12 +14,12 @@ "url": "http://github.com/rndmh3ro/monica_ynh" }, "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 4.1.3" }, "multi_instance": true, "services": [ "nginx", - "php7.0-fpm", + "php7.3-fpm", "mysql" ], "arguments": { @@ -27,38 +27,22 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain name for Monica", - "fr": "Choisissez un nom de domaine pour Monica" - }, - "example": "monicahq.com" + "example": "example.com" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Monica", - "fr": "Choisissez un chemin pour Monica" - }, "example": "/monica", "default": "/monica" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l’administrateur" - }, "example": "johndoe" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, "default": true }, { diff --git a/scripts/backup b/scripts/backup index bff4737..1b8fd1c 100755 --- 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 @@ -56,7 +56,7 @@ 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 A CRON FILE +# BACKUP VARIOUS FILES #================================================= ynh_backup --src_path="/etc/cron.d/$app" diff --git a/scripts/change_url b/scripts/change_url index d3a7955..b8e5fcd 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -36,7 +36,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." @@ -46,7 +46,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 @@ -80,8 +80,8 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # 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 - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # 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 domain="$old_domain" path_url="$new_path" @@ -92,11 +92,11 @@ fi # Change the domain for NGINX if [ $change_domain -eq 1 ] then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= diff --git a/scripts/install b/scripts/install index db4da99..e3dfc88 100755 --- a/scripts/install +++ b/scripts/install @@ -7,11 +7,9 @@ #================================================= source _common.sh -source ynh_composer__2 -source send_readme_to_admin +source ynh_send_readme_to_admin source /usr/share/yunohost/helpers - #================================================= # MANAGE SCRIPT FAILURE #================================================= @@ -57,7 +55,6 @@ ynh_script_progression --message="Storing installation settings..." 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=is_public --value=$is_public ynh_app_setting_set --app=$app --key=language --value=$language ynh_app_setting_set --app=$app --key=random_key --value=$random_key ynh_app_setting_set --app=$app --key=dav_support --value=$dav_support @@ -74,6 +71,14 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -96,6 +101,10 @@ pushd "$final_path" git checkout tags/$version popd +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -104,14 +113,6 @@ ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -131,48 +132,42 @@ ynh_script_progression --message="Installing Composer dependencies..." ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Adding a configuration file..." config="$final_path/.env" -cp ../conf/.env "$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="random_key" --replace_string="$random_key" --target_file="$config" -ynh_replace_string --match_string="yunouser" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="yunopass" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="yunobase" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="yunomail" --replace_string="$email" --target_file="$config" -ynh_replace_string --match_string="yunodomain" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="language" --replace_string="$language" --target_file="$config" # Enable or disable DAV support for users if [ $dav_support -eq 0 ] then - ynh_replace_string --match_string="__DAV__" --replace_string="false" --target_file="$config" + dav_boolean="false" dav="Yes" else - ynh_replace_string --match_string="__DAV__" --replace_string="true" --target_file="$config" + dav_boolean="true" dav="No" fi # Enable or disable signup for public users if [ $signup -eq 1 ] then - ynh_replace_string --match_string="__SIGNUP__" --replace_string="false" --target_file="$config" + sign_boolean="false" sign="No" else - ynh_replace_string --match_string="__SIGNUP__" --replace_string="true" --target_file="$config" + sign_boolean="true" sign="Yes" fi # Enable or disable two factor authentication support for users if [ $two_factor -eq 1 ] then - ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="true" --target_file="$config" + twof_boolean="true" twof="Yes" else - ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="false" --target_file="$config" + twof_boolean="false" twof="No" fi +ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="$twof_boolean" --target_file="$config" + +ynh_add_config --template="../conf/.env" --destination="$config" #================================================= # DEPLOY @@ -204,6 +199,9 @@ ynh_script_progression --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" +chmod 400 "$config" +chown $app:$app "$config" + #================================================= # INSTALL THE CRON FILE #================================================= @@ -214,19 +212,10 @@ mv -f /tmp/cron$app /etc/cron.d/$app #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions to app files -chown -R $app: $final_path -chmod -R 775 "$final_path/storage" - #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -237,9 +226,9 @@ then fi # Giver API permission to visitors -ynh_permission_create --permission="api" --url "/api" --allowed="visitors" --show_tile="false" --protected="true" +ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" # Giver DAV permission to visitors -ynh_permission_create --permission="dav" --url "/dav" --allowed="visitors" --show_tile="false" --protected="true" +ynh_permission_create --permission="dav" --url="/dav" --allowed="visitors" --show_tile="false" --protected="true" #================================================= # RELOAD NGINX diff --git a/scripts/remove b/scripts/remove index f5ada37..5fba8f1 100755 --- a/scripts/remove +++ b/scripts/remove @@ -66,9 +66,9 @@ ynh_remove_fpm_config #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing the cron file..." +ynh_script_progression --message="Removing various files..." # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" @@ -87,4 +87,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 4248aa3..37530e7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -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 @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -53,6 +53,14 @@ ynh_script_progression --message="Restoring the NGINX configuration..." 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..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -60,27 +68,14 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." - -# Restore permissions on app files -chown -R $app: $final_path -chmod -R 775 "$final_path/storage" +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="Restoring PHP-FPM configuration..." +ynh_script_progression --message="Restoring the PHP-FPM configuration..." ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" @@ -107,9 +102,9 @@ 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 CRON FILE +# RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring the cron file..." +ynh_script_progression --message="Restoring various files..." ynh_restore_file --origin_path="/etc/cron.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index b32f5b7..0c6e0e4 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_composer__2 source ynh_package_version source /usr/share/yunohost/helpers @@ -21,7 +20,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) -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) @@ -33,7 +31,6 @@ signup=$(ynh_app_setting_get --app=$app --key=signup) two_factor=$(ynh_app_setting_get --app=$app --key=two_factor) version=$(curl -s https://api.github.com/repos/monicahq/monica/releases/latest | grep 'tag_name' | cut -d\" -f4) - #================================================= # CHECK VERSION #================================================= @@ -41,20 +38,27 @@ 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)..." + +# 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..." -# 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) @@ -67,6 +71,19 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# Create a permission if needed +if ! ynh_permission_exists --permission="api"; then + ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" +fi + +#================================================= +# 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 + #================================================= # CHECK VERSION NUMBER #================================================= @@ -75,22 +92,6 @@ abort_if_up_to_date # previous function is what defines 'version', more precisely the 'previous version' previous_version="${version}" -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# 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 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -100,7 +101,8 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - if [ `cd $final_path && git rev-parse --is-inside-work-tree` ]; then + if git -C "$final_path" rev-parse --is-inside-work-tree` >/dev/null 2>/dev/null + then pushd "$final_path" git fetch git checkout tags/$version @@ -112,6 +114,10 @@ then fi ynh_app_setting_set --app=$app --key=version --value=$version +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -127,14 +133,6 @@ ynh_script_progression --message="Upgrading dependencies..." 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 #================================================= @@ -151,54 +149,45 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= ynh_script_progression --message="Updating PHP dependencies..." -chown -R $app: "$final_path" - ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="update" #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Updating a configuration file..." config="$final_path/.env" -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/.env "$config" -ynh_replace_string --match_string="random_key" --replace_string="$random_key" --target_file="$config" -ynh_replace_string --match_string="yunouser" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="yunopass" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="yunobase" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="yunomail" --replace_string="$email" --target_file="$config" -ynh_replace_string --match_string="yunodomain" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="language" --replace_string="$language" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" # Enable or disable DAV support for users if [ $dav_support -eq 0 ] then - ynh_replace_string --match_string="__DAV__" --replace_string="false" --target_file="$config" + dav_boolean="false" + dav="Yes" else - ynh_replace_string --match_string="__DAV__" --replace_string="true" --target_file="$config" - dav_support=1 - ynh_app_setting_set --app=$app --key=dav_support --value=$dav_support + dav_boolean="true" + dav="No" fi # Enable or disable signup for public users if [ $signup -eq 1 ] then - ynh_replace_string --match_string="__SIGNUP__" --replace_string="false" --target_file="$config" + sign_boolean="false" + sign="No" else - ynh_replace_string --match_string="__SIGNUP__" --replace_string="true" --target_file="$config" - signup=0 - ynh_app_setting_set --app=$app --key=signup --value=$signup + sign_boolean="true" + sign="Yes" fi # Enable or disable two factor authentication support for users if [ $two_factor -eq 1 ] then - ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="true" --target_file="$config" + twof_boolean="true" + twof="Yes" else - ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="false" --target_file="$config" - two_factor=0 - ynh_app_setting_set --app=$app --key=two_factor --value=$two_factor + twof_boolean="false" + twof="No" fi +ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="$twof_boolean" --target_file="$config" + +ynh_add_config --template="../conf/.env" --destination="$config" #================================================= # DEPLOYMENT @@ -255,16 +244,8 @@ ynh_script_progression --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" -#================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions on app files -chown -R $app: $final_path -chmod -R 775 "$final_path/storage" +chmod 400 "$config" +chown $app:$app "$config" #================================================= # INSTALL THE CRON FILE @@ -274,6 +255,8 @@ ynh_script_progression --message="Installing the cron file..." echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$app mv -f /tmp/cron$app /etc/cron.d/$app +#================================================= +# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 deleted file mode 100644 index 6b21e43..0000000 --- a/scripts/ynh_composer__2 +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -readonly YNH_DEFAULT_COMPOSER_VERSION=1.10.17 -# Declare the actual composer version to use. -# A packager willing to use another version of composer can override the variable into its _common.sh. -YNH_COMPOSER_VERSION=${YNH_COMPOSER_VERSION:-$YNH_DEFAULT_COMPOSER_VERSION} - -# 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"] [--composerversion=composerversion] -# | 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 -# | arg: -c, --composerversion - Composer version to install -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= [c]=composerversion=) - local phpversion - local workdir - local install_args - local composerversion - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-$YNH_PHP_VERSION}" - install_args="${install_args:-}" - composerversion="${composerversion:-$YNH_COMPOSER_VERSION}" - - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} -- --quiet --install-dir="$workdir" --version=$composerversion \ - || 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." -} \ No newline at end of file diff --git a/scripts/send_readme_to_admin b/scripts/ynh_send_readme_to_admin similarity index 100% rename from scripts/send_readme_to_admin rename to scripts/ynh_send_readme_to_admin From 452a7612ad8b01b7b46a830bf5df8c4171316ed6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 May 2021 10:03:52 +0200 Subject: [PATCH 2/6] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index f36e16c..f76755b 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "url": "http://github.com/rndmh3ro/monica_ynh" }, "requirements": { - "yunohost": ">= 4.1.3" + "yunohost": ">= 4.2.0" }, "multi_instance": true, "services": [ From bfe142f9006ef2aa06cece0c0a69089892a0f057 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 May 2021 10:24:25 +0200 Subject: [PATCH 3/6] Monica require php7.4 --- manifest.json | 2 +- scripts/_common.sh | 2 +- scripts/install | 1 - scripts/upgrade | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index f76755b..42ea66f 100644 --- a/manifest.json +++ b/manifest.json @@ -19,7 +19,7 @@ "multi_instance": true, "services": [ "nginx", - "php7.3-fpm", + "php7.4-fpm", "mysql" ], "arguments": { diff --git a/scripts/_common.sh b/scripts/_common.sh index d73ec6b..87839e5 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,7 +7,7 @@ # dependencies used by the app pkg_dependencies="redis-server" YNH_COMPOSER_VERSION="2.0.11" -YNH_PHP_VERSION="7.3" +YNH_PHP_VERSION="7.4" extra_php_dependencies="php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-opcache php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-bcmath php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-gmp php${YNH_PHP_VERSION}-redis" diff --git a/scripts/install b/scripts/install index e3dfc88..64cbb4d 100755 --- a/scripts/install +++ b/scripts/install @@ -165,7 +165,6 @@ else twof_boolean="false" twof="No" fi -ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="$twof_boolean" --target_file="$config" ynh_add_config --template="../conf/.env" --destination="$config" diff --git a/scripts/upgrade b/scripts/upgrade index 0c6e0e4..ada3a2e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -185,7 +185,6 @@ else twof_boolean="false" twof="No" fi -ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="$twof_boolean" --target_file="$config" ynh_add_config --template="../conf/.env" --destination="$config" From a78a1a42e7efaff67bd037acb0401404c12d2593 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 May 2021 10:33:34 +0200 Subject: [PATCH 4/6] Typo --- conf/.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/.env b/conf/.env index 3aa1046..179fc22 100644 --- a/conf/.env +++ b/conf/.env @@ -68,7 +68,7 @@ APP_DEFAULT_LOCALE=__LANGUAGE__ # Ability to disable signups on your instance. # Can be true or false. Default to false. -APP_DISABLE_SIGNUP=__SIGN_BOLEAN__ +APP_DISABLE_SIGNUP=__SIGN_BOOLEAN__ # Enable user email verification. APP_SIGNUP_DOUBLE_OPTIN=false @@ -135,7 +135,7 @@ AWS_SERVER= MFA_ENABLED=__TWOF_BOOLEAN__ # Enable DAV support -DAV_ENABLED=__DAV_BOLEAN__ +DAV_ENABLED=__DAV_BOOLEAN__ # CLIENT ID and SECRET used for OAuth authentication PASSPORT_PERSONAL_ACCESS_CLIENT_ID=__IDENTITY__ From 405a0e8c4aa8c8cddacaa8bfdcdeca687e77decd Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 May 2021 11:40:31 +0200 Subject: [PATCH 5/6] Upgrade to 3.0.1 --- README.md | 2 +- conf/.env | 4 ++-- conf/app.src | 6 +++--- manifest.json | 2 +- scripts/_common.sh | 4 +++- scripts/install | 25 ++++++++++++++++--------- scripts/restore | 3 +++ scripts/upgrade | 16 +++++++++++----- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 37522e8..7234005 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview Monica is an open-source web application to organize the interactions with your loved ones. I call it a PRM, or Personal Relationship Management. Think of it as a [CRM](https://en.wikipedia.org/wiki/Customer_relationship_management) (a popular tool used by sales teams in the corporate world) for your friends or family. -**Shipped version:** 2.19.1 +**Shipped version:** 3.0.1 ## Screenshots diff --git a/conf/.env b/conf/.env index 179fc22..d8d54d2 100644 --- a/conf/.env +++ b/conf/.env @@ -138,8 +138,8 @@ MFA_ENABLED=__TWOF_BOOLEAN__ DAV_ENABLED=__DAV_BOOLEAN__ # CLIENT ID and SECRET used for OAuth authentication -PASSPORT_PERSONAL_ACCESS_CLIENT_ID=__IDENTITY__ -PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET==__KEY__ +PASSPORT_PERSONAL_ACCESS_CLIENT_ID=_IDENTITY_ +PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET==_KEY_ # Allow to access general statistics about your instance through a public API # call diff --git a/conf/app.src b/conf/app.src index fc26531..22ade3d 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,6 @@ -SOURCE_URL=https://github.com/monicahq/monica/archive/v2.19.1.zip -SOURCE_SUM=f7ea6258fbc852453ca0dcb30685987d5e83a413dd0218ed99bdc5819ef597f7 +SOURCE_URL=https://github.com/monicahq/monica/archive/v3.0.1.zip +SOURCE_SUM=92e182b4b9fdeb11ff03390b22a5bb1931fdd643fca99ca697642b5f1e009736 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=v2.19.1.zip +SOURCE_FILENAME=v3.0.1.zip diff --git a/manifest.json b/manifest.json index 42ea66f..5bfd32b 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": " Personal Relationship Manager - a new kind of CRM to organize interactions with your friends and family." }, - "version": "2.19.1~ynh1", + "version": "3.0.1~ynh1", "url": "https://monicahq.com", "license": "GPL-3.0", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 87839e5..840a8ba 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,8 +8,10 @@ pkg_dependencies="redis-server" YNH_COMPOSER_VERSION="2.0.11" YNH_PHP_VERSION="7.4" +NODEJS_VERSION=14 -extra_php_dependencies="php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-opcache php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-bcmath php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-gmp php${YNH_PHP_VERSION}-redis" +extra_php_dependencies="php${YNH_PHP_VERSION}-bcmath php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-gmp php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-redis php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-zip \ +php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-opcache" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 64cbb4d..0e554b5 100755 --- a/scripts/install +++ b/scripts/install @@ -71,6 +71,9 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + #================================================= # CREATE DEDICATED USER #================================================= @@ -124,13 +127,6 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC SETUP -#================================================= -# INSTALL COMPOSER DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing Composer dependencies..." - -ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" - #================================================= # ADD A CONFIGURATION #================================================= @@ -168,20 +164,31 @@ fi ynh_add_config --template="../conf/.env" --destination="$config" +#================================================= +# INSTALL COMPOSER DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing Composer dependencies..." + +ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path" + #================================================= # DEPLOY #================================================= ynh_script_progression --message="Deploying..." pushd "$final_path" + ynh_use_nodejs + yarn install + yarn run production + php$phpversion artisan setup:production --email=$email --password=$password -n --force php$phpversion artisan passport:client --password -n > key.txt mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) private_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-private.key) public_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-public.key) - ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$config" + ynh_replace_string --match_string="_IDENTITY_" --replace_string="$mobile_id" --target_file="$config" + ynh_replace_string --match_string="_KEY_" --replace_string="$mobile_key" --target_file="$config" ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key ynh_app_setting_set --app=$app --key=private_key --value=$private_key diff --git a/scripts/restore b/scripts/restore index 37530e7..215ec0f 100755 --- a/scripts/restore +++ b/scripts/restore @@ -92,6 +92,9 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + #================================================= # RESTORE THE MYSQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index ada3a2e..8ff79c2 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -133,6 +133,9 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -193,7 +196,10 @@ ynh_add_config --template="../conf/.env" --destination="$config" #================================================= ynh_script_progression --message="Deploying..." -pushd "$final_path" +pushd "$final_path" + ynh_use_nodejs + yarn install + yarn run production php$phpversion artisan monica:update --force popd @@ -206,8 +212,8 @@ if [ -f $final_path/storage/oauth-private.key ]; then ynh_app_setting_set --app=$app --key=private_key --value=$private_key ynh_app_setting_set --app=$app --key=private_key --value=$public_key fi - ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$config" + ynh_replace_string --match_string="_IDENTITY_" --replace_string="$mobile_id" --target_file="$config" + ynh_replace_string --match_string="_KEY_" --replace_string="$mobile_key" --target_file="$config" else pushd "$final_path" php$phpversion artisan passport:keys @@ -217,8 +223,8 @@ else mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) private_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-private.key) public_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' storage/oauth-public.key) - ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$config" - ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$config" + ynh_replace_string --match_string="_IDENTITY_" --replace_string="$mobile_id" --target_file="$config" + ynh_replace_string --match_string="_KEY_" --replace_string="$mobile_key" --target_file="$config" ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key ynh_app_setting_set --app=$app --key=private_key --value=$private_key From a55a6fd96c7af92ee284d93ee3357181e8b10769 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 May 2021 12:11:45 +0200 Subject: [PATCH 6/6] Fix php for yarn --- scripts/install | 4 ++++ scripts/upgrade | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/scripts/install b/scripts/install index 0e554b5..06b170d 100755 --- a/scripts/install +++ b/scripts/install @@ -176,6 +176,8 @@ ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$f #================================================= ynh_script_progression --message="Deploying..." +update-alternatives --set php /usr/bin/php$phpversion + pushd "$final_path" ynh_use_nodejs yarn install @@ -197,6 +199,8 @@ pushd "$final_path" php$phpversion artisan config:clear popd +update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} + #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 8ff79c2..aa5ac43 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -196,6 +196,8 @@ ynh_add_config --template="../conf/.env" --destination="$config" #================================================= ynh_script_progression --message="Deploying..." +update-alternatives --set php /usr/bin/php$phpversion + pushd "$final_path" ynh_use_nodejs yarn install @@ -241,6 +243,8 @@ if ynh_version_gt "2.15.0" "${previous_version}" ; then popd fi +update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION} + #================================================= # STORE THE CONFIG FILE CHECKSUM #=================================================