From eddf934549745fd04aff3a5e0384aa11fdf1d749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 15 Jan 2024 22:17:38 +0100 Subject: [PATCH 01/10] manifest v2 --- .github/workflows/updater.sh | 118 -------- .github/workflows/updater.yml | 49 ---- check_process | 24 -- conf/app.src | 7 - conf/cron | 2 +- conf/env_files.env.sample | 2 +- conf/f2b_filter.conf | 2 +- conf/systemd_api-gateway.service | 4 +- conf/systemd_auth-worker.service | 4 +- conf/systemd_auth.service | 4 +- conf/systemd_files.service | 4 +- conf/systemd_syncing-server-worker.service | 4 +- conf/systemd_syncing-server.service | 4 +- conf/systemd_workspace.service | 4 +- doc/DISCLAIMER.md | 3 - doc/DISCLAIMER_fr.md | 3 - doc/PRE_INSTALL.md | 1 + doc/PRE_INSTALL_fr.md | 1 + manifest.json | 45 --- manifest.toml | 72 +++++ scripts/_common.sh | 36 ++- scripts/backup | 56 +--- scripts/change_url | 82 +++--- scripts/install | 298 +++++-------------- scripts/remove | 154 ++-------- scripts/restore | 317 +++++++-------------- scripts/upgrade | 184 ++++++------ tests.toml | 9 + 28 files changed, 471 insertions(+), 1022 deletions(-) delete mode 100644 .github/workflows/updater.sh delete mode 100644 .github/workflows/updater.yml delete mode 100644 check_process delete mode 100644 conf/app.src delete mode 100644 doc/DISCLAIMER.md delete mode 100644 doc/DISCLAIMER_fr.md create mode 100644 doc/PRE_INSTALL.md create mode 100644 doc/PRE_INSTALL_fr.md delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh deleted file mode 100644 index 7b3fcbc..0000000 --- a/.github/workflows/updater.sh +++ /dev/null @@ -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 < 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 diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml deleted file mode 100644 index a137af4..0000000 --- a/.github/workflows/updater.yml +++ /dev/null @@ -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 ' - author: 'yunohost-bot ' - 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 diff --git a/check_process b/check_process deleted file mode 100644 index fef06e5..0000000 --- a/check_process +++ /dev/null @@ -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 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 22c0a45..0000000 --- a/conf/app.src +++ /dev/null @@ -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 diff --git a/conf/cron b/conf/cron index 8ad4979..63ef707 100644 --- a/conf/cron +++ b/conf/cron @@ -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 diff --git a/conf/env_files.env.sample b/conf/env_files.env.sample index 3d64490..33edd31 100644 --- a/conf/env_files.env.sample +++ b/conf/env_files.env.sample @@ -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/ diff --git a/conf/f2b_filter.conf b/conf/f2b_filter.conf index 6bbbd0b..4215e9d 100644 --- a/conf/f2b_filter.conf +++ b/conf/f2b_filter.conf @@ -1,6 +1,6 @@ [INCLUDES] before = common.conf [Definition] -failregex = .* .POST __PATH_URL__.*auth/sign_in HTTP/.... 401 +failregex = .* .POST __PATH__.*auth/sign_in HTTP/.... 401 ignoreregex = datepattern = %%d/%%b/%%Y:%%H:%%M:%%S diff --git a/conf/systemd_api-gateway.service b/conf/systemd_api-gateway.service index 3e91482..ab66293 100644 --- a/conf/systemd_api-gateway.service +++ b/conf/systemd_api-gateway.service @@ -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 diff --git a/conf/systemd_auth-worker.service b/conf/systemd_auth-worker.service index 7b93ec7..1196c37 100644 --- a/conf/systemd_auth-worker.service +++ b/conf/systemd_auth-worker.service @@ -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 diff --git a/conf/systemd_auth.service b/conf/systemd_auth.service index fc25c47..e06682f 100644 --- a/conf/systemd_auth.service +++ b/conf/systemd_auth.service @@ -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 diff --git a/conf/systemd_files.service b/conf/systemd_files.service index d93ef79..4a50f5a 100644 --- a/conf/systemd_files.service +++ b/conf/systemd_files.service @@ -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 diff --git a/conf/systemd_syncing-server-worker.service b/conf/systemd_syncing-server-worker.service index 706f016..6e30ddb 100644 --- a/conf/systemd_syncing-server-worker.service +++ b/conf/systemd_syncing-server-worker.service @@ -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 diff --git a/conf/systemd_syncing-server.service b/conf/systemd_syncing-server.service index cffd348..d814708 100644 --- a/conf/systemd_syncing-server.service +++ b/conf/systemd_syncing-server.service @@ -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 diff --git a/conf/systemd_workspace.service b/conf/systemd_workspace.service index 31615fb..c9cdea5 100644 --- a/conf/systemd_workspace.service +++ b/conf/systemd_workspace.service @@ -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 diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index c824f93..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -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 diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md deleted file mode 100644 index bcf0338..0000000 --- a/doc/DISCLAIMER_fr.md +++ /dev/null @@ -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 diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md new file mode 100644 index 0000000..ea8626b --- /dev/null +++ b/doc/PRE_INSTALL.md @@ -0,0 +1 @@ +* 4GB swap memory will be created during install diff --git a/doc/PRE_INSTALL_fr.md b/doc/PRE_INSTALL_fr.md new file mode 100644 index 0000000..fe735b1 --- /dev/null +++ b/doc/PRE_INSTALL_fr.md @@ -0,0 +1 @@ +* 4 Go de mémoire swap seront créés pendant l'installation diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 0daa393..0000000 --- a/manifest.json +++ /dev/null @@ -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": "/" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..5b781b3 --- /dev/null +++ b/manifest.toml @@ -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" diff --git a/scripts/_common.sh b/scripts/_common.sh index bdeaa61..5937f60 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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" } #================================================= diff --git a/scripts/backup b/scripts/backup index 68c35e5..74d9476 100755 --- a/scripts/backup +++ b/scripts/backup @@ -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 #================================================= diff --git a/scripts/change_url b/scripts/change_url index 02da51b..2317ddf 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -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 diff --git a/scripts/install b/scripts/install index ce9c71a..39b745b 100755 --- a/scripts/install +++ b/scripts/install @@ -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 diff --git a/scripts/remove b/scripts/remove index 6e438c1..b7dbbc5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -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 #================================================= diff --git a/scripts/restore b/scripts/restore index 9bd7758..0b19d33 100755 --- a/scripts/restore +++ b/scripts/restore @@ -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 diff --git a/scripts/upgrade b/scripts/upgrade index e231128..81cdd22 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -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 diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..5c224fa --- /dev/null +++ b/tests.toml @@ -0,0 +1,9 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ + + test_upgrade_from.62b95a36.name = "2022.09.16~ynh1" From 501611917e95a7c806e8bd9c91e939f22cebbe59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 15 Jan 2024 22:37:42 +0100 Subject: [PATCH 02/10] fix manifestv2 --- manifest.toml | 8 + scripts/_common.sh | 7 + scripts/actions/add_subscription.sh | 54 ++-- scripts/change_url | 103 +------ scripts/config | 107 +++---- scripts/install | 16 +- scripts/restore | 13 +- scripts/upgrade | 455 ++++++++-------------------- sources/extra_files/cron.sh | 42 +-- 9 files changed, 242 insertions(+), 563 deletions(-) diff --git a/manifest.toml b/manifest.toml index 5b781b3..a7fb4c4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -36,6 +36,10 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen type = "path" default = "/" + [install.init_main_permission] + type = "group" + default = "visitors" + [resources] [resources.sources.main] url = "https://github.com/standardnotes/server/archive/5ea91aeafc6c986391e6f4acc5cad20584a90828.tar.gz" @@ -63,6 +67,10 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen workspace.default = 3006 [resources.apt] + packages = [ + "mariadb-server", + ] + [resources.apt.extras.yarn] repo = "deb https://dl.yarnpkg.com/debian/ stable main" key = "https://dl.yarnpkg.com/debian/pubkey.gpg" diff --git a/scripts/_common.sh b/scripts/_common.sh index 5937f60..c7a774e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,6 +9,13 @@ nodejs_version=16.13.1 swap_needed=4096 node_max_old_space_size=6144 +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" #================================================= # PERSONAL HELPERS diff --git a/scripts/actions/add_subscription.sh b/scripts/actions/add_subscription.sh index 8d6e876..7b69f65 100755 --- a/scripts/actions/add_subscription.sh +++ b/scripts/actions/add_subscription.sh @@ -2,24 +2,18 @@ source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) - #================================================= # LOAD ENV FILE #================================================= -if [ ! -f .env ] -then - export $(cat $final_path/cron.env | grep -v -E "^#" | xargs) +if [ ! -f .env ]; then + set -a + source "$install_dir/cron.env" + set +a fi FILE_UPLOAD_BYTES_PER_MB=1048576 -FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB)) +FILE_UPLOAD_BYTES_LIMIT="$((FILES_SIZE * FILE_UPLOAD_BYTES_PER_MB))" #================================================= # ADD SUBSCRIPTION AND FILES SPACE TO ALL USERS @@ -28,28 +22,26 @@ FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB)) ynh_script_progression --message="Add a subscription and $FILES_SIZE MB of file space to all users without a subscription" # Searching for new users in the last 10 minutes without a Pro_Plan subscription. -mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \ - SELECT email FROM users WHERE NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ -" 2>/dev/null | - -# Read through the piped result until it's empty. +mysql --password="$db_pwd" --database="$db_name" <<< " \ + SELECT email FROM users WHERE NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ +" 2>/dev/null | \ while IFS='\n' read email; do - if [[ ${email} = "email" ]]; then - ynh_print_info --message="New users found:" - ynh_print_info --message="----------------------------------------" - else - # ADD new user with Email $EMAIL a PRO_PLAN subscription - ynh_print_info --message="[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" + if [[ ${email} = "email" ]]; then + ynh_print_info --message="New users found:" + ynh_print_info --message="----------------------------------------" + else + # ADD new user with Email $EMAIL a PRO_PLAN subscription + ynh_print_info --message="[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." + mysql --password="$db_pwd" --database="$db_name" -e \ + "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" + mysql --password="$db_pwd" --database="$db_name" -e \ + "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" - # Add new user Files space. Size is 1GB*$FILES_SIZE - ynh_print_info --message="[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" - fi + # Add new user Files space. Size is 1GB*$FILES_SIZE + ynh_print_info --message="[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." + mysql --password="$db_pwd" --database="$db_name" -e \ + "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" + fi done ynh_script_progression --message="Execution completed" --last diff --git a/scripts/change_url b/scripts/change_url index 2317ddf..25c928e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,70 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN -#REMOVEME? old_path=$YNH_APP_OLD_PATH - -#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN -#REMOVEME? new_path=$YNH_APP_NEW_PATH - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#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 -#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="$install_dir/live/api-gateway.env" - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -#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 -#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. -#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -#REMOVEME? change_domain=0 -#REMOVEME? if [ "$old_domain" != "$new_domain" ] -then - #REMOVEME? change_domain=1 -fi - -#REMOVEME? change_path=0 -#REMOVEME? if [ "$old_path" != "$new_path" ] -then - #REMOVEME? change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -83,30 +19,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- 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 -#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper -#REMOVEME? domain="$old_domain" -#REMOVEME? path="$new_path" - # Create a dedicated 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 -#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 -#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - #================================================= # SPECIFIC MODIFICATIONS #================================================= @@ -121,23 +33,10 @@ ynh_store_file_checksum --file="$config_api_gateway" # SETUP FAIL2BAN #================================================= ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 -#REMOVEME? -domain=$new_domain -path=$new_path + # Create a dedicated Fail2Ban config -touch "/var/log/$app/$app.log" ynh_add_fail2ban_config --use_template -#================================================= -# GENERIC FINALISATION -#================================================= -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/config b/scripts/config index 7a46ca9..7bffcce 100644 --- a/scripts/config +++ b/scripts/config @@ -10,38 +10,27 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$(ynh_app_setting_get $app id) -final_path=$(ynh_app_setting_get $app final_path) - #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= get__disable_user_registration(){ - - disabled=$(ynh_read_var_in_file --file="$final_path/live/auth.env" --key="DISABLE_USER_REGISTRATION") - - echo $disabled + disabled=$(ynh_read_var_in_file --file="$install_dir/live/auth.env" --key="DISABLE_USER_REGISTRATION") + echo "$disabled" } get__files_limit(){ - limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE") - - echo $limit + limit=$(ynh_read_var_in_file --file="$install_dir/cron.env" --key="FILES_SIZE") + echo "$limit" } get__info(){ - domain="$(cat /etc/yunohost/current_host)" - limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE") - link="https://$domain/yunohost/admin/#/apps/$app/actions" - cat << EOF + domain="$(cat /etc/yunohost/current_host)" + limit=$(ynh_read_var_in_file --file="$install_dir/cron.env" --key="FILES_SIZE") + link="https://$domain/yunohost/admin/#/apps/$app/actions" + cat << EOF ask: "Add subscriptions:\nAdd a subscription and $limit MB of file space to all users without a subscription.\n$link" EOF - } #================================================= @@ -53,56 +42,56 @@ EOF #================================================= set__disable_user_registration(){ - #--------------------------------------------- - # IMPORTANT: setter are trigger only if a change is detected - #--------------------------------------------- - if [ $disable_user_registration = "1" ]; then - disabled="true" - fi - if [ $disable_user_registration = "0" ]; then - disabled="false" - fi + #--------------------------------------------- + # IMPORTANT: setter are trigger only if a change is detected + #--------------------------------------------- + if [ "$disable_user_registration" = "1" ]; then + disabled="true" + fi + if [ "$disable_user_registration" = "0" ]; then + disabled="false" + fi - config_auth="$final_path/live/auth.env" - config_auth_worker="$final_path/live/auth-worker.env" - - ynh_write_var_in_file --file="$config_auth" --key="DISABLE_USER_REGISTRATION" --value="$disabled" - ynh_write_var_in_file --file="$config_auth_worker" --key="DISABLE_USER_REGISTRATION" --value="$disabled" + config_auth="$install_dir/live/auth.env" + config_auth_worker="$install_dir/live/auth-worker.env" - ynh_store_file_checksum --file="$config_auth" - ynh_store_file_checksum --file="$config_auth_worker" + ynh_write_var_in_file --file="$config_auth" --key="DISABLE_USER_REGISTRATION" --value="$disabled" + ynh_write_var_in_file --file="$config_auth_worker" --key="DISABLE_USER_REGISTRATION" --value="$disabled" - ynh_systemd_action \ - --service_name="$app-auth" \ - --action="restart" \ - --log_path="/var/log/$app/auth.log" \ - --line_match='^.*Server started on port.*$|^.*Starting worker.*$' - ynh_systemd_action \ - --service_name="$app-auth-worker" \ - --action="restart" \ - --log_path="/var/log/$app/auth-worker.log" \ - --line_match='^.*Server started on port.*$|^.*Starting worker.*$' + ynh_store_file_checksum --file="$config_auth" + ynh_store_file_checksum --file="$config_auth_worker" - #--------------------------------------------- - # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too - #--------------------------------------------- - ynh_app_setting_set --app="$app" --key="disable_user_registration" --value="$disabled" + ynh_systemd_action \ + --service_name="$app-auth" \ + --action="restart" \ + --log_path="/var/log/$app/auth.log" \ + --line_match='^.*Server started on port.*$|^.*Starting worker.*$' + ynh_systemd_action \ + --service_name="$app-auth-worker" \ + --action="restart" \ + --log_path="/var/log/$app/auth-worker.log" \ + --line_match='^.*Server started on port.*$|^.*Starting worker.*$' + + #--------------------------------------------- + # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too + #--------------------------------------------- + ynh_app_setting_set --app="$app" --key="disable_user_registration" --value="$disabled" } set__files_limit(){ - #--------------------------------------------- - # IMPORTANT: setter are trigger only if a change is detected - #--------------------------------------------- - config_cron="$final_path/cron.env" + #--------------------------------------------- + # IMPORTANT: setter are trigger only if a change is detected + #--------------------------------------------- + config_cron="$install_dir/cron.env" - ynh_write_var_in_file --file="$config_cron" --key="FILES_SIZE" --value="$files_limit" + ynh_write_var_in_file --file="$config_cron" --key="FILES_SIZE" --value="$files_limit" - ynh_store_file_checksum --file="$config_cron" + ynh_store_file_checksum --file="$config_cron" - #--------------------------------------------- - # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too - #--------------------------------------------- - ynh_app_setting_set --app="$app" --key="files_size" --value="$files_limit" + #--------------------------------------------- + # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too + #--------------------------------------------- + ynh_app_setting_set --app="$app" --key="files_size" --value="$files_limit" } #================================================= diff --git a/scripts/install b/scripts/install index 39b745b..3eb4fc2 100755 --- a/scripts/install +++ b/scripts/install @@ -49,14 +49,6 @@ chown -R "$app:$app" "$data_dir" #================================================= ynh_script_progression --message="Adding configuration files..." --weight=2 -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) auth_jwt_secret=$(ynh_string_random --length=48 | base64) @@ -108,6 +100,7 @@ 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" + 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" @@ -125,14 +118,13 @@ 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" +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --use_template + ynh_add_config --template="cron" --destination="/etc/cron.d/$app" chmod 640 "/etc/cron.d/$app" chown root: "/etc/cron.d/$app" -# 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 diff --git a/scripts/restore b/scripts/restore index 0b19d33..c072415 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,15 +14,6 @@ source /usr/share/yunohost/helpers redis_db=$(ynh_redis_get_free_db) ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" -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" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -129,10 +120,10 @@ ynh_replace_string --match_string="^AUTH_SERVER_URL.*$" --replace_string="AUTH_S ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_auth_worker" --target_file="$config_auth_worker" # API-Gateway Port ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_api_gateway" --target_file="$config_api_gateway" -ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="$config_nginx" +ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" # Files Port ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_files" --target_file="$config_files" -ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="$config_nginx" +ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf" # Workspace Port 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" diff --git a/scripts/upgrade b/scripts/upgrade index 81cdd22..0e3c87d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,314 +10,142 @@ source _common.sh source ynh_add_swap source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#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) - -#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) - -#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) - -#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) - -#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="$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" - -#REMOVEME? nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping systemd services..." --weight=1 ynh_systemd_action \ - --service_name="$app-api-gateway" \ - --action="stop" \ - --log_path="/var/log/$app/api-gateway.log" + --service_name="$app-api-gateway" \ + --action="stop" \ + --log_path="/var/log/$app/api-gateway.log" ynh_systemd_action \ - --service_name="$app-auth" \ - --action="stop" \ - --log_path="/var/log/$app/auth.log" + --service_name="$app-auth" \ + --action="stop" \ + --log_path="/var/log/$app/auth.log" ynh_systemd_action \ - --service_name="$app-auth-worker" \ - --action="stop" \ - --log_path="/var/log/$app/auth-worker.log" + --service_name="$app-auth-worker" \ + --action="stop" \ + --log_path="/var/log/$app/auth-worker.log" ynh_systemd_action \ - --service_name="$app-files" \ - --action="stop" \ - --log_path="/var/log/$app/files.log" + --service_name="$app-files" \ + --action="stop" \ + --log_path="/var/log/$app/files.log" ynh_systemd_action \ - --service_name="$app-syncing-server" \ - --action="stop" \ - --log_path="/var/log/$app/syncing-server.log" + --service_name="$app-syncing-server" \ + --action="stop" \ + --log_path="/var/log/$app/syncing-server.log" ynh_systemd_action \ - --service_name="$app-syncing-server-worker" \ - --action="stop" \ - --log_path="/var/log/$app/syncing-server-worker.log" + --service_name="$app-syncing-server-worker" \ + --action="stop" \ + --log_path="/var/log/$app/syncing-server-worker.log" ynh_systemd_action \ - --service_name="$app-workspace" \ - --action="stop" \ - --log_path="/var/log/$app/workspace.log" + --service_name="$app-workspace" \ + --action="stop" \ + --log_path="/var/log/$app/workspace.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# 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 -if [ -z "$redis_db" ]; then - redis_db=$(ynh_redis_get_free_db) - ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" -fi - - -# If one port_* doesn't exist, create all new -if [[ -z "$port_api_gateway" || \ - -z "$port_auth" || \ - -z "$port_auth_worker" || \ - -z "$port_files" || \ - -z "$port_syncing_server" || \ - -z "$port_syncing_server_worker" || \ - -z "$port_workspace" ]]; then -#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 if [ -z "$jwt_secret" ]; then - jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret + jwt_secret=$(ynh_string_random --length=48 | base64) + ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret fi # If legacy_jwt_secret doesn't exist, create it if [ -z "$legacy_jwt_secret" ]; then - legacy_jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret + legacy_jwt_secret=$(ynh_string_random --length=48 | base64) + ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret fi # If auth_jwt_secret doesn't exist, create it if [ -z "$auth_jwt_secret" ]; then - auth_jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret + auth_jwt_secret=$(ynh_string_random --length=48 | base64) + ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret fi # If pseudo_key_params_key doesn't exist, create it if [ -z "$pseudo_key_params_key" ]; then - pseudo_key_params_key=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key + pseudo_key_params_key=$(ynh_string_random --length=48 | base64) + ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key fi # If encryption_server_key doesn't exist, create it if [ -z "$encryption_server_key" ]; then - encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required - ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key + encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required + ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key fi # If valet_token_secret doesn't exist, create it if [ -z "$valet_token_secret" ]; then - valet_token_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret + valet_token_secret=$(ynh_string_random --length=48 | base64) + ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret fi # If disable_user_registration doesn't exist, create it if [ -z "$disable_user_registration" ]; then - disable_user_registration=false - ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration + disable_user_registration=false + ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration fi # If files_zise doesn't exist, create it if [ -z "$files_size" ]; then - files_size=100 - ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size + files_size=100 + ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size fi -# Remove old Settings, Services, Files, Dependencies -# 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 +if [ -n "${api_gateway_version_installed+x}" ]; then + ynh_app_setting_delete --app=$app --key=api_gateway_version_installed fi -if [ -n ${auth_version_installed+x} ]; then - ynh_app_setting_delete --app=$app --key=auth_version_installe +if [ -n "${auth_version_installed+x}" ]; then + ynh_app_setting_delete --app=$app --key=auth_version_installe fi -if [ -n ${syncing_server_version_installed+x} ]; then - ynh_app_setting_delete --app=$app --key=syncing_server_version_installed +if [ -n "${syncing_server_version_installed+x}" ]; then + ynh_app_setting_delete --app=$app --key=syncing_server_version_installed fi -if [ -n ${install_dir_www+x} ]; then - ynh_app_setting_delete --app=$app --key=install_dir_www +if [ -n "${install_dir_www+x}" ]; then + ynh_app_setting_delete --app=$app --key=install_dir_www fi # 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 -#REMOVEME? if ynh_permission_exists --permission="help" -then - ynh_permission_delete --permission="help" +if [ -n "${install_dir_extensions+x}" ]; then + ynh_app_setting_delete --app=$app --key=install_dir_extensions fi # If old service exsits; remove it -if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null -then - ynh_script_progression --message="Removing old service..." --weight=1 - yunohost service remove "$app-syncing-server-js" - ynh_remove_systemd_config --service="$app-syncing-server-js" - ynh_reset_systemd +if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null; then + ynh_script_progression --message="Removing old service..." --weight=1 + yunohost service remove "$app-syncing-server-js" + ynh_remove_systemd_config --service="$app-syncing-server-js" + ynh_reset_systemd fi -if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null -then - ynh_script_progression --message="Removing old service..." --weight=1 - yunohost service remove "$app-syncing-server-js-worker" - ynh_remove_systemd_config --service="$app-syncing-server-js-worker" - ynh_reset_systemd -fi - -# Remove unneeded data -if [ -e "/var/www/$app" ]; then - ynh_secure_remove --file="/var/www/$app" -fi - -# If data_dir doesn't exist, create it -# CREATE DATA DIRECTORY -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 $data_dir/uploads - - chmod -R 750 "$data_dir" - chmod -R o-rwx "$data_dir" - chown -R $app:$app "$data_dir" +if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null; then + ynh_script_progression --message="Removing old service..." --weight=1 + yunohost service remove "$app-syncing-server-js-worker" + ynh_remove_systemd_config --service="$app-syncing-server-js-worker" + ynh_reset_systemd fi #================================================= -# CREATE DEDICATED USER +# UPGRADE NODEJS #================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Upgrading NodeJS..." --weight=1 -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" +ynh_install_nodejs --nodejs_version="$nodejs_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1 +cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh" - # Download, check integrity, uncompress and patch the source from app.src -#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 "$install_dir" - chmod -R o-rwx "$install_dir" - chown -R $app:$app "$install_dir" -fi +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= -# UPGRADE DEPENDENCIES +# ADD A CONFIGURATION #================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$nodejs_version -#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 -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# ADD SWAP -#================================================= -ynh_script_progression --message="Adding swap..." - -if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then - ynh_add_swap --size=$swap_needed -fi - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=2 +ynh_script_progression --message="Adding configuration files..." --weight=2 ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway" ynh_add_config --template="env_auth.env.sample" --destination="$config_auth" @@ -327,23 +155,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 #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93 - ynh_use_nodejs - 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 -fi +ynh_script_progression --message="Building Standard Notes - Syncing Server..." --weight=93 + +ynh_use_nodejs +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 +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 +ynh_script_progression --message="Upgrading 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" @@ -354,15 +185,13 @@ ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_synci 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" -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --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" @@ -373,86 +202,58 @@ 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 +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --use_template -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_add_config --template="cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 640 "/etc/cron.d/$app" + +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 A CRON -#================================================= -ynh_script_progression --message="Setup a cron..." - -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" -chmod 640 "/etc/cron.d/$app" - -#================================================= -# UPGRADE FAIL2BAN -#================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1 - -# Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --use_template - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? 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 diff --git a/sources/extra_files/cron.sh b/sources/extra_files/cron.sh index 747da57..cf6f8ed 100755 --- a/sources/extra_files/cron.sh +++ b/sources/extra_files/cron.sh @@ -2,7 +2,7 @@ if [ ! -f .env ] then - export $(cat cron.env | grep -v -E "^#" | xargs) + export $(cat cron.env | grep -v -E "^#" | xargs) fi FILE_UPLOAD_BYTES_PER_MB=1048576 @@ -10,28 +10,28 @@ FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB)) # Searching for new users in the last 10 minutes without a Pro_Plan subscription. mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \ - SELECT email FROM users WHERE created_at >= DATE_SUB( TIMESTAMP(NOW()), INTERVAL 10 MINUTE) AND NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ -" 2>/dev/null | + SELECT email FROM users WHERE created_at >= DATE_SUB( TIMESTAMP(NOW()), INTERVAL 10 MINUTE) AND NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ +" 2>/dev/null | # Read through the piped result until it's empty. while IFS='\n' read email; do - if [[ $email = "0" ]]; then - echo "No new users registered" - fi - if [[ ${email} = "email" ]]; then - echo "New users found:" - echo "----------------------------------------" - else - # ADD new user with Email $EMAIL a PRO_PLAN subscription - echo "[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" + if [[ $email = "0" ]]; then + echo "No new users registered" + fi + if [[ ${email} = "email" ]]; then + echo "New users found:" + echo "----------------------------------------" + else + # ADD new user with Email $EMAIL a PRO_PLAN subscription + echo "[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." + mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ + "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" + mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ + "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" - # Add new user Files space. Size is 1GB*$FILES_SIZE - echo "[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." - mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ - "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" - fi + # Add new user Files space. Size is 1GB*$FILES_SIZE + echo "[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." + mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ + "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" + fi done From c0cc162d1f374aa6011e2a80b5b9574c441244d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 15 Jan 2024 23:21:30 +0100 Subject: [PATCH 03/10] Fix nginx http_host -> host --- conf/nginx.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index da233ec..066f3f3 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ location __PATH__/ { proxy_pass http://127.0.0.1:__PORT_API_GATEWAY__/; proxy_http_version 1.1; - proxy_set_header Host $http_host; + proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-Proto $scheme; @@ -17,7 +17,7 @@ location = __PATH__/ { location __PATH__/files/ { proxy_pass http://127.0.0.1:__PORT_FILES__/; proxy_http_version 1.1; - proxy_set_header Host $http_host; + proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-Proto $scheme; From a7ec7c8befbb26c64689062fb2100b03e300a53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 15 Jan 2024 23:24:14 +0100 Subject: [PATCH 04/10] fix upgrade --- config_panel.toml | 36 ++++++++++++++++---------------- scripts/upgrade | 53 ++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/config_panel.toml b/config_panel.toml index d79e4c4..88e2fe5 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -3,25 +3,25 @@ version = "1.0" [main] name = "StandardNotes Server configuration" - [main.new_user] - name = "New User Options" + [main.new_user] + name = "New User Options" - [main.new_user.disable_user_registration] - ask = "Disable user registration?" - type = "boolean" - default = "false" - help = "false = New users can register\ntrue = No new user registrations allowed" + [main.new_user.disable_user_registration] + ask = "Disable user registration?" + type = "boolean" + default = "false" + help = "false = New users can register\ntrue = No new user registrations allowed" - [main.new_user.files_limit] - ask = "Default files limit" - type = "number" - default = "100" - help = "Choose a default limit in MB for the user file upload space.\n 100 = 100 MB\n 1024 = 1GB\n 10240 = 10GB" + [main.new_user.files_limit] + ask = "Default files limit" + type = "number" + default = "100" + help = "Choose a default limit in MB for the user file upload space.\n 100 = 100 MB\n 1024 = 1GB\n 10240 = 10GB" - [main.subscription] - name = "User Subscription" + [main.subscription] + name = "User Subscription" - [main.subscription.info] - ask = "" - type = "alert" - style = "info" + [main.subscription.info] + ask = "" + type = "alert" + style = "info" diff --git a/scripts/upgrade b/scripts/upgrade index 0e3c87d..c7f4dec 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -51,62 +51,55 @@ ynh_systemd_action \ #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# If jwt_secret doesn't exist, create it -if [ -z "$jwt_secret" ]; then +# Create non existing settings +if [ -z "${jwt_secret:-}" ]; then jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret + ynh_app_setting_set --app="$app" --key=jwt_secret --value="$jwt_secret" fi -# If legacy_jwt_secret doesn't exist, create it -if [ -z "$legacy_jwt_secret" ]; then +if [ -z "${legacy_jwt_secret:-}" ]; then legacy_jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret + ynh_app_setting_set --app="$app" --key=legacy_jwt_secret --value="$legacy_jwt_secret" fi -# If auth_jwt_secret doesn't exist, create it -if [ -z "$auth_jwt_secret" ]; then +if [ -z "${auth_jwt_secret:-}" ]; then auth_jwt_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret + ynh_app_setting_set --app="$app" --key=auth_jwt_secret --value="$auth_jwt_secret" fi -# If pseudo_key_params_key doesn't exist, create it -if [ -z "$pseudo_key_params_key" ]; then +if [ -z "${pseudo_key_params_key:-}" ]; then pseudo_key_params_key=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key + ynh_app_setting_set --app="$app" --key=pseudo_key_params_key --value="$pseudo_key_params_key" fi -# If encryption_server_key doesn't exist, create it -if [ -z "$encryption_server_key" ]; then +if [ -z "${encryption_server_key:-}" ]; then encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required - ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key + ynh_app_setting_set --app="$app" --key=encryption_server_key --value="$encryption_server_key" fi -# If valet_token_secret doesn't exist, create it -if [ -z "$valet_token_secret" ]; then +if [ -z "${valet_token_secret:-}" ]; then valet_token_secret=$(ynh_string_random --length=48 | base64) - ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret + ynh_app_setting_set --app="$app" --key=valet_token_secret --value="$valet_token_secret" fi -# If disable_user_registration doesn't exist, create it -if [ -z "$disable_user_registration" ]; then +if [ -z "${disable_user_registration:-}" ]; then disable_user_registration=false - ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration + ynh_app_setting_set --app="$app" --key=DISABLE_USER_REGISTRATION --value="$disable_user_registration" fi -# If files_zise doesn't exist, create it -if [ -z "$files_size" ]; then +if [ -z "${files_size:-}" ]; then files_size=100 - ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size + ynh_app_setting_set --app="$app" --key=FILES_SIZE --value="$files_size" fi +# Delete legacy settings if [ -n "${api_gateway_version_installed+x}" ]; then - ynh_app_setting_delete --app=$app --key=api_gateway_version_installed + ynh_app_setting_delete --app="$app" --key=api_gateway_version_installed fi if [ -n "${auth_version_installed+x}" ]; then - ynh_app_setting_delete --app=$app --key=auth_version_installe + ynh_app_setting_delete --app="$app" --key=auth_version_installe fi if [ -n "${syncing_server_version_installed+x}" ]; then - ynh_app_setting_delete --app=$app --key=syncing_server_version_installed + ynh_app_setting_delete --app="$app" --key=syncing_server_version_installed fi if [ -n "${install_dir_www+x}" ]; then - ynh_app_setting_delete --app=$app --key=install_dir_www + ynh_app_setting_delete --app="$app" --key=install_dir_www fi -# If install_dir_extensions exist, delete it if [ -n "${install_dir_extensions+x}" ]; then - ynh_app_setting_delete --app=$app --key=install_dir_extensions + ynh_app_setting_delete --app="$app" --key=install_dir_extensions fi # If old service exsits; remove it From 6c5a20d8bdda52820cde7c4f25781d78cc50554d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:47:53 +0100 Subject: [PATCH 05/10] fix linter --- manifest.toml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/manifest.toml b/manifest.toml index a7fb4c4..eeafb18 100644 --- a/manifest.toml +++ b/manifest.toml @@ -22,11 +22,14 @@ code = "https://github.com/standardnotes/server" 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, ... + +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.domain] From 3072c0e002c25a31e4d88543c4c57bee79409069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 18 Jan 2024 11:44:46 +0100 Subject: [PATCH 06/10] Try without root level return 200 in nginx --- conf/nginx.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 066f3f3..3a1a0d0 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -9,10 +9,10 @@ location __PATH__/ { proxy_buffering off; } -location = __PATH__/ { - default_type text/plain; - return 200 "This is where Standard Notes - Syncing Server is installed."; -} +# location = __PATH__/ { +# default_type text/plain; +# return 200 "This is where Standard Notes - Syncing Server is installed."; +# } location __PATH__/files/ { proxy_pass http://127.0.0.1:__PORT_FILES__/; From cf063d14d8ec0fe584cbdb115a05196445591663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 6 Feb 2024 22:00:36 +0100 Subject: [PATCH 07/10] add toml schema --- tests.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests.toml b/tests.toml index 5c224fa..a27cd68 100644 --- a/tests.toml +++ b/tests.toml @@ -1,3 +1,5 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + test_format = 1.0 [default] From 221ec0105c02aabe37d7e7afdae10953aeb5a113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 2 May 2024 08:46:43 +0200 Subject: [PATCH 08/10] Update nginx.conf --- conf/nginx.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 3a1a0d0..066f3f3 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -9,10 +9,10 @@ location __PATH__/ { proxy_buffering off; } -# location = __PATH__/ { -# default_type text/plain; -# return 200 "This is where Standard Notes - Syncing Server is installed."; -# } +location = __PATH__/ { + default_type text/plain; + return 200 "This is where Standard Notes - Syncing Server is installed."; +} location __PATH__/files/ { proxy_pass http://127.0.0.1:__PORT_FILES__/; From 04f20d6a2614b8887b9af62119f859d2347d89c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 20 May 2024 19:23:25 +0200 Subject: [PATCH 09/10] Update description in manifest --- manifest.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index eeafb18..a94c1ca 100644 --- a/manifest.toml +++ b/manifest.toml @@ -4,7 +4,8 @@ packaging_format = 2 id = "snserver" name = "Standard Notes Server" -description.en = "The Standard Notes syncing server. An end-to-end encrypted note-taking app." +description.en = "End-to-end encrypted note-taking app syncing server" +description.fr = "Serveur de synchronisation de prise de notes cryptées de bout en bout" version = "2023.01.26~ynh2" From 53e4e50cd8756229dc1726231b0c72819a5432f1 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Mon, 20 May 2024 18:53:24 +0000 Subject: [PATCH 10/10] Auto-update READMEs --- README.md | 12 +++--------- README_es.md | 12 +++--------- README_eu.md | 12 +++--------- README_fr.md | 12 +++--------- README_gl.md | 12 +++--------- README_zh_Hans.md | 12 +++--------- 6 files changed, 18 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 18a89a9..f2b6301 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,9 @@ It shall NOT be edited by hand. Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and life’s work all in one secure place. -**Shipped version:** 2023.01.26~ynh1 +**Shipped version:** 2023.01.26~ynh2 **Demo:** -## Disclaimers / important information - -* 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 - ## :red_circle: Antifeatures - **Non-free assets**: Contains and makes use of non-free assets. The most common case is apps using artwork - images, sounds, music, etc. - under a commercial license. @@ -35,9 +29,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and pr ## Documentation and resources -- Official app website: +- Official app website: - Official user documentation: -- Official admin documentation: +- Official admin documentation: - Upstream app code repository: - YunoHost Store: - Report a bug: diff --git a/README_es.md b/README_es.md index 0c73f92..3cc60cd 100644 --- a/README_es.md +++ b/README_es.md @@ -19,15 +19,9 @@ No se debe editar a mano. Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and life’s work all in one secure place. -**Versión actual:** 2023.01.26~ynh1 +**Versión actual:** 2023.01.26~ynh2 **Demo:** -## informaciones importantes - -* 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 - ## :red_circle: funcionalidades no deseadas - **Non-free assets**: Contains and makes use of non-free assets. The most common case is apps using artwork - images, sounds, music, etc. - under a commercial license. @@ -35,9 +29,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and pr ## Documentaciones y recursos -- Sitio web oficial: +- Sitio web oficial: - Documentación usuario oficial: -- Documentación administrador oficial: +- Documentación administrador oficial: - Repositorio del código fuente oficial de la aplicación : - Catálogo YunoHost: - Reportar un error: diff --git a/README_eu.md b/README_eu.md index 0994aa9..01962bf 100644 --- a/README_eu.md +++ b/README_eu.md @@ -19,15 +19,9 @@ EZ editatu eskuz. Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and life’s work all in one secure place. -**Paketatutako bertsioa:** 2023.01.26~ynh1 +**Paketatutako bertsioa:** 2023.01.26~ynh2 **Demoa:** -## Ezespena / informazio garrantzitsua - -* 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 - ## :red_circle: Ezaugarri zalantzagarriak - **Libreak ez diren baliabideak**: Libreak ez diren baliabideak ditu eta erabiltzen ditu. Kasurik ohikoena artelanak (irudiak, soinuak, musika, etab.) erabiltzen dituzten aplikazioak dira. - jabedun-lizentziapean. @@ -35,9 +29,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and pr ## Dokumentazioa eta baliabideak -- Aplikazioaren webgune ofiziala: +- Aplikazioaren webgune ofiziala: - Erabiltzaileen dokumentazio ofiziala: -- Administratzaileen dokumentazio ofiziala: +- Administratzaileen dokumentazio ofiziala: - Jatorrizko aplikazioaren kode-gordailua: - YunoHost Denda: - Eman errore baten berri: diff --git a/README_fr.md b/README_fr.md index 8aa3bb4..be46167 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,15 +19,9 @@ Il NE doit PAS être modifié à la main. Standard Notes est une application de prise de notes chiffrée de bout en bout pour les numériciens et les professionnels. Capturez vos notes, vos fichiers et le travail de votre vie en un seul endroit sécurisé. -**Version incluse :** 2023.01.26~ynh1 +**Version incluse :** 2023.01.26~ynh2 **Démo :** -## Avertissements / informations importantes - -* 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 - ## :red_circle: Anti-fonctionnalités - **Ressources non libres **: Contient ou utilise des médias non libres. Le cas le plus fréquent concerne des applications utilisant des œuvres (images, sons, musiques, etc.) sous une licence commerciale. @@ -35,9 +29,9 @@ Standard Notes est une application de prise de notes chiffrée de bout en bout p ## Documentations et ressources -- Site officiel de l’app : +- Site officiel de l’app : - Documentation officielle utilisateur : -- Documentation officielle de l’admin : +- Documentation officielle de l’admin : - Dépôt de code officiel de l’app : - YunoHost Store : - Signaler un bug : diff --git a/README_gl.md b/README_gl.md index 8745685..cf3feb5 100644 --- a/README_gl.md +++ b/README_gl.md @@ -19,15 +19,9 @@ NON debe editarse manualmente. Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and life’s work all in one secure place. -**Versión proporcionada:** 2023.01.26~ynh1 +**Versión proporcionada:** 2023.01.26~ynh2 **Demo:** -## Avisos / información importante - -* 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 - ## :red_circle: Debes considerar - **Non-free assets**: Contains and makes use of non-free assets. The most common case is apps using artwork - images, sounds, music, etc. - under a commercial license. @@ -35,9 +29,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and pr ## Documentación e recursos -- Web oficial da app: +- Web oficial da app: - Documentación oficial para usuarias: -- Documentación oficial para admin: +- Documentación oficial para admin: - Repositorio de orixe do código: - Tenda YunoHost: - Informar dun problema: diff --git a/README_zh_Hans.md b/README_zh_Hans.md index b5717e3..da2dcbf 100644 --- a/README_zh_Hans.md +++ b/README_zh_Hans.md @@ -19,15 +19,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and life’s work all in one secure place. -**分发版本:** 2023.01.26~ynh1 +**分发版本:** 2023.01.26~ynh2 **演示:** -## 免责声明 / 重要信息 - -* 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 - ## :red_circle: 负面特征 - **Non-free assets**: Contains and makes use of non-free assets. The most common case is apps using artwork - images, sounds, music, etc. - under a commercial license. @@ -35,9 +29,9 @@ Standard Notes is an end-to-end encrypted note-taking app for digitalists and pr ## 文档与资源 -- 官方应用网站: +- 官方应用网站: - 官方用户文档: -- 官方管理文档: +- 官方管理文档: - 上游应用代码库: - YunoHost 商店: - 报告 bug: