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

Fix, Cleanup

This commit is contained in:
Fabian Wilkens 2020-12-27 01:28:03 +01:00
parent 23c080814d
commit dd4c4d6f57
12 changed files with 198 additions and 231 deletions

View file

@ -55,7 +55,7 @@ Can the app be used by multiple users? Yes
## Links ## Links
* Report a bug: https://github.com/YunoHost-Apps/snweb_ynh/issues * Report a bug: https://github.com/FabianWilknes/snweb_ynh/issues
* App website: https://standardnotes.org/ * App website: https://standardnotes.org/
* Upstream app repository: https://github.com/standardnotes/web * Upstream app repository: https://github.com/standardnotes/web
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/
@ -66,11 +66,11 @@ Developers info
---------------- ----------------
**Only if you want to use a testing branch for coding, instead of merging directly into master.** **Only if you want to use a testing branch for coding, instead of merging directly into master.**
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/snweb_ynh/tree/testing). Please do your pull request to the [testing branch](https://github.com/FabianWilknes/snweb_ynh/tree/testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
``` ```
sudo yunohost app install https://github.com/YunoHost-Apps/snweb_ynh/tree/testing --debug sudo yunohost app install https://github.com/FabianWilkens/snweb_ynh/tree/testing --debug
or or
sudo yunohost app upgrade snweb -u https://github.com/YunoHost-Apps/snweb_ynh/tree/testing --debug sudo yunohost app upgrade snweb -u https://github.com/FabianWilkens/snweb_ynh/tree/testing --debug
``` ```

View file

@ -6,21 +6,16 @@
;; Test complet ;; Test complet
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
language="en"
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
password="pass"
port="666" (PORT)
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=0
setup_root=1 setup_root=1
setup_nourl=0 setup_nourl=0
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=CommitHash upgrade=0 from_commit=
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
@ -34,7 +29,7 @@
Email= Email=
Notification=none Notification=none
;;; Upgrade options ;;; Upgrade options
; commit=CommitHash ; commit=
name=Name and date of the commit. name=
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& manifest_arg=domain=DOMAIN&is_public=1

View file

@ -1,41 +1,22 @@
# upload max size location __PATH__/ {
client_max_body_size 25M; alias __FINALPATH__/live/public ;
root __FINALPATH__/live/public; if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
location / { proxy_pass http://127.0.0.1:__PORT____PATH__/;
if ($scheme = http) { proxy_http_version 1.1;
rewrite ^ https://$server_name$request_uri? permanent; proxy_set_header Host $http_host;
} proxy_set_header Upgrade $http_upgrade;
proxy_set_header Accept-Encoding ""; proxy_set_header Connection $connection_upgrade;
try_files $uri @proxy; proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc; # upload max size
client_max_body_size 25M;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
more_clear_input_headers 'Accept-Encoding';
} }
location @proxy {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_pass http://127.0.0.1:__PORT__;
proxy_buffering on;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#proxy_cache CACHE;
proxy_cache_valid 200 7d;
proxy_cache_valid 410 24h;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
add_header X-Cached $upstream_cache_status;
add_header Strict-Transport-Security "max-age=31536000";
tcp_nodelay on;
}
error_page 500 501 502 503 504 /500.html;

View file

@ -1,5 +1,5 @@
{ {
"name": "Standard Notes - Web App", "name": "Standard Notes",
"id": "snweb", "id": "snweb",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
@ -18,7 +18,7 @@
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
"nginx", "nginx",
"mysql" "mysql"
], ],
"arguments": { "arguments": {
@ -28,27 +28,30 @@
"type": "domain", "type": "domain",
"ask": { "ask": {
"en": "Choose a domain name for snweb", "en": "Choose a domain name for snweb",
"fr": "Choisissez un domaine pour snweb", "fr": "Choisissez un domaine pour snweb",
"de": "Wähle einen Domain Namen für snweb" "de": "Wähle einen Domain Namen für snweb"
}, },
"example": "example.com" "example": "example.com"
}, },
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"help": {
"en": "A public application means that anyone can access this site."
},
"ask": { "ask": {
"en": "Is it a public application?", "en": "Is it a public application?",
"fr": "Est-ce une application publique ?", "fr": "Est-ce une application publique ?",
"de": "Ist die Application Öffendlich?" "de": "Ist die Application Öffendlich?"
}, },
"default": true "default": false
}, },
{ {
"name": "snserver_domain", "name": "snserver_domain",
"type": "string", "type": "string",
"ask": { "ask": {
"en": "Choose the default Standard Notes Syncing Server", "en": "Choose the default Standard Notes Syncing Server",
"de": "Wähle den Standard Notes Syncing Server" "de": "Wähle den Standard Notes Syncing Server"
}, },
"default": "sync.standardnotes.org" "default": "sync.standardnotes.org"
} }

View file

@ -15,4 +15,4 @@
--- ---
*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* *If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results*
[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/) [![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/snweb_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/snweb_ynh%20PR-NUM-%20(USERNAME)/)

View file

@ -6,11 +6,11 @@
# dependencies used by the app # dependencies used by the app
pkg_dependencies="\ pkg_dependencies="\
zlib1g-dev \ zlib1g-dev \
libssl-dev \ libssl-dev \
libjemalloc-dev \ libjemalloc-dev \
git \ git \
" "
RUBY_VERSION="2.7.2" RUBY_VERSION="2.7.2"
NODEJS_VERSION="10" NODEJS_VERSION="10"
@ -26,21 +26,21 @@ COMMIT="31676f1cc61898147b363d442593870ae880d3e5"
# (hence in user home dir, with prior loading of .profile, etc.) # (hence in user home dir, with prior loading of .profile, etc.)
# usage: exec_login_as USER COMMAND [ARG ...] # usage: exec_login_as USER COMMAND [ARG ...]
exec_login_as() { exec_login_as() {
local user=$1 local user=$1
shift 1 shift 1
exec_as $user --login "$@" exec_as $user --login "$@"
} }
# Execute a command as another user # Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...] # usage: exec_as USER COMMAND [ARG ...]
exec_as() { exec_as() {
local user=$1 local user=$1
shift 1 shift 1
if [[ $user = $(whoami) ]]; then if [[ $user = $(whoami) ]]; then
eval "$@" eval "$@"
else else
sudo -u "$user" "$@" sudo -u "$user" "$@"
fi fi
} }
#================================================ #================================================

View file

@ -15,8 +15,8 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script. ### 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -24,7 +24,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2 ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -33,31 +33,24 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Backing up the main app directory..." --weight=1 ynh_print_info "Backing up the main app directory..."
ynh_backup --src_path="$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Backing up nginx web server configuration..." --weight=2 ynh_print_info "Backing up nginx web server configuration..."
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP FAIL2BAN CONFIGURATION # BACKUP FAIL2BAN CONFIGURATION
#================================================= #=================================================
#ynh_script_progression --message="Backing up fail2ban configuration..." --weight=1 #ynh_print_info "Backing up fail2ban configuration..."
#ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" #ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
#ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
@ -67,26 +60,19 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 ynh_print_info "Backing up logrotate configuration..."
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Backing up systemd configuration..." --weight=1 ynh_print_info "Backing up systemd configuration..."
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -25,7 +25,7 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1 ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
@ -34,16 +34,16 @@ port=$(ynh_app_setting_get --app=$app --key=port)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1 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 # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -55,13 +55,13 @@ ynh_abort_if_errors
change_domain=0 change_domain=0
if [ "$old_domain" != "$new_domain" ] if [ "$old_domain" != "$new_domain" ]
then then
change_domain=1 change_domain=1
fi fi
change_path=0 change_path=0
if [ "$old_path" != "$new_path" ] if [ "$old_path" != "$new_path" ]
then then
change_path=1 change_path=1
fi fi
#================================================= #=================================================
@ -69,37 +69,37 @@ fi
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 ynh_script_progression --message="Updating nginx web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf 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 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config "port" ynh_add_nginx_config "port"
fi fi
# Change the domain for nginx # Change the domain for nginx
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
#================================================= #=================================================
@ -107,7 +107,7 @@ fi
#================================================= #=================================================
config_file="$final_path/live/.env" config_file="$final_path/live/.env"
ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file" ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$new_domain${new_path%/}" --target_file="$config_file"
#================================================= #=================================================
@ -116,27 +116,20 @@ ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_str
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
sleep 10
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# STORE SETTINGS
#=================================================
ynh_script_progression --message="Storing settings..." --weight=2
ynh_app_setting_set --app=$app --key=domain --value=$new_domain
ynh_app_setting_set --app=$app --key=path --value=$new_path
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --time --last ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -84,7 +84,7 @@ ynh_script_progression --message="Setting up source files..." --weight=16
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
git clone $SOURCE "$final_path/live" --quiet git clone $SOURCE "$final_path/live" --quiet
pushd "$final_path/live" pushd "$final_path/live"
git checkout $COMMIT --quiet git checkout $COMMIT --quiet
popd popd
#================================================= #=================================================
@ -108,7 +108,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
# INSTALLING RUBY AND BUNDLER # INSTALLING RUBY AND BUNDLER
#================================================= #=================================================
ynh_script_progression --message="Installing Ruby..." --weight=212 ynh_script_progression --message="Installing Ruby... ( This may take a while... )" --weight=100 #212
ynh_install_ruby --ruby_version=$RUBY_VERSION ynh_install_ruby --ruby_version=$RUBY_VERSION
@ -126,27 +126,27 @@ secret_key=$(ynh_string_random --length=48 | base64)
ynh_replace_string --match_string="SECRET_KEY_BASE=test" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" ynh_replace_string --match_string="SECRET_KEY_BASE=test" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file"
ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file" ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file"
if [ "$snserver_domain" = "" ]; then if [ "$snserver_domain" = "" ]; then
snserver_domain="sync.standardnotes.org" snserver_domain="sync.standardnotes.org"
fi fi
ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file" ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file"
#================================================= #=================================================
# BUILDING # BUILDING
#================================================= #=================================================
ynh_script_progression --message="Building..." --weight=497 ynh_script_progression --message="Building... ( This may take a while... )" --weight=100 #497
ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin" ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin"
chown -R $app: "$final_path" chown -R $app: "$final_path"
pushd "$final_path/live" pushd "$final_path/live"
git submodule update --init --recursive git submodule update --init --recursive --quiet
ynh_use_nodejs ynh_use_nodejs
exec_as $app $ENV_PATH $ynh_npm ci exec_as $app $ENV_PATH $ynh_npm --loglevel=error ci
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --quiet
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install --quiet
exec_as $app $ENV_PATH $ynh_npm run bundle exec_as $app $ENV_PATH $ynh_npm --loglevel=error run bundle
exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet
popd popd
#================================================= #=================================================
@ -157,9 +157,9 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=3
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --others_var="\ ynh_add_systemd_config --others_var="\
port \ port \
ENV_PATH \ ENV_PATH \
RUBY_VERSION \ RUBY_VERSION \
" "
#================================================= #=================================================
@ -183,6 +183,8 @@ chown -R root:root "$final_path"
chown $app: "$final_path" chown $app: "$final_path"
mkdir -p $app: "$final_path/.config" mkdir -p $app: "$final_path/.config"
chown $app: "$final_path/.config" chown $app: "$final_path/.config"
mkdir -p $app: "$final_path/.cache"
chown $app: "$final_path/.cache"
mkdir -p "$final_path/live/log" mkdir -p "$final_path/live/log"
chown -R $app: "$final_path/live/log" chown -R $app: "$final_path/live/log"
mkdir -p "$final_path/live/public" mkdir -p "$final_path/live/public"
@ -217,7 +219,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
sleep 10
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -227,8 +229,8 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=2
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# Create the visitors permission if needed # Create the visitors permission if needed
ynh_permission_update --permission "main" --add "visitors" ynh_permission_update --permission "main" --add "visitors"
fi fi
#================================================= #=================================================

View file

@ -30,8 +30,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service..." --weight=1 ynh_script_progression --message="Removing $app service..." --weight=1
yunohost service remove $app yunohost service remove $app
fi fi
#================================================= #=================================================
@ -83,8 +83,8 @@ ynh_secure_remove --file="/var/log/$app"
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_script_progression --message="Closing port $port..." --weight=1 ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
#================================================= #=================================================

View file

@ -16,8 +16,8 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script. #### 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -39,9 +39,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available --domain=$domain --path_url=$path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
@ -81,7 +81,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=294 ynh_script_progression --message="Reinstalling dependencies... ( This may take a while... )" --weight=100 #294
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
@ -93,20 +93,21 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION
#================================================= #=================================================
# BUILDING # BUILDING
#================================================= #=================================================
ynh_script_progression --message="Reinstalling $app..." --weight=222 ynh_script_progression --message="Reinstalling $app... ( This may take a while... )" --weight=100 #222
ynh_use_nodejs
ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin" ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin"
chown -R $app: "$final_path" chown -R $app: "$final_path"
pushd "$final_path/live" pushd "$final_path/live"
git submodule update --init --recursive git submodule update --init --recursive --quiet
exec_as $app $ENV_PATH $ynh_npm ci ynh_use_nodejs
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler exec_as $app $ENV_PATH $ynh_npm --loglevel=error ci
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --quiet
exec_as $app $ENV_PATH $ynh_npm run bundle env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install --quiet
exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile exec_as $app $ENV_PATH $ynh_npm --loglevel=error run bundle
exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet
popd popd
#================================================= #=================================================
@ -129,13 +130,16 @@ mkdir -p "$final_path/live/tmp"
chown -R $app: "$final_path/live/tmp" chown -R $app: "$final_path/live/tmp"
chown $app: "$final_path/live/Gemfile.lock" chown $app: "$final_path/live/Gemfile.lock"
mkdir -p "/var/log/$app"
chown -R $app: "/var/log/$app"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
@ -149,6 +153,7 @@ yunohost service add $app --description "Standard Notes" --log "/var/log/$app/$a
ynh_script_progression --message="Starting a systemd service..." --weight=2 ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
sleep 10
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION

View file

@ -43,17 +43,17 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Fix is_public as a boolean value # Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1 ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0 is_public=0
fi fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]; then
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
#================================================= #=================================================
@ -64,8 +64,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -93,24 +93,24 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." --weight=17 ynh_script_progression --message="Upgrading source files..." --weight=17
# Backup files to keep # Backup files to keep
tmpdir=$(mktemp -d) tmpdir=$(mktemp -d)
if [ -d $final_path/live/log ] ; then if [ -d $final_path/live/log ] ; then
cp -Rp $final_path/live/log $tmpdir cp -Rp $final_path/live/log $tmpdir
fi fi
# Remove destination directory # Remove destination directory
ynh_secure_remove --file=$final_path ynh_secure_remove --file=$final_path
# Download # Download
mkdir -p "$final_path" mkdir -p "$final_path"
git clone $SOURCE "$final_path/live" --quiet git clone $SOURCE "$final_path/live" --quiet
pushd "$final_path/live" pushd "$final_path/live"
git checkout $COMMIT --quiet git checkout $COMMIT --quiet
popd popd
# Restore files # Restore files
if [ -d $tmpdir/log ] ; then if [ -d $tmpdir/log ] ; then
cp -Rp $tmpdir/log "$final_path/live" cp -Rp $tmpdir/log "$final_path/live"
fi fi
fi fi
#================================================= #=================================================
@ -135,29 +135,28 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
# INSTALLING RUBY AND BUNDLER # INSTALLING RUBY AND BUNDLER
#================================================= #=================================================
ynh_script_progression --message="Installing Ruby..." --weight=331 ynh_script_progression --message="Installing Ruby... ( This may take a while... )" --weight=100 #331
ynh_install_ruby --ruby_version=$RUBY_VERSION ynh_install_ruby --ruby_version=$RUBY_VERSION
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
config_file="$final_path/live/.env"
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Modifying a config file..." --weight=2 ynh_script_progression --message="Modifying a config file..." --weight=2
config_file="$final_path/live/.env" cp -f ../conf/env.sample $config_file
cp -f ../conf/env.sample $config_file ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAILS_ENV=production" --target_file="$config_file"
ynh_replace_string --match_string="PORT=3001" --replace_string="PORT=$port" --target_file="$config_file"
ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAILS_ENV=production" --target_file="$config_file" secret_key=$(ynh_string_random --length=48 | base64)
ynh_replace_string --match_string="PORT=3001" --replace_string="PORT=$port" --target_file="$config_file" ynh_replace_string --match_string="SECRET_KEY_BASE=test" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file"
secret_key=$(ynh_string_random --length=48 | base64) ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file"
ynh_replace_string --match_string="SECRET_KEY_BASE=test" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" if [ "$snserver_domain" = "" ]; then
ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file" snserver_domain="sync.standardnotes.org"
if [ "$snserver_domain" = "" ]; then fi
snserver_domain="sync.standardnotes.org" ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file"
fi
ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file"
fi fi
#================================================= #=================================================
@ -165,21 +164,21 @@ fi
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Building..." --weight=131 ynh_script_progression --message="Building... ( This may take a while... )" --weight=100 #131
ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin" ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin"
chown -R $app: "$final_path" chown -R $app: "$final_path"
pushd "$final_path/live" pushd "$final_path/live"
git submodule update --init --recursive git submodule update --init --recursive --quiet
ynh_use_nodejs ynh_use_nodejs
exec_as $app $ENV_PATH $ynh_npm ci exec_as $app $ENV_PATH $ynh_npm --loglevel=error ci
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler --quiet
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install --quiet
exec_as $app $ENV_PATH $ynh_npm run bundle exec_as $app $ENV_PATH $ynh_npm --loglevel=error run bundle
exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet
popd popd
fi fi
#================================================= #=================================================
@ -189,9 +188,9 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=4
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --others_var="\ ynh_add_systemd_config --others_var="\
port \ port \
ENV_PATH \ ENV_PATH \
RUBY_VERSION \ RUBY_VERSION \
" "
#================================================= #=================================================
@ -213,6 +212,8 @@ chown -R root:root "$final_path"
chown $app: "$final_path" chown $app: "$final_path"
mkdir -p $app: "$final_path/.config" mkdir -p $app: "$final_path/.config"
chown $app: "$final_path/.config" chown $app: "$final_path/.config"
mkdir -p $app: "$final_path/.cache"
chown $app: "$final_path/.cache"
mkdir -p "$final_path/live/log" mkdir -p "$final_path/live/log"
chown -R $app: "$final_path/live/log" chown -R $app: "$final_path/live/log"
mkdir -p "$final_path/live/public" mkdir -p "$final_path/live/public"
@ -247,6 +248,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
sleep 10
#================================================= #=================================================
# UPGRADE FAIL2BAN # UPGRADE FAIL2BAN
@ -264,8 +266,8 @@ ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=2
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# Create the visitors permission if needed # Create the visitors permission if needed
ynh_permission_update --permission "main" --add "visitors" ynh_permission_update --permission "main" --add "visitors"
fi fi
#================================================= #=================================================