1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snserver_ynh.git synced 2024-09-03 20:26:22 +02:00

manifest v2

This commit is contained in:
Salamandar 2024-01-15 22:17:38 +01:00
parent 40d2cf5fed
commit eddf934549
28 changed files with 471 additions and 1022 deletions

View file

@ -1,118 +0,0 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
commit=""
id=0
while [[ -z $commit && $id -le 29 ]]
do
commit=$(curl --silent "https://api.github.com/repos/$repo/commits" | jq -r ".[$id] | .sha" )
tags=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/standardnotes/server.git | grep $commit)
if [[ -z $tags || $tags == *"alpha"* ]]; then
commit=""
fi
let id++
done
if [ -z $commit ]; then
echo "::warning ::No new version found.."
exit 0
fi
version=$(curl --silent "https://api.github.com/repos/$repo/commits/$commit" | jq -r '.commit.committer.date' | sed 's/T.*$//g' | sed 's/-/./g')
api_gateway_online_version=$(curl --silent "https://raw.githubusercontent.com/$repo/$commit/packages/api-gateway/package.json" | jq -j '.version')
auth_online_version=$(curl --silent "https://raw.githubusercontent.com/$repo/$commit/packages/auth/package.json" | jq -j '.version')
files_online_version=$(curl --silent "https://raw.githubusercontent.com/$repo/$commit/packages/files/package.json" | jq -j '.version')
ss_online_version=$(curl --silent "https://raw.githubusercontent.com/$repo/$commit/packages/syncing-server/package.json" | jq -j '.version')
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $version"
echo "API-Gateway: $api_gateway_online_version"
echo "Auth: $auth_online_version"
echo "Files: $files_online_version"
echo "Syncing-Server: $ss_online_version"
echo "VERSION=$version" >> $GITHUB_ENV
echo "VERSION_CURRENT=$current_version" >> $GITHUB_ENV
echo "VERSION_API=$api_gateway_online_version" >> $GITHUB_ENV
echo "VERSION_AUTH=$auth_online_version" >> $GITHUB_ENV
echo "VERSION_FILES=$files_online_version" >> $GITHUB_ENV
echo "VERSION_SS=$ss_online_version" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV
# Proceed only if the retrieved version is greater than the current one
if [[ "$current_version" == "$version" ]]; then
echo "::warning ::No new version available"
exit 0
# Proceed only if a PR for this new version does not already exist
elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
echo "::warning ::A branch already exists for this update"
exit 0
fi
asset="https://github.com/$repo/archive/$commit.tar.gz"
#=================================================
# UPDATE SOURCE FILES
#=================================================
# Create the temporary directory
tempdir="$(mktemp -d)"
# Download sources and calculate checksum
filename=${asset##*/}
curl --silent -4 -L $asset -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Rewrite source file
cat <<EOT > conf/app.src
SOURCE_URL=$asset
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true
EOT
echo "... conf/app.src updated"
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# Any action on the app's source code can be done.
# The GitHub Action workflow takes care of committing all changes after this script ends.
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
# No need to update the README, yunohost-bot takes care of it
# The Action will proceed only if the PROCEED environment variable is set to true
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

View file

@ -1,49 +0,0 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every monday at 6:00 UTC
schedule:
- cron: '0 6 * * 1'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to $VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Update: to latest versions'
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
branch: ci-auto-update-${{ env.VERSION }}
base: testing
delete-branch: true
title: 'Upgrade to ${{ env.VERSION }}'
body: |
Upgrade ${{ env.VERSION_CURRENT }} to ${{ env.VERSION }}
draft: false

View file

@ -1,24 +0,0 @@
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=0
setup_public=1
upgrade=1
# 2022.09.16~yhn1
upgrade=1 from_commit=62b95a36cb6b8bc991cc4cd4fccc1b0365d13b11
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notificationnone
;;; Upgrade options
; commit=62b95a36cb6b8bc991cc4cd4fccc1b0365d13b11
name=2022.09.16~ynh1

View file

@ -1,7 +0,0 @@
SOURCE_URL=https://github.com/standardnotes/server/archive/5ea91aeafc6c986391e6f4acc5cad20584a90828.tar.gz
SOURCE_SUM=87d98db93233f88da30e5b89fa9df02bc0d2ee2ddadc9087a42b90987ec3c581
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -1 +1 @@
*/5 * * * * __APP__ __FINALPATH__/cron.sh > /var/log/__APP__/cron.log 2>&1
*/5 * * * * __APP__ __INSTALL_DIR__/cron.sh > /var/log/__APP__/cron.log 2>&1

View file

@ -34,4 +34,4 @@ SQS_QUEUE_URL=
SQS_AWS_REGION=
# (Optional) File upload path (relative to root directory)
FILE_UPLOAD_PATH=__DATADIR__/uploads/
FILE_UPLOAD_PATH=__DATA_DIR__/uploads/

View file

@ -1,6 +1,6 @@
[INCLUDES]
before = common.conf
[Definition]
failregex = <HOST> .* .POST __PATH_URL__.*auth/sign_in HTTP/.... 401
failregex = <HOST> .* .POST __PATH__.*auth/sign_in HTTP/.... 401
ignoreregex =
datepattern = %%d/%%b/%%Y:%%H:%%M:%%S

View file

@ -8,8 +8,8 @@ After=__APP__-auth.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live/
EnvironmentFile=__FINALPATH__/live/api-gateway.env
WorkingDirectory=__INSTALL_DIR__/live/
EnvironmentFile=__INSTALL_DIR__/live/api-gateway.env
ExecStart=/usr/bin/yarn start:api-gateway
StandardOutput=append:/var/log/__APP__/api-gateway.log
StandardError=inherit

View file

@ -9,8 +9,8 @@ After=__APP__-auth.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/live/auth-worker.env
WorkingDirectory=__INSTALL_DIR__/live
EnvironmentFile=__INSTALL_DIR__/live/auth-worker.env
ExecStart=/usr/bin/yarn start:auth-worker
StandardOutput=append:/var/log/__APP__/auth-worker.log
StandardError=inherit

View file

@ -9,8 +9,8 @@ After=__APP__-syncing-server-js.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/live/auth.env
WorkingDirectory=__INSTALL_DIR__/live
EnvironmentFile=__INSTALL_DIR__/live/auth.env
ExecStart=/usr/bin/yarn start:auth
StandardOutput=append:/var/log/__APP__/auth.log
StandardError=inherit

View file

@ -9,8 +9,8 @@ After=__APP__-syncing-server.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/live/files.env
WorkingDirectory=__INSTALL_DIR__/live
EnvironmentFile=__INSTALL_DIR__/live/files.env
ExecStart=/usr/bin/yarn start:files
StandardOutput=append:/var/log/__APP__/files.log
StandardError=inherit

View file

@ -9,8 +9,8 @@ After=__APP__-syncing-server.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/live/syncing-server-worker.env
WorkingDirectory=__INSTALL_DIR__/live
EnvironmentFile=__INSTALL_DIR__/live/syncing-server-worker.env
ExecStart=/usr/bin/yarn start:syncing-server-worker
StandardOutput=append:/var/log/__APP__/syncing-server-worker.log
StandardError=inherit

View file

@ -8,8 +8,8 @@ After=redis.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/live/syncing-server.env
WorkingDirectory=__INSTALL_DIR__/live
EnvironmentFile=__INSTALL_DIR__/live/syncing-server.env
ExecStart=/usr/bin/yarn start:syncing-server
StandardOutput=append:/var/log/__APP__/syncing-server.log
StandardError=inherit

View file

@ -7,8 +7,8 @@ After=__APP__-auth.service
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/live/
EnvironmentFile=__FINALPATH__/live/workspace.env
WorkingDirectory=__INSTALL_DIR__/live/
EnvironmentFile=__INSTALL_DIR__/live/workspace.env
ExecStart=/usr/bin/yarn start:workspace
StandardOutput=append:/var/log/__APP__/workspace.log
StandardError=inherit

View file

@ -1,3 +0,0 @@
* No single-sign on or LDAP integration
* Ram requirements ( 4GB swap memory will be created during install ):
* Configuration can be changed under: https://my_domain.tld/yunohost/admin/#/apps/$app_id/config-panel

View file

@ -1,3 +0,0 @@
* Pas d'authentification unique ou d'intégration LDAP.
* Besoins en mémoire vive (4 Go de mémoire swap seront créés pendant l'installation) :
* La configuration peut être modifiée sous : https://my_domain.tld/yunohost/admin/#/apps/$app_id/config-panel

1
doc/PRE_INSTALL.md Normal file
View file

@ -0,0 +1 @@
* 4GB swap memory will be created during install

1
doc/PRE_INSTALL_fr.md Normal file
View file

@ -0,0 +1 @@
* 4 Go de mémoire swap seront créés pendant l'installation

View file

@ -1,45 +0,0 @@
{
"name": "Standard Notes Server",
"id": "snserver",
"packaging_format": 1,
"description": {
"en": "The Standard Notes syncing server. An end-to-end encrypted note-taking app."
},
"version": "2023.01.26~ynh1",
"url": "https://github.com/standardnotes/standalone",
"upstream": {
"license": "AGPL-3.0-or-later",
"website": "https://standardnotes.org/",
"demo": "https://standardnotes.org/demo",
"admindoc": "https://docs.standardnotes.org/",
"userdoc": "https://standardnotes.com/help",
"code": "https://github.com/standardnotes/server"
},
"license": "AGPL-3.0-or-later",
"maintainer": {
"name": "Fabian Wilkens",
"email": "46000361+FabianWilkens@users.noreply.github.com"
},
"requirements": {
"yunohost": ">= 11.2.12"
},
"multi_instance": true,
"services": [
"nginx",
"mysql"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/example",
"default": "/"
}
]
}
}

72
manifest.toml Normal file
View file

@ -0,0 +1,72 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "snserver"
name = "Standard Notes Server"
description.en = "The Standard Notes syncing server. An end-to-end encrypted note-taking app."
version = "2023.01.26~ynh2"
maintainers = ["Fabian Wilkens"]
[upstream]
license = "AGPL-3.0-or-later"
website = "https://standardnotes.org"
demo = "https://standardnotes.org/demo"
admindoc = "https://docs.standardnotes.org"
userdoc = "https://standardnotes.com/help"
code = "https://github.com/standardnotes/server"
[integration]
yunohost = ">= 11.2.12"
architectures = "all"
multi_instance = true
ldap = false
sso = false
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.domain]
type = "domain"
[install.path]
type = "path"
default = "/"
[resources]
[resources.sources.main]
url = "https://github.com/standardnotes/server/archive/5ea91aeafc6c986391e6f4acc5cad20584a90828.tar.gz"
sha256 = "87d98db93233f88da30e5b89fa9df02bc0d2ee2ddadc9087a42b90987ec3c581"
autoupdate.strategy = "latest_github_release"
autoupdate.asset = "tarball"
[resources.system_user]
[resources.install_dir]
[resources.data_dir]
subdirs = ["uploads"]
[resources.permissions]
main.url = "/"
[resources.ports]
api_gateway.default = 3000
auth.default = 3001
auth_worker.default = 3002
files.default = 3003
syncing_server.default = 3004
syncing_server_worker.default = 3005
workspace.default = 3006
[resources.apt]
[resources.apt.extras.yarn]
repo = "deb https://dl.yarnpkg.com/debian/ stable main"
key = "https://dl.yarnpkg.com/debian/pubkey.gpg"
packages = "yarn"
[resources.database]
type = "mysql"

View file

@ -9,8 +9,6 @@ nodejs_version=16.13.1
swap_needed=4096
node_max_old_space_size=6144
# dependencies used by the app (must be on a single line)
pkg_dependencies=""
#=================================================
# PERSONAL HELPERS
@ -18,7 +16,7 @@ pkg_dependencies=""
# Reset failed systemd services.
ynh_reset_systemd(){
systemctl reset-failed
systemctl reset-failed
}
# Substitute/replace a string (or expression) by another in a file on a line
@ -33,24 +31,24 @@ ynh_reset_systemd(){
# sub-expressions can be used (see sed manual page for more information)
#
ynh_replace_string_on_line() {
# Declare an array to define the options of this helper.
local legacy_args=lmrf
local -A args_array=([l]=line= [m]=match_string= [r]=replace_string= [f]=target_file=)
local line
local match_string
local replace_string
local target_file
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
set +o xtrace # set +x
# Declare an array to define the options of this helper.
local legacy_args=lmrf
local -A args_array=([l]=line= [m]=match_string= [r]=replace_string= [f]=target_file=)
local line
local match_string
local replace_string
local target_file
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
set +o xtrace # set +x
local delimit=@
# Escape the delimiter if it's in the string.
match_string=${match_string//${delimit}/"\\${delimit}"}
replace_string=${replace_string//${delimit}/"\\${delimit}"}
local delimit=@
# Escape the delimiter if it's in the string.
match_string=${match_string//${delimit}/"\\${delimit}"}
replace_string=${replace_string//${delimit}/"\\${delimit}"}
set -o xtrace # set -x
sed --in-place "${line} s${delimit}${match_string}${delimit}${replace_string}${delimit}" "$target_file"
set -o xtrace # set -x
sed --in-place "${line} s${delimit}${match_string}${delimit}${replace_string}${delimit}" "$target_file"
}
#=================================================

View file

@ -10,28 +10,6 @@
source ../settings/scripts/_common.sh
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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -41,39 +19,20 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="$data_dir" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
# SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app-api-gateway.service"
ynh_backup --src_path="/etc/systemd/system/$app-auth.service"
ynh_backup --src_path="/etc/systemd/system/$app-auth-worker.service"
@ -82,12 +41,15 @@ ynh_backup --src_path="/etc/systemd/system/$app-syncing-server.service"
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server-worker.service"
ynh_backup --src_path="/etc/systemd/system/$app-workspace.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/var/log/$app/"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================

View file

@ -13,64 +13,64 @@ source /usr/share/yunohost/helpers
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
#REMOVEME? old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#REMOVEME? # Needed for helper "ynh_add_nginx_config"
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
# Add settings here as needed by your application
port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
port_files=$(ynh_app_setting_get --app=$app --key=port_files)
port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
#REMOVEME? port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
#REMOVEME? port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
#REMOVEME? port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
#REMOVEME? port_files=$(ynh_app_setting_get --app=$app --key=port_files)
#REMOVEME? port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
#REMOVEME? port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
#REMOVEME? port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
config_api_gateway="$final_path/live/api-gateway.env"
config_api_gateway="$install_dir/live/api-gateway.env"
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
#REMOVEME? change_domain=0
#REMOVEME? if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
#REMOVEME? change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
#REMOVEME? change_path=0
#REMOVEME? if [ "$old_path" != "$new_path" ]
then
change_path=1
#REMOVEME? change_path=1
fi
#=================================================
@ -81,28 +81,30 @@ fi
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_change_url_nginx_config
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
#REMOVEME? domain="$old_domain"
#REMOVEME? path="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
#REMOVEME? ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
@ -119,9 +121,9 @@ ynh_store_file_checksum --file="$config_api_gateway"
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
#REMOVEME?
domain=$new_domain
path_url=$new_path
path=$new_path
# Create a dedicated Fail2Ban config
touch "/var/log/$app/$app.log"
ynh_add_fail2ban_config --use_template
@ -132,9 +134,9 @@ ynh_add_fail2ban_config --use_template
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT

View file

@ -11,159 +11,51 @@ source ynh_add_swap
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
# INITIALIZE AND STORE SETTINGS
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
app=$YNH_APP_INSTANCE_NAME
redis_db=$(ynh_redis_get_free_db)
disable_user_registration=false
files_size=100
#=================================================
# 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
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_app_setting_set --app="$app" --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
ynh_app_setting_set --app="$app" --key=FILES_SIZE --value=$files_size
#=================================================
# STORE SETTINGS FROM MANIFEST
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=3
ynh_script_progression --message="Installing NodeJS..." --weight=17
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=redis_db --value="$redis_db"
ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port_api_gateway=$(ynh_find_port --port=3000)
port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
ynh_app_setting_set --app=$app --key=port_files --value=$port_files
ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=17
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..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=2
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
ynh_install_nodejs --nodejs_version="$nodejs_version"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
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 --source_id=app --dest_dir="$final_path/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$final_path/cron.sh"
ynh_setup_source --dest_dir="$install_dir/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=3
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD SWAP
#=================================================
ynh_script_progression --message="Adding swap..."
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_add_swap --size=$swap_needed
fi
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..." --weight=1
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir/uploads
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
chmod -R o-rwx "$data_dir"
chown -R "$app:$app" "$data_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=2
ynh_script_progression --message="Adding configuration files..." --weight=2
config_api_gateway="$final_path/live/api-gateway.env"
config_auth="$final_path/live/auth.env"
config_auth_worker="$final_path/live/auth-worker.env"
config_files="$final_path/live/files.env"
config_syncing_server="$final_path/live/syncing-server.env"
config_syncing_server_worker="$final_path/live/syncing-server-worker.env"
config_workspace="$final_path/live/workspace.env"
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
jwt_secret=$(ynh_string_random --length=48 | base64)
legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
@ -187,21 +79,26 @@ ynh_add_config --template="env_syncing-server.env.sample" --destination="$config
ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker"
ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace"
ynh_add_config --template="cron.env" --destination="$install_dir/cron.env"
#=================================================
# INSTALLING Standard Notes - Syncing Server
#=================================================
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_script_progression --message="Building Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
pushd "$final_path/live"
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build
pushd "$install_dir/live"
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn install --immutable
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn build
popd
#=================================================
# SETUP SYSTEMD
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=4
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
@ -211,27 +108,13 @@ ynh_add_systemd_config --service="$app-files" --template="systemd_files.service"
ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_syncing-server.service"
ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service"
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setup a cron..."
ynh_add_config --template="../conf/cron.env" --destination="$final_path/cron.env"
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log"
@ -242,84 +125,59 @@ ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
# Create a dedicated Fail2Ban config
# FIXME:
ynh_add_fail2ban_config --use_template
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
ynh_add_swap --size="$swap_needed"
fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting systemd services..." --weight=1
# Start a systemd service
ynh_systemd_action \
--service_name="$app-api-gateway" \
--action="start" \
--log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-api-gateway" \
--action="start" \
--log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth" \
--action="start" \
--log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-auth" \
--action="start" \
--log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth-worker" \
--action="start" \
--log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-auth-worker" \
--action="start" \
--log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-files" \
--action="start" \
--log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-files" \
--action="start" \
--log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server" \
--action="start" \
--log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-syncing-server" \
--action="start" \
--log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server-worker" \
--action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
--service_name="$app-syncing-server-worker" \
--action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-workspace" \
--action="start" \
--log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --use_template
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=3
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors" --show_tile="false"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
--service_name="$app-workspace" \
--action="start" \
--log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
#=================================================
# END OF SCRIPT

View file

@ -11,73 +11,40 @@ source ynh_add_swap
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)
port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
port_files=$(ynh_app_setting_get --app=$app --key=port_files)
port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
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 SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# 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-api-gateway" >/dev/null
then
ynh_script_progression --message="Removing $app-api-gateway service..." --weight=1
yunohost service remove "$app-api-gateway"
if ynh_exec_warn_less yunohost service status "$app-api-gateway" >/dev/null; then
ynh_script_progression --message="Removing $app-api-gateway service..." --weight=1
yunohost service remove "$app-api-gateway"
fi
if ynh_exec_warn_less yunohost service status "$app-auth" >/dev/null
then
ynh_script_progression --message="Removing $app-auth service..." --weight=1
yunohost service remove "$app-auth"
if ynh_exec_warn_less yunohost service status "$app-auth" >/dev/null; then
ynh_script_progression --message="Removing $app-auth service..." --weight=1
yunohost service remove "$app-auth"
fi
if ynh_exec_warn_less yunohost service status "$app-auth-worker" >/dev/null
then
ynh_script_progression --message="Removing $app-auth-worker service..." --weight=1
yunohost service remove "$app-auth-worker"
if ynh_exec_warn_less yunohost service status "$app-auth-worker" >/dev/null; then
ynh_script_progression --message="Removing $app-auth-worker service..." --weight=1
yunohost service remove "$app-auth-worker"
fi
if ynh_exec_warn_less yunohost service status "$app-files" >/dev/null
then
ynh_script_progression --message="Removing $app-files service..." --weight=1
yunohost service remove "$app-files"
if ynh_exec_warn_less yunohost service status "$app-files" >/dev/null; then
ynh_script_progression --message="Removing $app-files service..." --weight=1
yunohost service remove "$app-files"
fi
if ynh_exec_warn_less yunohost service status "$app-syncing-server" >/dev/null
then
ynh_script_progression --message="Removing $app-syncing-server service..." --weight=1
yunohost service remove "$app-syncing-server"
if ynh_exec_warn_less yunohost service status "$app-syncing-server" >/dev/null; then
ynh_script_progression --message="Removing $app-syncing-server service..." --weight=1
yunohost service remove "$app-syncing-server"
fi
if ynh_exec_warn_less yunohost service status "$app-syncing-server-worker" >/dev/null
then
ynh_script_progression --message="Removing $app-syncing-server-worker service..." --weight=1
yunohost service remove "$app-syncing-server-worker"
if ynh_exec_warn_less yunohost service status "$app-syncing-server-worker" >/dev/null; then
ynh_script_progression --message="Removing $app-syncing-server-worker service..." --weight=1
yunohost service remove "$app-syncing-server-worker"
fi
if ynh_exec_warn_less yunohost service status "$app-workspace" >/dev/null
then
ynh_script_progression --message="Removing $app-workspace service..." --weight=1
yunohost service remove "$app-workspace"
if ynh_exec_warn_less yunohost service status "$app-workspace" >/dev/null; then
ynh_script_progression --message="Removing $app-workspace service..." --weight=1
yunohost service remove "$app-workspace"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config --service="$app-api-gateway"
ynh_remove_systemd_config --service="$app-auth"
@ -89,73 +56,24 @@ ynh_remove_systemd_config --service="$app-workspace"
ynh_reset_systemd
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE REDIS DB
#=================================================
ynh_script_progression --message="Removing the Redis database..." --weight=1
ynh_redis_remove_db
#=================================================
# 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..." --weight=1
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
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1
# Remove the dedicated Fail2Ban config
ynh_remove_fail2ban_config
#=================================================
# REMOVE NODEJS
#=================================================
ynh_script_progression --message="Removing NodeJS..." --weight=10
ynh_remove_nodejs
#=================================================
# SPECIFIC REMOVE
#=================================================
@ -175,19 +93,9 @@ ynh_secure_remove --file="/var/log/$app"
ynh_script_progression --message="Removing swap..."
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_del_swap
ynh_del_swap
fi
#=================================================
# 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
#=================================================

View file

@ -11,142 +11,94 @@ source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_add_swap
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_script_progression --message="Loading installation settings..." --weight=2
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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
config_api_gateway="$final_path/live/api-gateway.env"
config_auth="$final_path/live/auth.env"
config_auth_worker="$final_path/live/auth-worker.env"
config_files="$final_path/live/files.env"
config_syncing_server="$final_path/live/syncing-server.env"
config_syncing_server_worker="$final_path/live/syncing-server-worker.env"
config_workspace="$final_path/live/workspace.env"
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
config_nginx="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=2
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port_api_gateway=$(ynh_find_port --port=3000)
port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
ynh_app_setting_set --app=$app --key=port_files --value=$port_files
ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
#=================================================
# 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
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
ynh_restore_file --origin_path="$install_dir"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chown -R "$app:$app" "$install_dir"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$datadir" --not_mandatory
ynh_restore_file --origin_path="$data_dir" --not_mandatory
mkdir -p "$datadir/uploads"
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=17
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
chown -R "$app:$app" "$data_dir"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
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 SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app-api-gateway.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-auth.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-auth-worker.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-files.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-syncing-server.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-syncing-server-worker.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-workspace.service"
systemctl enable "$app-api-gateway.service" --quiet
systemctl enable "$app-auth.service" --quiet
systemctl enable "$app-auth-worker.service" --quiet
systemctl enable "$app-files.service" --quiet
systemctl enable "$app-syncing-server.service" --quiet
systemctl enable "$app-syncing-server-worker.service" --quiet
systemctl enable "$app-workspace.service" --quiet
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/var/log/$app/"
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
ynh_add_swap --size="$swap_needed"
fi
#=================================================
# REINSTALL NODEJS
#=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --weight=17
ynh_install_nodejs --nodejs_version="$nodejs_version"
#=================================================
# MODIFY CONFIG
@ -185,113 +137,48 @@ ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_
ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_workspace" --target_file="$config_workspace"
ynh_replace_string --match_string="^WORKSPACE_SERVER_URL.*$" --replace_string="WORKSPACE_SERVER_URL=http://localhost:$port_workspace" --target_file="$config_api_gateway"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# ADD SWAP
#=================================================
ynh_script_progression --message="Adding swap..."
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_add_swap --size=$swap_needed
fi
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app-api-gateway.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-auth.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-auth-worker.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-files.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-syncing-server.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-syncing-server-worker.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-workspace.service"
systemctl enable $app-api-gateway.service --quiet
systemctl enable $app-auth.service --quiet
systemctl enable $app-auth-worker.service --quiet
systemctl enable $app-files.service --quiet
systemctl enable $app-syncing-server.service --quiet
systemctl enable $app-syncing-server-worker.service --quiet
systemctl enable $app-workspace.service --quiet
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
mkdir -p "/var/log/$app"
chown -R $app: "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action \
--service_name="$app-api-gateway" \
--action="start" \
--log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth" \
--action="start" \
--log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth-worker" \
--action="start" \
--log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-files" \
--action="start" \
--log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server" \
--action="start" \
--log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server-worker" \
--action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-workspace" \
--action="start" \
--log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_script_progression --message="Reloading NGINX web server and $app's services..." --weight=1
ynh_systemd_action \
--service_name="$app-api-gateway" \
--action="start" \
--log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth" \
--action="start" \
--log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-auth-worker" \
--action="start" \
--log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-files" \
--action="start" \
--log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server" \
--action="start" \
--log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-syncing-server-worker" \
--action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \
--service_name="$app-workspace" \
--action="start" \
--log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -13,47 +13,47 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
#REMOVEME? 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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
port_files=$(ynh_app_setting_get --app=$app --key=port_files)
port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
#REMOVEME? port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
#REMOVEME? port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
#REMOVEME? port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
#REMOVEME? port_files=$(ynh_app_setting_get --app=$app --key=port_files)
#REMOVEME? port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
#REMOVEME? port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
#REMOVEME? port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
jwt_secret=$(ynh_app_setting_get --app=$app --key=jwt_secret)
legacy_jwt_secret=$(ynh_app_setting_get --app=$app --key=legacy_jwt_secret)
auth_jwt_secret=$(ynh_app_setting_get --app=$app --key=auth_jwt_secret)
pseudo_key_params_key=$(ynh_app_setting_get --app=$app --key=pseudo_key_params_key)
encryption_server_key=$(ynh_app_setting_get --app=$app --key=encryption_server_key)
valet_token_secret=$(ynh_app_setting_get --app=$app --key=valet_token_secret)
#REMOVEME? jwt_secret=$(ynh_app_setting_get --app=$app --key=jwt_secret)
#REMOVEME? legacy_jwt_secret=$(ynh_app_setting_get --app=$app --key=legacy_jwt_secret)
#REMOVEME? auth_jwt_secret=$(ynh_app_setting_get --app=$app --key=auth_jwt_secret)
#REMOVEME? pseudo_key_params_key=$(ynh_app_setting_get --app=$app --key=pseudo_key_params_key)
#REMOVEME? encryption_server_key=$(ynh_app_setting_get --app=$app --key=encryption_server_key)
#REMOVEME? valet_token_secret=$(ynh_app_setting_get --app=$app --key=valet_token_secret)
disable_user_registration=$(ynh_app_setting_get --app=$app --key=DISABLE_USER_REGISTRATION)
files_size=$(ynh_app_setting_get --app=$app --key=FILES_SIZE)
#REMOVEME? disable_user_registration=$(ynh_app_setting_get --app=$app --key=DISABLE_USER_REGISTRATION)
#REMOVEME? files_size=$(ynh_app_setting_get --app=$app --key=FILES_SIZE)
config_api_gateway="$final_path/live/api-gateway.env"
config_auth="$final_path/live/auth.env"
config_auth_worker="$final_path/live/auth-worker.env"
config_files="$final_path/live/files.env"
config_syncing_server="$final_path/live/syncing-server.env"
config_syncing_server_worker="$final_path/live/syncing-server-worker.env"
config_workspace="$final_path/live/workspace.env"
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
#REMOVEME? nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
#=================================================
# CHECK VERSION
@ -65,16 +65,16 @@ 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=1
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
@ -117,10 +117,10 @@ ynh_systemd_action \
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/opt/yunohost/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/opt/yunohost/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
fi
# If redis_db doesn't exist, create it
@ -138,20 +138,20 @@ if [[ -z "$port_api_gateway" || \
-z "$port_syncing_server" || \
-z "$port_syncing_server_worker" || \
-z "$port_workspace" ]]; then
port_api_gateway=$(ynh_find_port --port=3000)
port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
ynh_app_setting_set --app=$app --key=port_files --value=$port_files
ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
#REMOVEME? port_api_gateway=$(ynh_find_port --port=3000)
#REMOVEME? port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
#REMOVEME? port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
#REMOVEME? port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
#REMOVEME? port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
#REMOVEME? port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
#REMOVEME? port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
#REMOVEME? ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_files --value=$port_files
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
fi
# If jwt_secret doesn't exist, create it
@ -196,12 +196,12 @@ if [ -z "$files_size" ]; then
fi
# Remove old Settings, Services, Files, Dependencies
# If final_path_www exist, delete it
api_gateway_version_installed=$(ynh_app_setting_get --app=$app --key=api_gateway_version)
auth_version_installed=$(ynh_app_setting_get --app=$app --key=auth_version)
syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_server_version)
final_path_www=$(ynh_app_setting_get --app=$app --key=final_path_www)
final_path_extensions=$(ynh_app_setting_get --app=$app --key=final_path_extensions)
# If install_dir_www exist, delete it
#REMOVEME? api_gateway_version_installed=$(ynh_app_setting_get --app=$app --key=api_gateway_version)
#REMOVEME? auth_version_installed=$(ynh_app_setting_get --app=$app --key=auth_version)
#REMOVEME? syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_server_version)
#REMOVEME? install_dir_www=$(ynh_app_setting_get --app=$app --key=install_dir_www)
#REMOVEME? install_dir_extensions=$(ynh_app_setting_get --app=$app --key=install_dir_extensions)
if [ -n ${api_gateway_version_installed+x} ]; then
ynh_app_setting_delete --app=$app --key=api_gateway_version_installed
fi
@ -211,16 +211,16 @@ fi
if [ -n ${syncing_server_version_installed+x} ]; then
ynh_app_setting_delete --app=$app --key=syncing_server_version_installed
fi
if [ -n ${final_path_www+x} ]; then
ynh_app_setting_delete --app=$app --key=final_path_www
if [ -n ${install_dir_www+x} ]; then
ynh_app_setting_delete --app=$app --key=install_dir_www
fi
# If final_path_extensions exist, delete it
if [ -n ${final_path_extensions+x} ]; then
ynh_app_setting_delete --app=$app --key=final_path_extensions
# If install_dir_extensions exist, delete it
if [ -n ${install_dir_extensions+x} ]; then
ynh_app_setting_delete --app=$app --key=install_dir_extensions
fi
# If permission help exists, delete it
if ynh_permission_exists --permission="help"
#REMOVEME? if ynh_permission_exists --permission="help"
then
ynh_permission_delete --permission="help"
fi
@ -246,26 +246,26 @@ if [ -e "/var/www/$app" ]; then
ynh_secure_remove --file="/var/www/$app"
fi
# If datadir doesn't exist, create it
# If data_dir doesn't exist, create it
# CREATE DATA DIRECTORY
if [ -z "$datadir" ]; then
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
if [ -z "$data_dir" ]; then
data_dir=/home/yunohost.app/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
mkdir -p $datadir/uploads
mkdir -p $data_dir/uploads
chmod -R 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
chmod -R 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:$app "$data_dir"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
#REMOVEME? 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"
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -276,24 +276,24 @@ then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_secure_remove --file="$final_path/live"
mkdir -p "$final_path/live"
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$final_path/cron.sh"
#REMOVEME? ynh_secure_remove --file="$install_dir/live"
mkdir -p "$install_dir/live"
ynh_setup_source --dest_dir="$install_dir/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
fi
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#REMOVEME? 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"
#REMOVEME? 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
@ -334,7 +334,7 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
pushd "$final_path/live"
pushd "$install_dir/live"
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build
popd
@ -433,7 +433,7 @@ ynh_systemd_action \
#=================================================
ynh_script_progression --message="Setup a cron..."
ynh_add_config --template="../conf/cron.env" --destination="$final_path/cron.env"
ynh_add_config --template="../conf/cron.env" --destination="$install_dir/cron.env"
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
@ -450,9 +450,9 @@ ynh_add_fail2ban_config --use_template
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT

9
tests.toml Normal file
View file

@ -0,0 +1,9 @@
test_format = 1.0
[default]
# ------------
# Tests to run
# ------------
test_upgrade_from.62b95a36.name = "2022.09.16~ynh1"