1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/trilium_ynh.git synced 2024-10-01 13:34:49 +02:00

Merge pull request #38 from p4p4j0hn/packaging_v2

Packaging v2 and upgrade to v0.58.8
This commit is contained in:
Éric Gaspar 2023-02-28 08:52:33 +01:00 committed by GitHub
commit b5a601f7e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 240 additions and 499 deletions

View file

@ -1,21 +0,0 @@
;; Test complet
; Manifest
domain="domain.tld"
is_public=1
instance_name="MyTrillium"
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=ad97756d628eb8f95095bbed2d00915698ef6bb0
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none

View file

@ -1,7 +1,7 @@
SOURCE_URL=https://github.com/zadam/trilium/archive/refs/tags/v0.58.7.tar.gz SOURCE_URL=https://github.com/zadam/trilium/archive/refs/tags/v0.58.8.tar.gz
SOURCE_SUM=98f9f48fe32e6add383af724244ec5e57fbe7fc03169e69b79db983ff39a85cf SOURCE_SUM=a4b8d062bfacaa47bcde6356c8a5be0fe114f3f8db78c697e7f6cc4a72c03593
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=v0.58.7.tar.gz SOURCE_FILENAME=v0.58.8.tar.gz
SOURCE_EXTRACT=true SOURCE_EXTRACT=true

View file

@ -6,13 +6,13 @@ After=network.target
Type=simple Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
Environment=TRILIUM_DATA_DIR=__DATADIR__ Environment=TRILIUM_DATA_DIR=__DATA_DIR__
Environment=TRILIUM_PORT=__PORT__ Environment=TRILIUM_PORT=__PORT__
Environment="__YNH_NODE_LOAD_PATH__" Environment="__YNH_NODE_LOAD_PATH__"
Environment=NODE_ENV=production Environment=NODE_ENV=production
Environment=TRILIUM_ENV=dev Environment=TRILIUM_ENV=dev
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__INSTALL_DIR__/
ExecStart=__YNH_NODE__ __FINALPATH__/src/www ExecStart=__YNH_NODE__ __INSTALL_DIR__/src/www
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,3 +0,0 @@
## Configuration
You will be asked to choose a username and password when you first access the app. You can configure Trillium from the settings menu of the app interface.

View file

@ -1,3 +0,0 @@
## Configuration
On vous demandera de choisir un nom d'utilisateur et mot de passe quand vous installez l'application. Vous pouvez configurer Trillium depuis le menu de configuration de l'interface web.

3
doc/POST_INSTALL.md Normal file
View file

@ -0,0 +1,3 @@
## Configuration
You will be asked to choose a password when you first access the app. You can configure Trillium from the settings menu of the app interface.

3
doc/POST_INSTALL_fr.md Normal file
View file

@ -0,0 +1,3 @@
## Configuration
On vous demandera de choisir un mot de passe quand vous installez l'application. Vous pouvez configurer Trillium depuis le menu de configuration de l'interface web.

View file

@ -1,56 +0,0 @@
{
"name": "Trilium Notes",
"id": "trilium",
"packaging_format": 1,
"description": {
"en": "Hierarchical note taking application with focus on building large personal knowledge base",
"fr": "Prise de note hiérarchique centrée sur la construction d'une large base de connaissances personnelle"
},
"version": "0.58.7~ynh1",
"url": "https://github.com/zadam/trilium",
"upstream": {
"license": "AGPL-3.0-only",
"admindoc": "https://github.com/zadam/trilium/wiki",
"code": "https://github.com/zadam/trilium"
},
"license": "AGPL-3.0-only",
"maintainer": {
"name": "Jules Bertholet",
"email": "jules.bertholet@gmail.com"
},
"requirements": {
"yunohost": ">= 11.0.9"
},
"multi_instance": true,
"services": [
"nginx"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "is_public",
"type": "boolean",
"default": true,
"help": {
"en": "Required for sync with desktop app",
"fr": "Nécessaire pour la synchronisation avec l'application desktop"
}
},
{
"name": "instance_name",
"type": "string",
"ask": {
"en": "Choose a unique name for this instance (optional)",
"fr": "Choisissez un nom unique pour cette instance (facultatif)"
},
"example": "MyTrillium",
"optional": true,
"default": ""
}
]
}
}

68
manifest.toml Normal file
View file

@ -0,0 +1,68 @@
packaging_format = 2
id = "trilium"
name = "Trilium Notes"
description.en = "Hierarchical note taking application with focus on building large personal knowledge base"
description.fr = "Application de prise de note hiérarchique centrée sur la construction d'une large base de connaissances personnelle"
version = "0.58.8~ynh1"
maintainers = ["Jules Bertholet"]
[upstream]
license = "AGPL-3.0-only"
admindoc = "https://github.com/zadam/trilium/wiki"
code = "https://github.com/zadam/trilium"
cpe = "cpe:2.3:a:trilium_project:trilium"
fund = "https://github.com/sponsors/zadam"
[integration]
yunohost = ">= 11.1.11.1"
architectures = [ "amd64" ]
multi_instance = true
ldap = false
sso = false
disk = "200M"
ram.build = "350M"
ram.runtime = "110M"
[install]
[install.domain]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "domain"
full_domain = true
[install.init_main_permission]
help.en = "Enabling visitors access is required for sync with desktop app"
help.fr = "Autoriser l'accès aux visiteurs est nécessaire pour la synchronisation avec l'application desktop"
type = "group"
default = "visitors"
[install.instance_name]
ask.en = "Choose a unique name for this instance (optional)"
ask.fr = "Choisissez un nom unique pour cette instance (facultatif)"
type = "string"
example = "MyTrillium"
optional = true
default = ""
[resources]
[resources.system_user]
[resources.install_dir]
[resources.data_dir]
[resources.permissions]
main.url = "/"
[resources.ports]
main.default = 8095
[resources.apt]
packages = "libpng16-16, libpng-dev, pkg-config, autoconf, libtool, build-essential, nasm, libx11-dev, libxkbfile-dev"
extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main"
extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg"
extras.yarn.packages = "yarn"

View file

@ -6,9 +6,6 @@
nodejs_version=16 nodejs_version=16
# dependencies used by the app
pkg_dependencies="libpng16-16 libpng-dev pkg-config autoconf libtool build-essential nasm libx11-dev libxkbfile-dev"
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================

33
scripts/backup Executable file → Normal file
View file

@ -10,43 +10,28 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
#================================================= #=================================================
ynh_print_info --message="Declaring files to be backed up..." ynh_print_info --message="Declaring files to be backed up..."
### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs
### to be backuped and not an actual copy of any file. The actual backup that
### creates and fill the archive with the files happens in the core after this
### script is called. Hence ynh_backups calls takes basically 0 seconds to run.
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$final_path" ynh_backup --src_path="$install_dir"
#================================================= #=================================================
# BACKUP THE DATA DIR # BACKUP THE DATA DIR
#================================================= #=================================================
ynh_backup --src_path="$datadir" --is_big # Only relevant if there is a "data_dir" resource for this app
ynh_backup --src_path="$data_dir" --is_big
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
@ -66,4 +51,4 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

181
scripts/install Executable file → Normal file
View file

@ -9,98 +9,52 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= # Install parameters are automatically saved as settings
# MANAGE SCRIPT FAILURE #
#================================================= # Settings are automatically loaded as bash variables
# in every app script context, therefore typically these will exist:
# - $domain
# - $path
# - $language
# ... etc
#
# Resources defined in the manifest are provisioned prior to this script
# and corresponding settings are also available, such as:
# - $install_dir
# - $port
# - $db_name
# ...
ynh_clean_setup () { #
ynh_clean_check_starting # $app is the app id (i.e. 'example' for first install,
} # or 'example__2', '__3', ... for multi-instance installs)
# Exit if an error occurs during the execution of the script #
ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST # INSTALL NODEJS
#================================================= #=================================================
ynh_script_progression --message="Installing nodejs..." --weight=10
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC
instance_name=$YNH_APP_ARG_INSTANCE_NAME
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
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=instance_name --value=$instance_name
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=60
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less 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 # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=5 ynh_script_progression --message="Setting up source files..." --weight=10
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" ynh_setup_source --dest_dir="$install_dir"
grep -v electron "$final_path/package.json" > "$final_path/server-package.json" grep -v electron "$install_dir/package.json" > "$install_dir/server-package.json"
mv "$final_path/server-package.json" "$final_path/package.json" mv "$install_dir/server-package.json" "$install_dir/package.json"
# $install_dir will automatically be initialized with some decent
chmod 750 "$final_path" # permission by default ... however, you may need to recursively reapply
chmod -R o-rwx "$final_path" # ownership to all files such as after the ynh_setup_source step
chown -R $app:www-data "$final_path" chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
#================================================= chown -R $app:www-data "$install_dir"
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
@ -109,84 +63,51 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Installing Node.js packages ..." --weight=45 ynh_script_progression --message="Installing Node.js packages ..." --weight=45
pushd "$final_path" pushd "$install_dir"
ynh_use_nodejs ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ./
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm rebuild ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm rebuild ./
popd popd
#================================================= #=================================================
# CREATE DATA DIRECTORY # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Creating a data directory..." ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1
datadir=/home/yunohost.app/$app # Create a dedicated NGINX config using the conf/nginx.conf template
ynh_app_setting_set --app=$app --key=datadir --value=$datadir ynh_add_nginx_config
mkdir -p $datadir # Create a dedicated systemd config
ynh_add_systemd_config
chmod 750 "$datadir" yunohost service add $app --description="Trilium Notes app" --log="systemd"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# APP INITIAL CONFIGURATION
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/config.ini" --destination="$final_path/config.ini" ### You can add specific configuration files.
ln -sf $final_path/config.ini $datadir/config.ini
chmod 400 "$final_path/config.ini" ynh_add_config --template="../conf/config.ini" --destination="$install_dir/config.ini"
chown $app:$app "$final_path/config.ini" ln -sf $install_dir/config.ini $data_dir/config.ini
#================================================= chmod 400 "$install_dir/config.ini"
# SETUP SYSTEMD chown $app:$app "$install_dir/config.ini"
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Trilium Notes app" --log="systemd"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression --message="Installation of $app completed" --last

70
scripts/remove Executable file → Normal file
View file

@ -10,86 +10,30 @@ source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Removing system configurations related to $app..."
domain=$(ynh_app_setting_get --app=$app --key=domain) # This should be a symetric version of what happens in the install script
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app yunohost service remove $app
fi fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=30
# Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DATA DIR
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..."
ynh_secure_remove --file="$datadir"
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=30
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs ynh_remove_nodejs
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression --message="Removal of $app completed" --last

103
scripts/restore Executable file → Normal file
View file

@ -10,117 +10,58 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression --message="Restoring the app main directory..." --weight=20
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$install_dir"
chmod 750 "$final_path" # $install_dir will automatically be initialized with some decent
chmod -R o-rwx "$final_path" # permission by default ... however, you may need to recursively reapply
chown -R $app:www-data "$final_path" # ownership to all files such as after the ynh_setup_source step
chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring the data directory..." ynh_script_progression --message="Restoring the data directory..." --weight=50
ynh_restore_file --origin_path="$datadir" --not_mandatory ynh_restore_file --origin_path="$data_dir" --not_mandatory
mkdir -p $datadir # (Same as for install dir)
chown -R $app:www-data "$data_dir"
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#================================================= #=================================================
# SPECIFIC RESTORATION # INSTALL NODEJS
#================================================= #=================================================
# REINSTALL DEPENDENCIES ynh_script_progression --message="Installing nodejs..." --weight=20
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=40
# Define and install dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less 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 NGINX CONFIGURATION # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_script_progression --message="Restoring system configurations related to $app..." --weight=10
# This should be a symetric version of what happens in the install script
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"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Trilium Notes app" --log="systemd" yunohost service add $app --description="Trilium Notes app" --log="systemd"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
# Typically you only have either $app or php-fpm but not both at the same time...
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port"
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
@ -128,4 +69,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -9,165 +9,118 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
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)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
port=$(ynh_app_setting_get --app=$app --key=port)
instance_name=$(ynh_app_setting_get --app=$app --key=instance_name)
#=================================================
# CHECK VERSION
#=================================================
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)..." --weight=15
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# 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 # STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
#ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
#
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# of what you may want to do in some cases (e.g. a setting was not defined on
# some legacy installs and you therefore want to initiaze stuff during upgrade)
#
# If db_name doesn't exist, create it
#if [ -z "$db_name" ]; then
# db_name=$(ynh_sanitize_dbid --db_name=$app)
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#fi
# If install_dir doesn't exist, create it
#if [ -z "$install_dir" ]; then
# install_dir=/var/www/$app
# ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
#fi
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=60 ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...)
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# If datadir doesn't exist, create it
if [ -z "$datadir" ]; then
datadir=$(ynh_app_setting_get --app=$app --key=data_path)
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
ynh_app_setting_delete --app=$app --key=data_path
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." ynh_script_progression --message="Upgrading source files..." --weight=10
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --keep="config.ini" ynh_setup_source --dest_dir="$install_dir" --keep="config.ini"
grep -v electron "$final_path/package.json" > "$final_path/server-package.json" grep -v electron "$install_dir/package.json" > "$install_dir/server-package.json"
mv "$final_path/server-package.json" "$final_path/package.json" mv "$install_dir/server-package.json" "$install_dir/package.json"
fi fi
chmod 750 "$final_path" # $install_dir will automatically be initialized with some decent
chmod -R o-rwx "$final_path" # permission by default ... however, you may need to recursively reapply
chown -R $app:www-data "$final_path" # ownership to all files such as after the ynh_setup_source step
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE NODEJS
#================================================= #=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Upgrading nodejs..." --weight=5
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# INSTALL NODE PACKAGES # INSTALL NODE PACKAGES
#================================================= #=================================================
ynh_script_progression --message="Installing Node.js packages ..." --weight=45 ynh_script_progression --message="Installing Node.js packages ..." --weight=45
pushd "$final_path" pushd "$install_dir"
ynh_use_nodejs ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ./
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm rebuild ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm rebuild ./
popd popd
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# This should be a literal copypasta of what happened in the install's "System configuration" section
ynh_add_nginx_config
ynh_add_systemd_config
yunohost service add $app --description="Trilium Notes app" --log="systemd"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...)
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/config.ini" --destination="$final_path/config.ini" ynh_add_config --template="../conf/config.ini" --destination="$install_dir/config.ini"
ln -sf $final_path/config.ini $datadir/config.ini ln -sf $install_dir/config.ini $data_dir/config.ini
chmod 400 "$final_path/config.ini" chmod 400 "$install_dir/config.ini"
chown $app:$app "$final_path/config.ini" chown $app:$app "$install_dir/config.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Trilium Notes app" --log="systemd"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last

9
tests.toml Normal file
View file

@ -0,0 +1,9 @@
test_format = 1.0
[default]
# -------------------------------
# Commits to test upgrade from
# -------------------------------
test_upgrade_from.85a53b5.name = "Merge pull request #36 from YunoHost-Apps/testing"