1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monica_ynh.git synced 2024-09-03 19:46:23 +02:00

Merge pull request #47 from YunoHost-Apps/example

Apply last example_ynh
This commit is contained in:
yalh76 2021-06-10 23:37:52 +02:00 committed by GitHub
commit 567f9a24ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 170 additions and 269 deletions

View file

@ -10,7 +10,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview ## 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. 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 ## Screenshots

View file

@ -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 ;; Test complet
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld"
path="/" (PATH) path="/path"
admin="john" (USER) admin="john"
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
language="fr" language="fr"
dav_support=1 dav_support=1
@ -33,9 +28,6 @@
# incorrect_path=1 # incorrect_path=1
port_already_use=0 port_already_use=0
change_url=0 change_url=0
;;; Levels
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
Level 5=auto
;;; Options ;;; Options
Email=anmol@datamol.org Email=anmol@datamol.org
Notification=change Notification=change

View file

@ -14,7 +14,7 @@ APP_DEBUG=false
# this secure otherwise, everyone will be able to access your application. # this secure otherwise, everyone will be able to access your application.
# Must be 32 characters long exactly. # Must be 32 characters long exactly.
# Use `php artisan key:generate` or `pwgen -s 32 1` to generate a random key. # 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 # Prevent information leakage by referring to IDs with hashIds instead of
# the actual IDs used in the database. # the actual IDs used in the database.
@ -36,9 +36,9 @@ DB_HOST=127.0.0.1
DB_PORT=3306 DB_PORT=3306
# You can use mysql unix socket if available, it overrides DB_HOST and DB_PORT values. # 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_UNIX_SOCKET=/var/run/mysqld/mysqld.sock
DB_DATABASE=yunobase DB_DATABASE=__DB_NAME__
DB_USERNAME=yunouser DB_USERNAME=__DB_USER__
DB_PASSWORD=yunopass DB_PASSWORD=__DB_PWD__
DB_PREFIX= DB_PREFIX=
DB_TEST_HOST=127.0.0.1 DB_TEST_HOST=127.0.0.1
DB_TEST_DATABASE=monica_test DB_TEST_DATABASE=monica_test
@ -57,18 +57,18 @@ MAIL_USERNAME=
MAIL_PASSWORD= MAIL_PASSWORD=
MAIL_ENCRYPTION= MAIL_ENCRYPTION=
# Outgoing emails will be sent with these identity # Outgoing emails will be sent with these identity
MAIL_FROM_ADDRESS=monica@yunodomain MAIL_FROM_ADDRESS=monica@__DOMAIN__
MAIL_FROM_NAME="Monica" MAIL_FROM_NAME="Monica"
# New registration notification sent to this email # 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. # Default locale used in the application.
APP_DEFAULT_LOCALE=language APP_DEFAULT_LOCALE=__LANGUAGE__
# Ability to disable signups on your instance. # Ability to disable signups on your instance.
# Can be true or false. Default to false. # Can be true or false. Default to false.
APP_DISABLE_SIGNUP=__SIGNUP__ APP_DISABLE_SIGNUP=__SIGN_BOOLEAN__
# Enable user email verification. # Enable user email verification.
APP_SIGNUP_DOUBLE_OPTIN=false APP_SIGNUP_DOUBLE_OPTIN=false
@ -132,14 +132,14 @@ AWS_BUCKET=
AWS_SERVER= AWS_SERVER=
# Allow Two Factor Authentication feature on your instance # Allow Two Factor Authentication feature on your instance
MFA_ENABLED=__TWO_FACTOR__ MFA_ENABLED=__TWOF_BOOLEAN__
# Enable DAV support # Enable DAV support
DAV_ENABLED=__DAV__ DAV_ENABLED=__DAV_BOOLEAN__
# CLIENT ID and SECRET used for OAuth authentication # CLIENT ID and SECRET used for OAuth authentication
PASSPORT_PERSONAL_ACCESS_CLIENT_ID=__IDENTITY__ PASSPORT_PERSONAL_ACCESS_CLIENT_ID=_IDENTITY_
PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET==__KEY__ PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET==_KEY_
# Allow to access general statistics about your instance through a public API # Allow to access general statistics about your instance through a public API
# call # call

View file

@ -1,6 +1,6 @@
SOURCE_URL=https://github.com/monicahq/monica/archive/v2.19.1.zip SOURCE_URL=https://github.com/monicahq/monica/archive/v3.0.1.zip
SOURCE_SUM=f7ea6258fbc852453ca0dcb30685987d5e83a413dd0218ed99bdc5819ef597f7 SOURCE_SUM=92e182b4b9fdeb11ff03390b22a5bb1931fdd643fca99ca697642b5f1e009736
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=v2.19.1.zip SOURCE_FILENAME=v3.0.1.zip

View file

@ -5,7 +5,7 @@
"description": { "description": {
"en": " Personal Relationship Manager - a new kind of CRM to organize interactions with your friends and family." "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", "url": "https://monicahq.com",
"license": "GPL-3.0", "license": "GPL-3.0",
"maintainer": { "maintainer": {
@ -14,12 +14,12 @@
"url": "http://github.com/rndmh3ro/monica_ynh" "url": "http://github.com/rndmh3ro/monica_ynh"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.8.1" "yunohost": ">= 4.2.0"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
"nginx", "nginx",
"php7.0-fpm", "php7.4-fpm",
"mysql" "mysql"
], ],
"arguments": { "arguments": {
@ -27,38 +27,22 @@
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": { "example": "example.com"
"en": "Choose a domain name for Monica",
"fr": "Choisissez un nom de domaine pour Monica"
},
"example": "monicahq.com"
}, },
{ {
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": {
"en": "Choose a path for Monica",
"fr": "Choisissez un chemin pour Monica"
},
"example": "/monica", "example": "/monica",
"default": "/monica" "default": "/monica"
}, },
{ {
"name": "admin", "name": "admin",
"type": "user", "type": "user",
"ask": {
"en": "Choose an admin user",
"fr": "Choisissez ladministrateur"
},
"example": "johndoe" "example": "johndoe"
}, },
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"ask": {
"en": "Is it a public application?",
"fr": "Est-ce une application publique ?"
},
"default": true "default": true
}, },
{ {

View file

@ -7,9 +7,11 @@
# dependencies used by the app # dependencies used by the app
pkg_dependencies="redis-server" pkg_dependencies="redis-server"
YNH_COMPOSER_VERSION="2.0.11" YNH_COMPOSER_VERSION="2.0.11"
YNH_PHP_VERSION="7.3" 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 # PERSONAL HELPERS

View file

@ -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" 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" ynh_backup --src_path="/etc/cron.d/$app"

View file

@ -36,7 +36,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) 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)..." 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. # 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" 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 ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script

89
scripts/install Executable file → Normal file
View file

@ -7,11 +7,9 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_composer__2 source ynh_send_readme_to_admin
source send_readme_to_admin
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # 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=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url 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=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=language --value=$language
ynh_app_setting_set --app=$app --key=random_key --value=$random_key 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=dav_support --value=$dav_support
@ -74,6 +71,17 @@ ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_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
#=================================================
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 # CREATE A MYSQL DATABASE
#================================================= #=================================================
@ -96,6 +104,10 @@ pushd "$final_path"
git checkout tags/$version git checkout tags/$version
popd popd
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
@ -104,14 +116,6 @@ ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_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 # PHP-FPM CONFIGURATION
#================================================= #=================================================
@ -124,28 +128,12 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# INSTALL COMPOSER DEPENDENCIES # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Installing Composer dependencies..." ynh_script_progression --message="Adding a configuration file..."
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path"
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..."
config="$final_path/.env" 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 # Enable or disable DAV support for users
if [ $dav_support -eq 0 ] if [ $dav_support -eq 0 ]
then then
@ -177,24 +165,35 @@ else
twof="No" twof="No"
fi fi
ynh_replace_string --match_string="__DAV__" --replace_string="$dav_boolean" --target_file="$config" ynh_add_config --template="../conf/.env" --destination="$config"
ynh_replace_string --match_string="__SIGNUP__" --replace_string="$sign_boolean" --target_file="$config"
ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="$twof_boolean" --target_file="$config" #=================================================
# INSTALL COMPOSER DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing Composer dependencies..."
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path"
#================================================= #=================================================
# DEPLOY # DEPLOY
#================================================= #=================================================
ynh_script_progression --message="Deploying..." ynh_script_progression --message="Deploying..."
update-alternatives --set php /usr/bin/php$phpversion
pushd "$final_path" 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 setup:production --email=$email --password=$password -n --force
php$phpversion artisan passport:client --password -n > key.txt php$phpversion artisan passport:client --password -n > key.txt
mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) 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- ) 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) 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) 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="_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="_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_id --value=$mobile_id
ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key 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=$private_key
@ -203,6 +202,8 @@ pushd "$final_path"
php$phpversion artisan config:clear php$phpversion artisan config:clear
popd popd
update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION}
#================================================= #=================================================
# STORE THE CONFIG FILE CHECKSUM # STORE THE CONFIG FILE CHECKSUM
#================================================= #=================================================
@ -211,6 +212,9 @@ ynh_script_progression --message="Storing the config file checksum..."
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config" ynh_store_file_checksum --file="$config"
chmod 400 "$config"
chown $app:$app "$config"
#================================================= #=================================================
# INSTALL THE CRON FILE # INSTALL THE CRON FILE
#================================================= #=================================================
@ -221,19 +225,10 @@ mv -f /tmp/cron$app /etc/cron.d/$app
#================================================= #=================================================
# GENERIC FINALIZATION # 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 775 "$final_path/storage"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
@ -244,9 +239,9 @@ then
fi fi
# Giver API permission to visitors # 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 # 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 # RELOAD NGINX

View file

@ -66,9 +66,9 @@ ynh_remove_fpm_config
#================================================= #=================================================
# SPECIFIC REMOVE # 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 # Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app" ynh_secure_remove --file="/etc/cron.d/$app"

38
scripts/restore Executable file → Normal file
View file

@ -23,7 +23,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME 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" 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 # 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" ynh_restore_file --origin_path="$final_path"
#================================================= chmod 750 "$final_path"
# RECREATE THE DEDICATED USER chmod -R o-rwx "$final_path"
#================================================= chown -R $app:www-data "$final_path"
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 775 "$final_path/storage"
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # 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" ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
@ -97,6 +92,9 @@ ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_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 # RESTORE THE MYSQL DATABASE
#================================================= #=================================================
@ -107,9 +105,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 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" ynh_restore_file --origin_path="/etc/cron.d/$app"

141
scripts/upgrade Executable file → Normal file
View file

@ -7,7 +7,6 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_composer__2
source ynh_package_version source ynh_package_version
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -21,7 +20,6 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin) 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) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
language=$(ynh_app_setting_get --app=$app --key=language) language=$(ynh_app_setting_get --app=$app --key=language)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) 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) 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) version=$(curl -s https://api.github.com/repos/monicahq/monica/releases/latest | grep 'tag_name' | cut -d\" -f4)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
@ -41,20 +38,27 @@ ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) 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 # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring 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 db_name doesn't exist, create it
if [ -z "$db_name" ]; then if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app) 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 ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi 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 # CHECK VERSION NUMBER
#================================================= #=================================================
@ -75,22 +92,6 @@ abort_if_up_to_date
# previous function is what defines 'version', more precisely the 'previous version' # previous function is what defines 'version', more precisely the 'previous version'
previous_version="${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 # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -113,6 +114,10 @@ then
fi fi
ynh_app_setting_set --app=$app --key=version --value=$version 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 # NGINX CONFIGURATION
#================================================= #=================================================
@ -128,13 +133,8 @@ ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#================================================= ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
# CREATE DEDICATED USER ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
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 # PHP-FPM CONFIGURATION
@ -152,61 +152,56 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#================================================= #=================================================
ynh_script_progression --message="Updating PHP dependencies..." 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" 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" 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 # Enable or disable DAV support for users
if [ $dav_support -eq 0 ] if [ $dav_support -eq 0 ]
then then
ynh_replace_string --match_string="__DAV__" --replace_string="false" --target_file="$config" dav_boolean="false"
dav="Yes"
else else
ynh_replace_string --match_string="__DAV__" --replace_string="true" --target_file="$config" dav_boolean="true"
dav_support=1 dav="No"
ynh_app_setting_set --app=$app --key=dav_support --value=$dav_support
fi fi
# Enable or disable signup for public users # Enable or disable signup for public users
if [ $signup -eq 1 ] if [ $signup -eq 1 ]
then then
ynh_replace_string --match_string="__SIGNUP__" --replace_string="false" --target_file="$config" sign_boolean="false"
sign="No"
else else
ynh_replace_string --match_string="__SIGNUP__" --replace_string="true" --target_file="$config" sign_boolean="true"
signup=0 sign="Yes"
ynh_app_setting_set --app=$app --key=signup --value=$signup
fi fi
# Enable or disable two factor authentication support for users # Enable or disable two factor authentication support for users
if [ $two_factor -eq 1 ] if [ $two_factor -eq 1 ]
then then
ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="true" --target_file="$config" twof_boolean="true"
twof="Yes"
else else
ynh_replace_string --match_string="__TWO_FACTOR__" --replace_string="false" --target_file="$config" twof_boolean="false"
two_factor=0 twof="No"
ynh_app_setting_set --app=$app --key=two_factor --value=$two_factor
fi fi
ynh_add_config --template="../conf/.env" --destination="$config"
#================================================= #=================================================
# DEPLOYMENT # DEPLOYMENT
#================================================= #=================================================
ynh_script_progression --message="Deploying..." ynh_script_progression --message="Deploying..."
update-alternatives --set php /usr/bin/php$phpversion
pushd "$final_path" pushd "$final_path"
ynh_use_nodejs
yarn install
yarn run production
php$phpversion artisan monica:update --force php$phpversion artisan monica:update --force
popd popd
@ -219,8 +214,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=$private_key
ynh_app_setting_set --app=$app --key=private_key --value=$public_key ynh_app_setting_set --app=$app --key=private_key --value=$public_key
fi fi
ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --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_replace_string --match_string="_KEY_" --replace_string="$mobile_key" --target_file="$config"
else else
pushd "$final_path" pushd "$final_path"
php$phpversion artisan passport:keys php$phpversion artisan passport:keys
@ -230,8 +225,8 @@ else
mobile_key=$( cd $final_path && 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) 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) 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="_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="_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_id --value=$mobile_id
ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key 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=$private_key
@ -248,6 +243,8 @@ if ynh_version_gt "2.15.0" "${previous_version}" ; then
popd popd
fi fi
update-alternatives --set php /usr/bin/php${YNH_DEFAULT_PHP_VERSION}
#================================================= #=================================================
# STORE THE CONFIG FILE CHECKSUM # STORE THE CONFIG FILE CHECKSUM
#================================================= #=================================================
@ -256,16 +253,8 @@ ynh_script_progression --message="Storing the config file checksum..."
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config" ynh_store_file_checksum --file="$config"
#================================================= chmod 400 "$config"
# GENERIC FINALIZATION chown $app:$app "$config"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions on app files
chown -R $app: $final_path
chmod 775 "$final_path/storage"
#================================================= #=================================================
# INSTALL THE CRON FILE # INSTALL THE CRON FILE
@ -275,6 +264,8 @@ ynh_script_progression --message="Installing the cron file..."
echo "* * * * * -u $app /usr/bin/php$phpversion $final_path/artisan schedule:run" > /tmp/cron$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 mv -f /tmp/cron$app /etc/cron.d/$app
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================

View file

@ -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."
}