From 7f1048ac90129803371b6981d06fc93583901288 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 6 Aug 2021 02:07:54 +0200 Subject: [PATCH 1/3] Apply example_ynh --- check_process | 8 -- conf/nginx.conf | 35 +++--- scripts/backup | 24 ++--- scripts/change_url | 51 +++++---- scripts/install | 96 +++++++---------- scripts/remove | 29 +++-- scripts/restore | 74 ++++++------- scripts/upgrade | 262 +++++++++++++++++++++------------------------ 8 files changed, 260 insertions(+), 319 deletions(-) diff --git a/check_process b/check_process index 2f1b1dc..2a04250 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,3 @@ -# 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" @@ -22,8 +17,6 @@ #upgrade=1 from_commit=2c82b25537bc09b99c1daeced8ca38fe9b1bae8b backup_restore=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. - # incorrect_path=1 port_already_use=0 change_url=1 ;;; Options @@ -33,4 +26,3 @@ Notification=none ; commit=0459e279ab1ac0624203b710619bfe3f22686908 name=3.6.2~ynh1 manifest_arg=domain=DOMAIN&is_public=1 - diff --git a/conf/nginx.conf b/conf/nginx.conf index b7ae6e5..dbf605d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,22 +1,25 @@ location __PATH__/ { - alias __FINALPATH__/live/public ; - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + # Path to source + alias __FINALPATH__/live/public ; - proxy_pass http://127.0.0.1:__PORT____PATH__/; - 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; + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } - # upload max size - client_max_body_size 25M; + # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file + client_max_body_size 25M; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; - more_clear_input_headers 'Accept-Encoding'; + proxy_pass http://127.0.0.1:__PORT____PATH__/; + 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; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; + more_clear_input_headers 'Accept-Encoding'; } diff --git a/scripts/backup b/scripts/backup index 42f4b53..7e4729f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -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,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -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 @@ -32,42 +31,33 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= -# STANDARD BACKUP STEPS +# 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" #================================================= # 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 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" - #================================================= # SPECIFIC BACKUP #================================================= # 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.service" @@ -75,4 +65,4 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" # 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)." diff --git a/scripts/change_url b/scripts/change_url index 386886c..e309997 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -31,18 +31,18 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) #================================================= -# 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=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 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 @@ -54,13 +54,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 #================================================= @@ -75,30 +75,30 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --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 -# 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 #================================================= @@ -109,8 +109,6 @@ config_file="$final_path/live/.env" ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$new_domain${new_path%/}" --target_file="$config_file" ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=$old_path" --replace_string="RAILS_RELATIVE_URL_ROOT=$new_path" --target_file="$config_file" -#================================================= - #================================================= # GENERIC FINALISATION #================================================= @@ -118,12 +116,13 @@ ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=$old_path" --replace_ #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # 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 diff --git a/scripts/install b/scripts/install index 9f42047..c8bd49a 100644 --- a/scripts/install +++ b/scripts/install @@ -27,9 +27,10 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC -app=$YNH_APP_INSTANCE_NAME snserver_domain=$YNH_APP_ARG_SNSERVER_DOMAIN +app=$YNH_APP_INSTANCE_NAME + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -38,10 +39,6 @@ ynh_script_progression --message="Validating installation parameters..." --weigh final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -mkdir -p "$final_path/live" - -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -75,12 +72,22 @@ 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" ynh_install_ruby --ruby_version=$RUBY_VERSION +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=16 +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" git clone $SOURCE "$final_path/live" --quiet pushd "$final_path/live" git checkout $COMMIT --quiet @@ -95,22 +102,26 @@ then popd fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app: "$final_path" + +# Set permissions to app files +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log" +mkdir -p "$final_path/live/public" +chown -R $app: "$final_path/live/public" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp" + #================================================= # 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 -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # SPECIFIC SETUP #================================================= @@ -125,9 +136,9 @@ pushd "$final_path/live" popd #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Modifying a config file..." --weight=1 +ynh_script_progression --message="Adding a configuration file..." --weight=1 config_file="$final_path/live/.env" cp -f ../conf/env.sample $config_file @@ -143,6 +154,10 @@ 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="RAILS_RELATIVE_URL_ROOT=.*$" --replace_string="RAILS_RELATIVE_URL_ROOT=$path_url" --target_file="$config_file" +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$config_file" +ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # BUILDING #================================================= @@ -165,46 +180,19 @@ popd #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=3 - # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# 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_file" -ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." --weight=1 - -# Set permissions to app files -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" - -mkdir -p "$final_path/live/log" -chown -R $app: "$final_path/live/log" -mkdir -p "$final_path/live/public" -chown -R $app: "$final_path/live/public" -mkdir -p "$final_path/live/tmp" -chown -R $app: "$final_path/live/tmp" - -mkdir -p "/var/log/$app" -chown -R $app: "/var/log/$app" - #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Configuring log rotation..." --weight=2 +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" + # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile="$final_path/live/log/production.log" ynh_use_logrotate --logfile="/var/log/$app/$app.log" @@ -214,7 +202,7 @@ ynh_use_logrotate --logfile="/var/log/$app/$app.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "Standard Notes" --log "/var/log/$app/$app.log" +yunohost service add $app --description="Standard Notes" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -227,20 +215,20 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=2 +ynh_script_progression --message="Configuring permissions..." --weight=2 # Make app public if necessary if [ $is_public -eq 1 ] then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=2 +ynh_script_progression --message="Reloading NGINX web server..." --weight=2 ynh_systemd_action --service_name=nginx --action=reload @@ -256,5 +244,3 @@ is_service_ready #================================================= ynh_script_progression --message="Installation of $app completed" --last - - diff --git a/scripts/remove b/scripts/remove index 6226538..460bbc1 100755 --- a/scripts/remove +++ b/scripts/remove @@ -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`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --weight=1 - yunohost service remove $app + ynh_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove $app fi #================================================= @@ -49,8 +49,8 @@ ynh_script_progression --message="Removing dependencies..." --weight=4 # Remove metapackage and its dependencies ynh_remove_ruby -ynh_remove_app_dependencies ynh_remove_nodejs +ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR @@ -63,9 +63,9 @@ ynh_secure_remove --file="$final_path" #================================================= # 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 #================================================= @@ -75,7 +75,6 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight= # Remove the app-specific logrotate config ynh_remove_logrotate -ynh_secure_remove --file="/var/log/$app" #================================================= # CLOSE A PORT @@ -83,21 +82,19 @@ ynh_secure_remove --file="/var/log/$app" if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression --message="Closing port $port..." --weight=1 - ynh_exec_warn_less yunohost firewall disallow TCP $port + ynh_script_progression --message="Closing port $port..." --weight=1 + ynh_exec_warn_less yunohost firewall disallow TCP $port fi -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -#ynh_script_progression --message="Removing fail2ban configuration..." --weight=1 - -# Remove the dedicated fail2ban config -#ynh_remove_fail2ban_config - #================================================= # SPECIFIC REMOVE #================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index a967dc9..6e77925 100755 --- a/scripts/restore +++ b/scripts/restore @@ -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_install_ruby__2 source /usr/share/yunohost/helpers @@ -16,8 +16,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -25,7 +24,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 @@ -39,25 +38,19 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) ynh_script_progression --message="Validating restoration parameters..." --weight=1 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 \ - || ynh_die --message="There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=2 - -ynh_restore_file --origin_path="$final_path" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -66,15 +59,24 @@ ynh_script_progression --message="Recreating the dedicated system user..." --wei # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= -# RESTORE FAIL2BAN CONFIGURATION +# RESTORE THE APP MAIN DIR #================================================= -#ynh_script_progression --message="Restoring the fail2ban configuration..." --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=2 -#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 +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app: "$final_path" + +# Set permissions to app files +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log" +mkdir -p "$final_path/live/public" +chown -R $app: "$final_path/live/public" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp" #================================================= # SPECIFIC RESTORATION @@ -88,31 +90,18 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_install_ruby --ruby_version=$RUBY_VERSION + +#================================================= +# INSTALLING RUBY AND BUNDLER +#================================================= +ynh_script_progression --message="Installing Ruby... ( This may take a while... )" --weight=100 #212 + pushd "$final_path/live" ynh_use_ruby ynh_gem update --system --no-document --quiet ynh_gem install bundler --no-document --quiet popd -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" - -mkdir -p "$final_path/live/log" -chown -R $app: "$final_path/live/log" -mkdir -p "$final_path/live/public" -chown -R $app: "$final_path/live/public" -mkdir -p "$final_path/live/tmp" -chown -R $app: "$final_path/live/tmp" - -mkdir -p "/var/log/$app" -chown -R $app: "/var/log/$app" - #================================================= # RESTORE SYSTEMD #================================================= @@ -124,8 +113,9 @@ systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "Standard Notes" --log "/var/log/$app/$app.log" +yunohost service add $app --description="Standard Notes" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -137,6 +127,10 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app" @@ -145,7 +139,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # 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 diff --git a/scripts/upgrade b/scripts/upgrade index 96b4297..99bc95f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -28,51 +28,10 @@ config_file="$final_path/live/.env" #================================================= # 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) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - -# 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 -fi - -if ynh_compare_current_package_version --comparison lt --version "3.6.8~ynh2" -then - # Add variables to .env config file - echo -e "\ -\n# Sub-URI\ -\nRAILS_RELATIVE_URL_ROOT=/\ -" >> "$config_file" - - # Apply Patch - if [ -f "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" ] - then - pushd "$final_path/live" - patch --strip=1 < "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" - popd - fi -fi - - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -81,8 +40,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 @@ -97,48 +56,39 @@ 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" #================================================= -# UPGRADE DEPENDENCIES +# ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=37 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -ynh_install_ruby --ruby_version=$RUBY_VERSION +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=17 - # Backup files to keep - tmpdir=$(mktemp -d) - if [ -d $final_path/live/log ] ; then - cp -Rp $final_path/live/log $tmpdir - fi - # Remove destination directory - ynh_secure_remove --file=$final_path - # Download - mkdir -p "$final_path" - git clone $SOURCE "$final_path/live" --quiet - pushd "$final_path/live" - git checkout $COMMIT --quiet - git submodule update --init --recursive --quiet - popd - # Restore files - if [ -d $tmpdir/log ] ; then - cp -Rp $tmpdir/log "$final_path/live" - fi + ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=3 +# 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 +fi -# Create a dedicated nginx config -ynh_add_nginx_config +if ynh_compare_current_package_version --comparison lt --version "3.6.8~ynh2" +then + # Add variables to .env config file + echo -e "\ +\n# Sub-URI\ +\nRAILS_RELATIVE_URL_ROOT=/\ +" >> "$config_file" + + # Apply Patch + if [ -f "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" ] + then + pushd "$final_path/live" + patch --strip=1 < "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" + popd + fi +fi #================================================= # CREATE DEDICATED USER @@ -148,6 +98,64 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) 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=17 + + # Backup files to keep + tmpdir=$(mktemp -d) + if [ -d $final_path/live/log ] ; then + cp -Rp $final_path/live/log $tmpdir + fi + # Remove destination directory + ynh_secure_remove --file=$final_path + # Download + mkdir -p "$final_path" + git clone $SOURCE "$final_path/live" --quiet + pushd "$final_path/live" + git checkout $COMMIT --quiet + git submodule update --init --recursive --quiet + popd + # Restore files + if [ -d $tmpdir/log ] ; then + cp -Rp $tmpdir/log "$final_path/live" + fi +fi + +# Set permissions to app files +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app: "$final_path" + +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log" +mkdir -p "$final_path/live/public" +chown -R $app: "$final_path/live/public" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=37 + +ynh_install_app_dependencies $pkg_dependencies +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_ruby --ruby_version=$RUBY_VERSION + #================================================= # SPECIFIC UPGRADE #================================================= @@ -162,42 +170,47 @@ pushd "$final_path/live" popd #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= + if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Modifying a config file..." --weight=2 + ynh_script_progression --message="Updating a configuration file..." --weight=2 - 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" - 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="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file" - if [ "$snserver_domain" = "" ]; then - snserver_domain="sync.standardnotes.org" - fi - ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$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" + 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="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$domain${path_url%/}" --target_file="$config_file" + if [ "$snserver_domain" = "" ]; then + snserver_domain="sync.standardnotes.org" + 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 +ynh_store_file_checksum --file="$config_file" +ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # BUILDING #================================================= + if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Building... ( This may take a while... )" --weight=100 #131 + ynh_script_progression --message="Building... ( This may take a while... )" --weight=100 #131 - chown -R $app: "$final_path" + chown -R $app: "$final_path" - pushd "$final_path/live" - ynh_use_nodejs - ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' - ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' - ynh_exec_warn_less "ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --quiet" - ynh_exec_warn_less "ynh_exec_as $app env PATH=$ynh_node_load_PATH yarn install --pure-lockfile" - ynh_exec_warn_less "ynh_exec_as $app env PATH=$ynh_node_load_PATH yarn bundle" - ynh_exec_warn_less "ynh_exec_as $app $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet" - popd + pushd "$final_path/live" + ynh_use_nodejs + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set --local path 'vendor/bundle' + ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set with 'development' + ynh_exec_warn_less "ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --quiet" + ynh_exec_warn_less "ynh_exec_as $app env PATH=$ynh_node_load_PATH yarn install --pure-lockfile" + ynh_exec_warn_less "ynh_exec_as $app env PATH=$ynh_node_load_PATH yarn bundle" + ynh_exec_warn_less "ynh_exec_as $app $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet" + popd fi #================================================= @@ -208,40 +221,16 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=4 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -ynh_store_file_checksum --file="$config_file" -ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." --weight=2 - -# Set permissions to app files -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" - -mkdir -p "$final_path/live/log" -chown -R $app: "$final_path/live/log" -mkdir -p "$final_path/live/public" -chown -R $app: "$final_path/live/public" -mkdir -p "$final_path/live/tmp" -chown -R $app: "$final_path/live/tmp" - -mkdir -p "/var/log/$app" -chown -R $app: "/var/log/$app" - #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" + # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile="$final_path/live/log/production.log" ynh_use_logrotate --logfile="/var/log/$app/$app.log" @@ -251,28 +240,19 @@ ynh_use_logrotate --logfile="/var/log/$app/$app.log" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "Standard Notes" --log "/var/log/$app/$app.log" +yunohost service add $app --description="Standard Notes" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 -# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -#================================================= -# UPGRADE FAIL2BAN -#================================================= -#ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1 - -# Create a dedicated fail2ban config -#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - #================================================= # 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 From 84f8cc464b7a5508fc1ab1138a68cdcf080b255b Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 6 Aug 2021 00:08:00 +0000 Subject: [PATCH 2/3] Auto-update README --- README.md | 21 +++++---------------- README_fr.md | 37 +++++++++++++++---------------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e3eaab3..ab78ebc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ - - ---- -