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

Merge pull request #84 from YunoHost-Apps/testing

Upgrade
This commit is contained in:
Fabian Wilkens 2022-09-03 09:03:39 +02:00 committed by GitHub
commit 273de1feeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 637 additions and 687 deletions

View file

@ -15,8 +15,7 @@
# 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]')
repo="standardnotes/server"
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
commit=""
id=0
while [[ -z $commit && $id -le 29 ]]
@ -31,8 +30,8 @@ do
done
if [ -z $commit ]; then
echo "::warning ::No new version found.."
exit 0
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')
@ -61,12 +60,12 @@ 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
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
echo "::warning ::A branch already exists for this update"
exit 0
fi
asset="https://github.com/$repo/archive/$commit.tar.gz"
@ -93,6 +92,8 @@ 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"
@ -104,7 +105,7 @@ echo "... conf/app.src updated"
# The GitHub Action workflow takes care of committing all changes after this script ends.
#=================================================
# GENERIC FINALIZA-TION
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest

View file

@ -8,42 +8,42 @@ on:
workflow_dispatch:
# Run it every monday at 6:00 UTC
schedule:
- cron: '0 6 * * 1'
- cron: '0 6 * * 1'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to $VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Update: to latest versions'
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
branch: ci-auto-update-${{ env.VERSION }}
base: testing
delete-branch: true
title: 'Upgrade to ${{ env.VERSION }}'
body: |
Upgrade ${{ env.VERSION_CURRENT }} to ${{ env.VERSION }}
draft: false
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
id: run_updater
run: |
# Setting up Git user
git config --global user.name 'yunohost-bot'
git config --global user.email 'yunohost-bot@users.noreply.github.com'
# Run the updater script
/bin/bash .github/workflows/updater.sh
- name: Commit changes
id: commit
if: ${{ env.PROCEED == 'true' }}
run: |
git commit -am "Upgrade to $VERSION"
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Update: to latest versions'
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
signoff: false
branch: ci-auto-update-${{ env.VERSION }}
base: testing
delete-branch: true
title: 'Upgrade to ${{ env.VERSION }}'
body: |
Upgrade ${{ env.VERSION_CURRENT }} to ${{ env.VERSION }}
draft: false

View file

@ -15,9 +15,10 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview
The Standard Notes syncing server. An end-to-end encrypted note-taking app.
Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and lifes work all in one secure place.
**Shipped version:** 2022.07.29~ynh1
**Shipped version:** 2022.08.30~ynh1
**Demo:** https://standardnotes.org/demo
@ -27,13 +28,12 @@ The Standard Notes syncing server. An end-to-end encrypted note-taking app.
* 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
## Documentation and resources
* Official app website: <https://standardnotes.org/>
* Official user documentation: <https://standardnotes.com/help>
* Official admin documentation: <https://docs.standardnotes.org/>
* Upstream app code repository: <https://github.com/standardnotes/standalone>
* Upstream app code repository: <https://github.com/standardnotes/server>
* YunoHost documentation for this app: <https://yunohost.org/app_snserver>
* Report a bug: <https://github.com/YunoHost-Apps/snserver_ynh/issues>

View file

@ -15,25 +15,25 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
## Vue d'ensemble
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 :** 2022.07.29~ynh1
**Version incluse :** 2022.08.30~ynh1
**Démo :** https://standardnotes.org/demo
## Avertissements / informations 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
* 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
## Documentations et ressources
* Site officiel de l'app : <https://standardnotes.org/>
* Documentation officielle utilisateur : <https://standardnotes.com/help>
* Documentation officielle de l'admin : <https://docs.standardnotes.org/>
* Dépôt de code officiel de l'app : <https://github.com/standardnotes/standalone>
* Dépôt de code officiel de l'app : <https://github.com/standardnotes/server>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_snserver>
* Signaler un bug : <https://github.com/YunoHost-Apps/snserver_ynh/issues>

View file

@ -1,30 +1,24 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; 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.06.20~yhn1
upgrade=1 from_commit=2a0f413937f8a3d4bd067a5890480bce1222ec5a
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
; 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.06.20~yhn1
upgrade=1 from_commit=2a0f413937f8a3d4bd067a5890480bce1222ec5a
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notification=
Notificationnone
;;; Upgrade options
; commit=2a0f413937f8a3d4bd067a5890480bce1222ec5a
name=2022.06.20~ynh1
; commit=2a0f413937f8a3d4bd067a5890480bce1222ec5a
name=2022.06.20~ynh1

View file

@ -1,5 +1,7 @@
SOURCE_URL=https://github.com/standardnotes/server/archive/033bc25d8f55e22ba168bad2d0c44fa1ac9a86e4.tar.gz
SOURCE_SUM=1f64d26630932d19985df8989f51c909912066b1dc4539b22f952f5e81f978f2
SOURCE_URL=https://github.com/standardnotes/server/archive/f6b359a77207deb66b497038e8ff2f04b287bea2.tar.gz
SOURCE_SUM=50f92435eb2c86e42ab2dc9c17b3a6d2b45278e845355e3fa148bcb003ff8763
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -1,24 +1,25 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
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 Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_pass http://127.0.0.1:__PORT_API_GATEWAY__/;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
location = __PATH__/ {
default_type text/plain;
return 200 "This is where Standard Notes - Syncing Server is installed.";
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__/;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_pass http://127.0.0.1:__PORT_FILES__/;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}

View file

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

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
Standard Notes is an end-to-end encrypted note-taking app for digitalists and professionals. Capture your notes, files, and lifes work all in one secure place.

1
doc/DESCRIPTION_fr.md Normal file
View file

@ -0,0 +1 @@
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é.

View file

@ -1,4 +1,3 @@
* 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

3
doc/DISCLAIMER_fr.md Normal file
View file

@ -0,0 +1,3 @@
* 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

View file

@ -5,7 +5,7 @@
"description": {
"en": "The Standard Notes syncing server. An end-to-end encrypted note-taking app."
},
"version": "2022.07.29~ynh1",
"version": "2022.08.30~ynh1",
"url": "https://github.com/standardnotes/standalone",
"upstream": {
"license": "AGPL-3.0-or-later",
@ -13,7 +13,7 @@
"demo": "https://standardnotes.org/demo",
"admindoc": "https://docs.standardnotes.org/",
"userdoc": "https://standardnotes.com/help",
"code": "https://github.com/standardnotes/standalone"
"code": "https://github.com/standardnotes/server"
},
"license": "AGPL-3.0-or-later",
"maintainer": {

View file

@ -3,12 +3,13 @@
#=================================================
# COMMON VARIABLES
#=================================================
NODEJS_VERSION="16"
nodejs_version=16.13.1
swap_needed=4096
node_max_old_space_size=4096
# dependencies used by the app
# dependencies used by the app (must be on a single line)
pkg_dependencies=""
#=================================================
@ -17,47 +18,45 @@ 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
#
# usage: ynh_replace_string_on_line --line=line --match_string=match_string --replace_string=replace_string --target_file=target_file
# | arg: -l, --line= - Replace match on nth line in the file
# | arg: -m, --match_string= - String to be searched and replaced in the file
# | arg: -l, --line= - Replace match on nth line in the file
# | arg: -m, --match_string= - String to be searched and replaced in the file
# | arg: -r, --replace_string= - String that will replace matches
# | arg: -f, --target_file= - File in which the string will be replaced.
# | arg: -f, --target_file= - File in which the string will be replaced.
#
# As this helper is based on sed command, regular expressions and references to
# 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"
}
#================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -29,26 +29,26 @@ ynh_script_progression --message="Add a subscription and $FILES_SIZE MB of file
# 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 ); \
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.
while IFS='\n' read email; do
if [[ ${email} = "email" ]]; then
ynh_print_info --message="New users found:"
ynh_print_info --message="----------------------------------------"
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\";"
# 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\";"
# 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\"));"
# 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
done

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
@ -15,8 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -24,7 +23,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@ -33,10 +32,14 @@ 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
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_print_info "Backing up the main app directory..."
ynh_backup --src_path="$final_path"
@ -49,21 +52,12 @@ ynh_backup --src_path="$datadir" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info "Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_print_info "Backing up fail2ban configuration..."
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
@ -73,14 +67,12 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_print_info "Backing up logrotate configuration..."
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_print_info "Backing up systemd configuration..."
ynh_backup --src_path="/etc/systemd/system/$app-api-gateway.service"
ynh_backup --src_path="/etc/systemd/system/$app-auth.service"
@ -90,14 +82,20 @@ ynh_backup --src_path="/etc/systemd/system/$app-syncing-server.service"
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server-worker.service"
#=================================================
# CRON LOGROTATE
# BACKUP VARIOUS FILES
#=================================================
ynh_print_info "Backing up cron configuration..."
ynh_backup --src_path="/etc/cron.d/$app"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -29,6 +29,7 @@ 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)
# 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)
@ -39,18 +40,18 @@ port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_s
config_api_gateway="$final_path/live/api-gateway.env"
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=33
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 () {
# 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"
# 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"
# restore it if the upgrade fails
ynh_restore_upgradebackup
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -62,13 +63,13 @@ ynh_abort_if_errors
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
change_path=1
fi
#=================================================
@ -77,30 +78,30 @@ fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --weight=2
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for nginx
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
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"
# 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
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
@ -116,11 +117,11 @@ ynh_store_file_checksum --file="$config_api_gateway"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring fail2ban..." --weight=1
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
domain=$new_domain
path_url=$new_path
# Create a dedicated fail2ban config
# Create a dedicated Fail2Ban config
touch "/var/log/$app/$app.log"
ynh_add_fail2ban_config --use_template
@ -130,7 +131,7 @@ ynh_add_fail2ban_config --use_template
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -23,22 +23,22 @@ final_path=$(ynh_app_setting_get $app final_path)
get__disable_user_registration(){
disabled=$(ynh_read_var_in_file --file="$final_path/live/auth.env" --key="DISABLE_USER_REGISTRATION")
disabled=$(ynh_read_var_in_file --file="$final_path/live/auth.env" --key="DISABLE_USER_REGISTRATION")
echo $disabled
echo $disabled
}
get__files_limit(){
limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE")
limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE")
echo $limit
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="$final_path/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 +53,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="$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"
ynh_store_file_checksum --file="$config_auth"
ynh_store_file_checksum --file="$config_auth_worker"
ynh_store_file_checksum --file="$config_auth"
ynh_store_file_checksum --file="$config_auth_worker"
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_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"
#---------------------------------------------
# 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="$final_path/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"
}
#=================================================

View file

@ -16,7 +16,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -29,11 +29,16 @@ 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
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
@ -42,19 +47,11 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=3
ynh_script_progression --message="Storing installation settings..." --weight=3
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
#=================================================
# STORE SETTINGS
#=================================================
disable_user_registration=false
files_size=100
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
@ -63,7 +60,7 @@ ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port_api_gateway=$(ynh_find_port --port=3000)
@ -83,24 +80,24 @@ ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_sy
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=17
ynh_script_progression --message="Installing dependencies..." --weight=17
ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
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
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=2
ynh_script_progression --message="Creating a MySQL database..." --weight=2
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
@ -110,10 +107,10 @@ ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
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
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"
@ -124,14 +121,22 @@ chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --weight=3
ynh_script_progression --message="Configuring NGINX web server..." --weight=3
# Create a dedicated nginx config
# 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
#=================================================
@ -142,21 +147,14 @@ ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir/uploads
chmod -R 750 "$datadir"
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
#=================================================
# ADD SWAP
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding swap..."
ynh_add_swap --size=$swap_needed
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=2
ynh_script_progression --message="Adding a configuration file..." --weight=2
config_api_gateway="$final_path/live/api-gateway.env"
config_auth="$final_path/live/auth.env"
@ -189,18 +187,18 @@ ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="
#=================================================
# INSTALLING Standard Notes - Syncing Server
#=================================================
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
pushd "$final_path/live"
ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn build
ynh_exec_warn_less ynh_exec_as $app env 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_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=4
ynh_script_progression --message="Configuring a systemd service..." --weight=4
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
@ -211,26 +209,22 @@ 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"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
# SETUP A CRON
#=================================================
ynh_script_progression --message="Storing the config file checksum..." --weight=1
ynh_script_progression --message="Setup a cron..."
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config_api_gateway"
ynh_store_file_checksum --file="$config_auth"
ynh_store_file_checksum --file="$config_auth_worker"
ynh_store_file_checksum --file="$config_files"
ynh_store_file_checksum --file="$config_syncing_server"
ynh_store_file_checksum --file="$config_syncing_server_worker"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
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
ynh_script_progression --message="Configuring log rotation..." --weight=1
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
@ -246,7 +240,7 @@ ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1
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"
@ -258,63 +252,52 @@ yunohost service add "$app-syncing-server-worker" --description="Standard Notes
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
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.*$'
#=================================================
# 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"
--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.*$'
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring fail2ban..." --weight=1
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
# Create a dedicated fail2ban config
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --use_template
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=3
ynh_script_progression --message="Configuring permissions..." --weight=3
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
@ -323,7 +306,7 @@ ynh_permission_update --permission="main" --add="visitors" --show_tile="false"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
@ -331,4 +314,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -14,12 +14,11 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
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)
@ -37,42 +36,42 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app-api-gateway" >/dev/null
then
ynh_script_progression --message="Removing $app-api-gateway service..." --weight=1
yunohost service remove "$app-api-gateway"
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"
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"
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"
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"
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"
ynh_script_progression --message="Removing $app-syncing-server-worker service..." --weight=1
yunohost service remove "$app-syncing-server-worker"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
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"
@ -84,34 +83,33 @@ ynh_remove_systemd_config --service="$app-syncing-server-worker"
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
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
#=================================================
# REMOVE REDIS DB
#=================================================
ynh_script_progression --message="Removing the Redis database..." --weight=1
ynh_redis_remove_db
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -123,57 +121,63 @@ ynh_secure_remove --file="$final_path"
# 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"
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
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated nginx config
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove the app-specific logrotate config
ynh_remove_logrotate
ynh_secure_remove --file="/var/log/$app"
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Removing fail2ban configuration..." --weight=1
ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1
# Remove the dedicated fail2ban config
# Remove the dedicated Fail2Ban config
ynh_remove_fail2ban_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE CRON CONFIGURATION
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing cron configuration..." --weight=1
ynh_script_progression --message="Removing various files..." --weight=1
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
#=================================================
# REMOVE SWAP
#=================================================
ynh_script_progression --message="Removing swap..."
ynh_del_swap
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_del_swap
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
@ -182,4 +186,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_add_swap
source ../settings/scripts/ynh_redis
@ -17,8 +17,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -26,7 +25,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..." --weight=2
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
@ -35,7 +34,6 @@ 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
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
redis_db=$(ynh_redis_get_free_db)
@ -54,14 +52,15 @@ config_nginx="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=2
test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
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
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port_api_gateway=$(ynh_find_port --port=3000)
@ -79,10 +78,12 @@ ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_s
ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
#=================================================
# RESTORE THE NGINX CONFIGURATION
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
@ -91,6 +92,10 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
@ -100,40 +105,21 @@ ynh_restore_file --origin_path="$datadir" --not_mandatory
mkdir -p "$datadir/uploads"
#=================================================
# 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 USER RIGHTS
#=================================================
# Restore permissions on app files
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
mkdir -p "/var/log/$app"
chown -R $app: "/var/log/$app"
#=================================================
# 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
#=================================================
#=================================================
# ADD SWAP
#=================================================
ynh_script_progression --message="Adding swap..."
ynh_add_swap --size=$swap_needed
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
@ -141,14 +127,22 @@ 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_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"
#=================================================
# 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
@ -185,6 +179,22 @@ ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_s
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"
#=================================================
# 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
#=================================================
@ -204,10 +214,20 @@ systemctl enable $app-files.service --quiet
systemctl enable $app-syncing-server.service --quiet
systemctl enable $app-syncing-server-worker.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="Integrate $app service in Yunohost..." --weight=1
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"
@ -222,65 +242,42 @@ yunohost service add "$app-syncing-server-worker" --description="Standard Notes
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.*$'
--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.*$'
#=================================================
# RESTORE THE CRON CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring cron configuration..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the fail2ban configuration..." --weight=1
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
--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.*$'
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=2
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -20,10 +20,8 @@ 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)
@ -59,13 +57,8 @@ nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
@ -76,8 +69,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -90,29 +83,29 @@ ynh_abort_if_errors
ynh_script_progression --message="Stopping a systemd service..." --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"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -121,77 +114,77 @@ 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
final_path=/opt/yunohost/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
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"
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" ]]; 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)))
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
-z "$port_auth" || \
-z "$port_auth_worker" || \
-z "$port_files" || \
-z "$port_syncing_server" || \
-z "$port_syncing_server_worker" ]]; 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)))
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
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
@ -202,60 +195,60 @@ syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_
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 [ -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 ${final_path_www+x} ]; then
ynh_app_setting_delete --app=$app --key=final_path_www
ynh_app_setting_delete --app=$app --key=final_path_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
ynh_app_setting_delete --app=$app --key=final_path_extensions
fi
# If permission help exists, delete it
if ynh_permission_exists --permission="help"
then
ynh_permission_delete --permission="help"
ynh_permission_delete --permission="help"
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
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
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"
ynh_secure_remove --file="/var/www/$app"
fi
# If datadir 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
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir/uploads
mkdir -p $datadir/uploads
chmod -R 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
chmod -R 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
fi
#=================================================
@ -264,63 +257,59 @@ fi
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
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
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"
# 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"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
# Remove old nodejs version
if [[ "$nodejs_version_installed" < "$NODEJS_VERSION" && -n "$nodejs_version_installed" ]]
then
ynh_remove_nodejs
fi
ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
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"
#=================================================
# SPECIFIC UPGRADE
# 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..."
ynh_add_swap --size=$swap_needed
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_add_swap --size=$swap_needed
fi
#=================================================
# MODIFY A CONFIG FILE
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Modify a config file..." --weight=2
ynh_script_progression --message="Updating a configuration file..." --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"
@ -334,12 +323,12 @@ ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
pushd "$final_path/live"
ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn build
popd
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
pushd "$final_path/live"
ynh_exec_warn_less ynh_exec_as $app env 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_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build
popd
fi
#=================================================
@ -355,24 +344,9 @@ 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"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_script_progression --message="Storing the config file checksum..." --weight=1
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config_api_gateway"
ynh_store_file_checksum --file="$config_auth"
ynh_store_file_checksum --file="$config_auth_worker"
ynh_store_file_checksum --file="$config_files"
ynh_store_file_checksum --file="$config_syncing_server"
ynh_store_file_checksum --file="$config_syncing_server_worker"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# GENERIC FINALIZATION
#=================================================
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
@ -391,7 +365,7 @@ ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1
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"
@ -407,35 +381,35 @@ ynh_script_progression --message="Starting a systemd service..." --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.*$'
#=================================================
# SETUP A CRON
@ -449,25 +423,20 @@ chown root: "/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app"
#=================================================
# SETUP FAIL2BAN
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
# Create a dedicated fail2ban config
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --use_template
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# STORE SETTINGS
#=================================================
ynh_app_setting_set --app=$app --key=standalone --value="true"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -91,4 +91,3 @@ ynh_is_main_device_a_sd_card () {
return 1
fi
}

View file

@ -5,27 +5,27 @@
# usage: ynh_redis_get_free_db
# | returns: the database number to use
ynh_redis_get_free_db() {
local result max db
result=$(redis-cli INFO keyspace)
local result max db
result=$(redis-cli INFO keyspace)
# get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
# get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
db=0
# default Debian setting is 15 databases
for i in $(seq 0 "$max")
do
if ! echo "$result" | grep -q "db$i"
then
db=$i
break 1
fi
db=-1
done
db=0
# default Debian setting is 15 databases
for i in $(seq 0 "$max")
do
if ! echo "$result" | grep -q "db$i"
then
db=$i
break 1
fi
db=-1
done
test "$db" -eq -1 && ynh_die --message="No available Redis databases..."
test "$db" -eq -1 && ynh_die --message="No available Redis databases..."
echo "$db"
echo "$db"
}
# Create a master password and set up global settings
@ -34,6 +34,6 @@ ynh_redis_get_free_db() {
# usage: ynh_redis_remove_db database
# | arg: database - the database to erase
ynh_redis_remove_db() {
local db=$1
redis-cli -n "$db" flushall
local db=$1
redis-cli -n "$db" flushall
}

View file

@ -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

View file

@ -1,2 +0,0 @@
*~
*.sw[op]