diff --git a/README.md b/README.md
index 72516d4..37522e8 100644
--- a/README.md
+++ b/README.md
@@ -1,29 +1,28 @@
-# Monica app for YunoHost
+# Monica for YunoHost
+
+[](https://dash.yunohost.org/appci/app/monica)  
-[](https://dash.yunohost.org/appci/app/monica)  
[](https://install-app.yunohost.org/?app=monica)
-> *This package allows you to install Monica quickly and simply on a YunoHost server.
+> *This package allows you to install Monica quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## 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.17.0
+**Shipped version:** 2.19.1
## Screenshots
-
+
## Configuration
-Change the settings of the app by changing the values in .env
+Change the settings of the app by changing the values in `.env`
## YunoHost specific features
-#### Multi-user support
-
-**First User Registration:** Visit the app **domain** after the installation is complete to register as **first user**. After the first user is registered the registration will be **locked**. You can open the register for all by changing the value **APP_DISABLE_SIGNUP** to **false** in **.env**. There is **no admin interface** in the Monica app currently.
+- **First User:** An email with credentials for login will be sent to user who was chosen while the installation process of Monica. There is no **admin interface** on Monica, so every registered users will considered as normal user.
#### Supported architectures
@@ -37,23 +36,9 @@ Change the settings of the app by changing the values in .env
* Upstream app repository: https://github.com/monicahq/monica
* YunoHost website: https://yunohost.org/
-## Introduction
-
-
-## What works?
-* [X] Update and remove script
-* [X] Upgrade script
-* [X] Backup and restore script (**Need testing**)
-* [X] Multi-instance (**Need testing**)
-* [x] make root domain redirect to index.php
-* [x] Chang URL (Need testing,backup before trying this)
-* [ ] LDAP/SSO support
-* [x] Make monica installable into subdirectory (eg. https://example.com/monica/)
-
---
-Developer info
-----------------
+## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/monica_ynh/tree/testing).
diff --git a/check_process b/check_process
index 4f8e79e..9a26695 100644
--- a/check_process
+++ b/check_process
@@ -10,6 +10,9 @@
admin="john" (USER)
is_public=1 (PUBLIC|public=1|private=0)
language="fr"
+ dav_support=1 (DAV_SUPPORT|dav_support=1|dav_support=0)
+ signup=0 (SIGNUP|signup=1|signup=0)
+ two_factor=0 (TWO_FACTOR|two_factor=1|two_factor=0)
; Checks
pkg_linter=1
setup_sub_dir=0
@@ -22,6 +25,8 @@
upgrade=1 from_commit=36d8f49e08958c19f99eda858f83a64e98be7844
# 2.17.0~ynh1
upgrade=1 from_commit=4b497cf6445fc515070265721f40ceb816864bf1
+ # 2.17.0~ynh2
+ upgrade=1 from_commit=d03eaae18c5b99f7933ae18378d5567fc46389f5
backup_restore=1
multi_instance=1
# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
@@ -39,3 +44,5 @@ Notification=change
name=2.14.0
; commit=4b497cf6445fc515070265721f40ceb816864bf1
name=2.17.0~ynh1
+ ; commit=d03eaae18c5b99f7933ae18378d5567fc46389f5
+ name=2.17.0~ynh2
diff --git a/conf/.env b/conf/.env
index b7bde89..314e600 100644
--- a/conf/.env
+++ b/conf/.env
@@ -4,7 +4,7 @@
# Two choices: local|production. Use local if you want to install Monica as a
# development version. Use production otherwise.
-APP_ENV=local
+APP_ENV=production
# true if you want to show debug information on errors. For production, put this
# to false.
@@ -13,7 +13,7 @@ APP_DEBUG=false
# The encryption key. This is the most important part of the application. Keep
# this secure otherwise, everyone will be able to access your application.
# Must be 32 characters long exactly.
-# Use `php artisan key:generate` to generate a random key.
+# Use `php artisan key:generate` or `pwgen -s 32 1` to generate a random key.
APP_KEY=random_key
# Prevent information leakage by referring to IDs with hashIds instead of
@@ -24,8 +24,13 @@ HASH_LENGTH=18
# The URL of your application.
APP_URL=https://__DOMAIN__
+# Force using APP_URL as base url of your application.
+# You should not need this, unless you are using subdirectory config.
+APP_FORCE_URL=false
+
# Database information
# To keep this information secure, we urge you to change the default password
+# Currently only "mysql" compatible servers are working
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
@@ -45,7 +50,7 @@ DB_TEST_PASSWORD=secret
DB_USE_UTF8MB4=true
# Mail credentials used to send emails from the application.
-MAIL_DRIVER=mail
+MAIL_MAILER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=25
MAIL_USERNAME=
@@ -54,6 +59,7 @@ MAIL_ENCRYPTION=
# Outgoing emails will be sent with these identity
MAIL_FROM_ADDRESS=monica@yunodomain
MAIL_FROM_NAME="Monica"
+# New registration notification sent to this email
APP_EMAIL_NEW_USERS_NOTIFICATION=yunomail
@@ -62,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=true
+APP_DISABLE_SIGNUP=__SIGNUP__
# Enable user email verification.
APP_SIGNUP_DOUBLE_OPTIN=false
@@ -104,7 +110,7 @@ SESSION_LIFETIME=120
QUEUE_CONNECTION=sync
# If you use redis, set the redis host or ip, like:
-#REDIS_HOST=redis
+REDIS_HOST=redis
# Maximum allowed size for uploaded files, in kilobytes.
# Make sure this is an integer, without commas or spaces.
@@ -126,17 +132,14 @@ AWS_BUCKET=
AWS_SERVER=
# Allow Two Factor Authentication feature on your instance
-MFA_ENABLED=false
+MFA_ENABLED=__TWO_FACTOR__
# Enable DAV support
-DAV_ENABLED=true
+DAV_ENABLED=__DAV__
-# CLIENT ID and SECRET used for the official mobile application
-# This is to make sure that only the mobile application that you approve can
-# access the route to let your users sign in with their credentials
-# Note: the official mobile application is not currently available on the stores.
-MOBILE_CLIENT_ID=__IDENTITY__
-MOBILE_CLIENT_SECRET=__KEY__
+# CLIENT ID and SECRET used for OAuth authentication
+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
@@ -146,27 +149,6 @@ ALLOW_STATISTICS_THROUGH_PUBLIC_API_ACCESS=false
# like CASL or GDPR
POLICY_COMPLIANT=true
-# Have access to paid features available on https://monicahq.com, for free.
-# Can be true or false. Default to false.
-# If set to true, that means your users will have to pay to access the paid
-# features. We use Stripe to do this.
-REQUIRES_SUBSCRIPTION=false
-
-# Number of contacts allowed in the Free version if the instance requires
-# a subscription
-NUMBER_OF_ALLOWED_CONTACTS_FREE_ACCOUNT=10
-
-# ONLY NECESSARY IF MONICA REQUIRES A SUBSCRIPTION TO WORK
-# Leave blank unless you know what you are doing.
-STRIPE_KEY=
-STRIPE_SECRET=
-PAID_PLAN_MONTHLY_FRIENDLY_NAME=
-PAID_PLAN_MONTHLY_ID=
-PAID_PLAN_MONTHLY_PRICE=
-PAID_PLAN_ANNUAL_FRIENDLY_NAME=
-PAID_PLAN_ANNUAL_ID=
-PAID_PLAN_ANNUAL_PRICE=
-
# Enable geolocation services
# This is used to translate addresses to GPS coordinates.
ENABLE_GEOLOCATION=false
@@ -187,4 +169,4 @@ ENABLE_WEATHER=false
# https://darksky.net/dev/register
# Darksky provides an api with 1000 free API calls per day
# You need to enable the weather above if you provide an API key here.
-DARKSKY_API_KEY=
+DARKSKY_API_KEY=
\ No newline at end of file
diff --git a/conf/app.src b/conf/app.src
index 0750fdb..fc26531 100644
--- a/conf/app.src
+++ b/conf/app.src
@@ -1,6 +1,6 @@
-SOURCE_URL=https://github.com/monicahq/monica/archive/v2.17.0.zip
-SOURCE_SUM=834c91b901f84e4a14a7e4697c0b6226b9b0768ff0b0ed761029c4e9d765262c
+SOURCE_URL=https://github.com/monicahq/monica/archive/v2.19.1.zip
+SOURCE_SUM=f7ea6258fbc852453ca0dcb30685987d5e83a413dd0218ed99bdc5819ef597f7
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=true
-SOURCE_FILENAME=v2.17.0.zip
+SOURCE_FILENAME=v2.19.1.zip
diff --git a/conf/nginx.conf b/conf/nginx.conf
index a441f46..3358362 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -3,7 +3,7 @@ location ^~ __PATH__/ {
# Path to source
alias __FINALPATH__/public/;
-
+
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
@@ -13,7 +13,7 @@ location ^~ __PATH__/ {
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;
-
+
try_files $uri $uri/ @monica;
location ~ \.php {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
@@ -37,8 +37,8 @@ location @monica {
rewrite .well-known/security.txt$ __PATH__/security.txt permanent;
# Old carddav url
- rewrite carddav/(.*) __PATH__/dav/$1 permanent;
+ rewrite carddav/(.*) __PATH__/dav?/$1 permanent;
# rewrite all to index.php
- rewrite ^(.*)$ __PATH__/index.php/$1 last;
+ rewrite ^__PATH__/(.*)$ __PATH__/index.php?/$1 last;
}
diff --git a/issue_template.md b/issue_template.md
index 7b47b30..5d6c499 100644
--- a/issue_template.md
+++ b/issue_template.md
@@ -7,7 +7,7 @@ about: Create a report to help us debug, it would be nice to fill the template a
**How to post a meaningful bug report**
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!*
+ - *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 Monica itself. Refer to its documentation or repository for help.*
- *If you have a doubt, post here, we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
@@ -34,8 +34,8 @@ about: Create a report to help us debug, it would be nice to fill the template a
- *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:*
1. *Go to '...'*
- 2. *Click on '....'*
- 3. *Scroll down to '....'*
+ 2. *Click on '...'*
+ 3. *Scroll down to '...'*
4. *See error*
**Expected behavior**
diff --git a/manifest.json b/manifest.json
index f4360d9..5cc62d6 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.17.0~ynh2",
+ "version": "2.19.1~ynh1",
"url": "https://monicahq.com",
"license": "GPL-3.0",
"maintainer": {
@@ -14,7 +14,7 @@
"url": "http://github.com/rndmh3ro/monica_ynh"
},
"requirements": {
- "yunohost": ">= 3.5"
+ "yunohost": ">= 3.8.1"
},
"multi_instance": true,
"services": [
@@ -70,6 +70,33 @@
},
"choices": ["cs","de","en","es","fr","he","it","nl","pt","ru","zh"],
"default": "en"
+ },
+ {
+ "name": "dav_support",
+ "type": "boolean",
+ "ask": {
+ "en": "Enable DAV support?",
+ "fr": "Activer le support DAV ?"
+ },
+ "default": true
+ },
+ {
+ "name": "signup",
+ "type": "boolean",
+ "ask": {
+ "en": "Enable signup for public users?",
+ "fr": "Activer l'inscription pour les utilisateurs publics ?"
+ },
+ "default": false
+ },
+ {
+ "name": "two_factor",
+ "type": "boolean",
+ "ask": {
+ "en": "Enable Two Factor Authentication for accounts?",
+ "fr": "Activer l'authentification à deux facteurs pour les comptes ?"
+ },
+ "default": false
}
]
}
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 0f97942..d73ec6b 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -5,11 +5,11 @@
#=================================================
# dependencies used by the app
-pkg_dependencies=""
-
+pkg_dependencies="redis-server"
+YNH_COMPOSER_VERSION="2.0.11"
YNH_PHP_VERSION="7.3"
-extra_php_dependencies="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}-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"
#=================================================
# PERSONAL HELPERS
diff --git a/scripts/change_url b/scripts/change_url
index 2024b5d..d3a7955 100644
--- a/scripts/change_url
+++ b/scripts/change_url
@@ -38,7 +38,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
-ynh_script_progression --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
@@ -73,22 +73,23 @@ fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
+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,14 +103,16 @@ fi
# SPECIFIC MODIFICATIONS
#=================================================
# Run monica update
-cd $final_path && sudo /usr/bin/php7.2 artisan monica:update --force
+pushd "$final_path"
+ php$phpversion artisan monica:update --force
+popd
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/install b/scripts/install
index 14420d7..db4da99 100755
--- a/scripts/install
+++ b/scripts/install
@@ -8,8 +8,10 @@
source _common.sh
source ynh_composer__2
+source send_readme_to_admin
source /usr/share/yunohost/helpers
+
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
@@ -28,6 +30,11 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
random_key=$(ynh_string_random --length=32)
email=$(ynh_user_get_info $admin 'mail')
+password=$(ynh_string_random --length=10)
+dav_support=$YNH_APP_ARG_DAV_SUPPORT
+signup=$YNH_APP_ARG_SIGNUP
+two_factor=$YNH_APP_ARG_TWO_FACTOR
+version=$(curl -s https://api.github.com/repos/monicahq/monica/releases/latest | grep 'tag_name' | cut -d\" -f4)
app=$YNH_APP_INSTANCE_NAME
@@ -53,20 +60,24 @@ 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
+ynh_app_setting_set --app=$app --key=signup --value=$signup
+ynh_app_setting_set --app=$app --key=two_factor --value=$two_factor
+ynh_app_setting_set --app=$app --key=version --value=$version
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
-ynh_script_progression --message="Installing dependencies..."
+ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
-ynh_script_progression --message="Creating a MySQL database..."
+ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
@@ -80,20 +91,23 @@ ynh_script_progression --message="Setting up source files..."
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"
+git clone https://github.com/monicahq/monica.git $final_path
+pushd "$final_path"
+ git checkout tags/$version
+popd
#=================================================
# NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Configuring nginx web server..."
+ynh_script_progression --message="Configuring NGINX web server..."
-# Create a dedicated nginx config
+# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
-ynh_script_progression --message="Configuring system user..."
+ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app
@@ -101,9 +115,9 @@ ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
-ynh_script_progression --message="Configuring php-fpm..."
+ynh_script_progression --message="Configuring PHP-FPM..."
-# Create a dedicated php-fpm config
+# Create a dedicated PHP-FPM config
ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies"
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
@@ -112,7 +126,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# INSTALL COMPOSER DEPENDENCIES
#=================================================
-ynh_script_progression --message="Installing composer dependencies..."
+ynh_script_progression --message="Installing Composer dependencies..."
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path"
@@ -132,6 +146,33 @@ ynh_replace_string --match_string="yunobase" --replace_string="$db_name" --targe
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="Yes"
+else
+ ynh_replace_string --match_string="__DAV__" --replace_string="true" --target_file="$config"
+ 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="No"
+else
+ ynh_replace_string --match_string="__SIGNUP__" --replace_string="true" --target_file="$config"
+ 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="Yes"
+else
+ ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="false" --target_file="$config"
+ twof="No"
+fi
#=================================================
# DEPLOY
@@ -139,16 +180,20 @@ ynh_replace_string --match_string="language" --replace_string="$language" --targ
ynh_script_progression --message="Deploying..."
pushd "$final_path"
- php$phpversion artisan monica:update --force
- php$phpversion artisan passport:keys
+ 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_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
+ ynh_app_setting_set --app=$app --key=private_key --value=$public_key
rm -f key.txt
+ php$phpversion artisan config:clear
popd
#=================================================
@@ -164,8 +209,8 @@ ynh_store_file_checksum --file="$config"
#=================================================
ynh_script_progression --message="Installing the cron file..."
-echo "* * * * * -u $app /usr/bin/php7.2 $final_path/artisan schedule:run" > /tmp/cron$app
-mv /tmp/cron$app /etc/cron.d/$app
+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
@@ -176,28 +221,62 @@ 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 SSOwat..."
# 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
+# Giver API permission to visitors
+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"
+
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
+#=================================================
+# SEND A README FOR THE ADMIN
+#=================================================
+# WARNING : theses command are used in INSTALL
+# For any update do it in all files
+
+echo "
+-----------------------------------------------------------
+|
+| Welcome to Monica
+|
+-----------------------------------------------------------
+| You can now sign in to your account:
+| username: $email
+| password: $password
+| URL: https://$domain
+| Dav support: $dav
+| Allowed registration for new users: $sign
+| Allowed Two Factor Authentication for accounts: $twof
+| It is advised to change your password after first login.
+-----------------------------------------------------------
+Setup is done. Have fun.
+
+" > mail_to_send
+
+ynh_send_readme_to_admin --app_message="mail_to_send" --type="install" --recipients="$email"
+
#=================================================
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Installation of $app completed" --last
+ynh_script_progression --message="Installation of $app completed"
diff --git a/scripts/remove b/scripts/remove
index f007d4a..f5ada37 100755
--- a/scripts/remove
+++ b/scripts/remove
@@ -50,17 +50,17 @@ ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Removing nginx web server configuration..."
+ynh_script_progression --message="Removing NGINX web server configuration..."
-# Remove the dedicated nginx config
+# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
-ynh_script_progression --message="Removing php-fpm configuration..."
+ynh_script_progression --message="Removing PHP-FPM configuration..."
-# Remove the dedicated php-fpm config
+# Remove the dedicated PHP-FPM config
ynh_remove_fpm_config
#=================================================
diff --git a/scripts/restore b/scripts/restore
index fb6f540..4248aa3 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -37,7 +37,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
-ynh_script_progression --message="Validating restoration parameters..."
+ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
@@ -49,7 +49,7 @@ test ! -d $final_path \
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Restoring the nginx configuration..."
+ynh_script_progression --message="Restoring the NGINX configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
@@ -75,6 +75,7 @@ ynh_script_progression --message="Restoring user rights..."
# Restore permissions on app files
chown -R $app: $final_path
+chmod -R 775 "$final_path/storage"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
@@ -83,7 +84,7 @@ ynh_script_progression --message="Restoring PHP-FPM configuration..."
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
-# Recreate a dedicated php-fpm config
+# Recreate a dedicated PHP-FPM config
ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies"
#=================================================
@@ -117,7 +118,7 @@ ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
-ynh_script_progression --message="Reloading nginx web server and php-fpm..."
+ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
@@ -126,4 +127,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
-ynh_script_progression --message="Restoration completed for $app"
+ynh_script_progression --message="Restoration completed for $app"
diff --git a/scripts/send_readme_to_admin b/scripts/send_readme_to_admin
new file mode 100644
index 0000000..223b08d
--- /dev/null
+++ b/scripts/send_readme_to_admin
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+# Send an email to inform the administrator
+#
+# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
+# | arg: -m --app_message= - The file with the content to send to the administrator.
+# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
+# example: "root admin@domain"
+# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
+# example: "root admin@domain user1 user2"
+# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
+ynh_send_readme_to_admin() {
+ # Declare an array to define the options of this helper.
+ declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
+ local app_message
+ local recipients
+ local type
+ # Manage arguments with getopts
+
+ ynh_handle_getopts_args "$@"
+ app_message="${app_message:-}"
+ recipients="${recipients:-root}"
+ type="${type:-install}"
+
+ # Get the value of admin_mail_html
+ admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
+ admin_mail_html="${admin_mail_html:-0}"
+
+ # Retrieve the email of users
+ find_mails () {
+ local list_mails="$1"
+ local mail
+ local recipients=" "
+ # Read each mail in argument
+ for mail in $list_mails
+ do
+ # Keep root or a real email address as it is
+ if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
+ then
+ recipients="$recipients $mail"
+ else
+ # But replace an user name without a domain after by its email
+ if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
+ then
+ recipients="$recipients $mail"
+ fi
+ fi
+ done
+ echo "$recipients"
+ }
+ recipients=$(find_mails "$recipients")
+
+ # Subject base
+ local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
+
+ # Adapt the subject according to the type of mail required.
+ if [ "$type" = "backup" ]; then
+ mail_subject="$mail_subject has just been backup."
+ elif [ "$type" = "change_url" ]; then
+ mail_subject="$mail_subject has just been moved to a new URL!"
+ elif [ "$type" = "remove" ]; then
+ mail_subject="$mail_subject has just been removed!"
+ elif [ "$type" = "restore" ]; then
+ mail_subject="$mail_subject has just been restored!"
+ elif [ "$type" = "upgrade" ]; then
+ mail_subject="$mail_subject has just been upgraded!"
+ else # install
+ mail_subject="$mail_subject has just been installed!"
+ fi
+
+ local mail_message="This is an automated message from your beloved YunoHost server.
+Specific information for the application $app.
+$(if [ -n "$app_message" ]
+then
+ cat "$app_message"
+else
+ echo "...No specific information..."
+fi)
+---
+Automatic diagnosis data from YunoHost
+__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
+
+ # Store the message into a file for further modifications.
+ echo "$mail_message" > mail_to_send
+
+ # If a html email is required. Apply html tags to the message.
+ if [ "$admin_mail_html" -eq 1 ]
+ then
+ # Insert 'br' tags at each ending of lines.
+ ynh_replace_string "$" "
" mail_to_send
+
+ # Insert starting HTML tags
+ sed --in-place '1s@^@\n\n
" mail_to_send + ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send + + # Insert finishing HTML tags + echo -e "\n\n" >> mail_to_send + + # Otherwise, remove tags to keep a plain text. + else + # Remove URL tags + ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send + ynh_replace_string "__URL_TAG2__" ": " mail_to_send + + # Remove PRE tags + ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send + fi + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + if [ "$admin_mail_html" -eq 1 ] + then + content_type="text/html" + else + content_type="text/plain" + fi + + # Send the email to the recipients + cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" +} \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index ab83977..b32f5b7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -28,6 +28,11 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) random_key=$(ynh_app_setting_get --app=$app --key=random_key) email=$(ynh_user_get_info --username=$admin --key=mail) +dav_support=$(ynh_app_setting_get --app=$app --key=dav_support) +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 @@ -84,13 +89,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -102,15 +100,24 @@ then ynh_script_progression --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + if [ `cd $final_path && git rev-parse --is-inside-work-tree` ]; then + pushd "$final_path" + git fetch + git checkout tags/$version + popd + else + ynh_setup_source --dest_dir="$final_path" + fi + fi +ynh_app_setting_set --app=$app --key=version --value=$version #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading NGINX web server configuration..." -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= @@ -123,7 +130,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create --username=$app @@ -131,9 +138,9 @@ ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." +ynh_script_progression --message="Upgrading PHP-FPM configuration..." -# Create a dedicated php-fpm config +# Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) @@ -142,9 +149,9 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # UPDATE PHP DEPENDENCIES #================================================= -ynh_script_progression --message="Updating php dependencies..." +ynh_script_progression --message="Updating PHP dependencies..." -chown -R "$app": "$final_path" +chown -R $app: "$final_path" ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="update" @@ -164,7 +171,34 @@ ynh_replace_string --match_string="yunobase" --replace_string="$db_name" - 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" +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" +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 +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" +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 +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" +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 +fi #================================================= # DEPLOYMENT @@ -178,6 +212,12 @@ popd if [ -f $final_path/storage/oauth-private.key ]; then mobile_id=$(ynh_app_setting_get --app=$app --key=mobile_id) mobile_key=$(ynh_app_setting_get --app=$app --key=mobile_key) + if [ -z $(ynh_app_setting_get --app=$app --key=private_key) ]; then + private_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $final_path/storage/oauth-private.key) + public_key=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $final_path/storage/oauth-public.key) + 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" else @@ -186,11 +226,17 @@ else php$phpversion artisan passport:client --password -n > key.txt mobile_id=$( tail -2 key.txt | head -1 | cut -c 12- ) mobile_key=$( tail -1 key.txt | cut -c 16- ) + 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_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 + ynh_app_setting_set --app=$app --key=private_key --value=$public_key rm -f key.txt + php$phpversion artisan config:clear popd fi @@ -218,23 +264,20 @@ ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R $app: $final_path +chmod -R 775 "$final_path/storage" #================================================= -# SETUP SSOWAT +# INSTALL THE CRON FILE #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." +ynh_script_progression --message="Installing the cron file..." -# 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 +echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$app +mv -f /tmp/cron$app /etc/cron.d/$app #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -242,4 +285,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 index 6f9676b..6b21e43 100644 --- a/scripts/ynh_composer__2 +++ b/scripts/ynh_composer__2 @@ -1,5 +1,10 @@ #!/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" @@ -20,34 +25,37 @@ ynh_composer_exec () { COMPOSER_HOME="$workdir/.composer" \ php${phpversion} "$workdir/composer.phar" $commands \ - -d "$workdir" --no-interaction + -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"] +# 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=) + 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} -- --install-dir="$workdir" \ + 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