2020-01-18 10:28:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2021-08-29 00:17:52 +02:00
|
|
|
source ynh_add_swap
|
2020-01-18 10:28:47 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Stopping systemd services..." --weight=1
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-api-gateway" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/api-gateway.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-auth" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/auth.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-auth-worker" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/auth-worker.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-files" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/files.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-syncing-server" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/syncing-server.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-syncing-server-worker" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/syncing-server-worker.log"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-workspace" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/workspace.log"
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
# If jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$jwt_secret" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
|
|
|
# If legacy_jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$legacy_jwt_secret" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
|
|
|
# If auth_jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$auth_jwt_secret" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
auth_jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
|
|
|
# If pseudo_key_params_key doesn't exist, create it
|
|
|
|
if [ -z "$pseudo_key_params_key" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
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
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
|
|
|
# If encryption_server_key doesn't exist, create it
|
|
|
|
if [ -z "$encryption_server_key" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
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
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
# If valet_token_secret doesn't exist, create it
|
|
|
|
if [ -z "$valet_token_secret" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
valet_token_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret
|
2021-07-11 14:10:21 +02:00
|
|
|
fi
|
2022-08-09 09:59:02 +02:00
|
|
|
# If disable_user_registration doesn't exist, create it
|
2022-08-09 21:17:53 +02:00
|
|
|
if [ -z "$disable_user_registration" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
disable_user_registration=false
|
|
|
|
ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
|
2022-08-09 09:59:02 +02:00
|
|
|
fi
|
|
|
|
# If files_zise doesn't exist, create it
|
|
|
|
if [ -z "$files_size" ]; then
|
2024-01-15 22:37:42 +01:00
|
|
|
files_size=100
|
|
|
|
ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
|
2022-08-09 09:59:02 +02:00
|
|
|
fi
|
2021-07-11 14:10:21 +02:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
if [ -n "${api_gateway_version_installed+x}" ]; then
|
|
|
|
ynh_app_setting_delete --app=$app --key=api_gateway_version_installed
|
2022-08-09 21:17:53 +02:00
|
|
|
fi
|
2024-01-15 22:37:42 +01:00
|
|
|
if [ -n "${auth_version_installed+x}" ]; then
|
|
|
|
ynh_app_setting_delete --app=$app --key=auth_version_installe
|
2022-08-09 21:17:53 +02:00
|
|
|
fi
|
2024-01-15 22:37:42 +01:00
|
|
|
if [ -n "${syncing_server_version_installed+x}" ]; then
|
|
|
|
ynh_app_setting_delete --app=$app --key=syncing_server_version_installed
|
2022-08-09 21:17:53 +02:00
|
|
|
fi
|
2024-01-15 22:37:42 +01:00
|
|
|
if [ -n "${install_dir_www+x}" ]; then
|
|
|
|
ynh_app_setting_delete --app=$app --key=install_dir_www
|
2022-08-01 21:46:14 +02:00
|
|
|
fi
|
2024-01-15 22:17:38 +01:00
|
|
|
# If install_dir_extensions exist, delete it
|
2024-01-15 22:37:42 +01:00
|
|
|
if [ -n "${install_dir_extensions+x}" ]; then
|
|
|
|
ynh_app_setting_delete --app=$app --key=install_dir_extensions
|
2022-08-01 21:46:14 +02:00
|
|
|
fi
|
|
|
|
|
2021-07-11 14:10:21 +02:00
|
|
|
# If old service exsits; remove it
|
2024-01-15 22:37:42 +01:00
|
|
|
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
|
2021-07-11 17:36:53 +02:00
|
|
|
fi
|
2024-01-15 22:37:42 +01:00
|
|
|
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
|
2022-08-04 17:28:39 +02:00
|
|
|
fi
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
# UPGRADE NODEJS
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading NodeJS..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_install_nodejs --nodejs_version="$nodejs_version"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2022-08-31 02:25:01 +02:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1
|
|
|
|
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
|
2024-01-15 22:17:38 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:$app" "$install_dir"
|
2021-02-07 00:02:09 +01:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
# ADD A CONFIGURATION
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Adding configuration files..." --weight=2
|
2021-02-06 01:44:31 +01:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway"
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_add_config --template="env_auth.env.sample" --destination="$config_auth"
|
|
|
|
ynh_add_config --template="env_auth-worker.env.sample" --destination="$config_auth_worker"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_config --template="env_files.env.sample" --destination="$config_files"
|
|
|
|
ynh_add_config --template="env_syncing-server.env.sample" --destination="$config_syncing_server"
|
|
|
|
ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace"
|
2021-01-24 11:36:36 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_add_config --template="cron.env" --destination="$install_dir/cron.env"
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-05-01 21:48:58 +02:00
|
|
|
# INSTALLING Standard Notes - Syncing Server
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Building Standard Notes - Syncing Server..." --weight=93
|
|
|
|
|
|
|
|
ynh_use_nodejs
|
|
|
|
pushd "$install_dir/live"
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn install --immutable
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn build
|
|
|
|
popd
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_add_systemd_config --service="$app-auth" --template="systemd_auth.service"
|
|
|
|
ynh_add_systemd_config --service="$app-auth-worker" --template="systemd_auth-worker.service"
|
2022-08-04 17:28:39 +02:00
|
|
|
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"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
|
|
|
|
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
|
|
|
|
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
|
|
|
|
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
|
|
|
|
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
|
|
|
|
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
|
|
|
|
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
|
2021-07-08 11:50:04 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log"
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/auth.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/auth-worker.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/files.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
# Create a dedicated Fail2Ban config
|
|
|
|
ynh_add_fail2ban_config --use_template
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
|
|
|
chown root: "/etc/cron.d/$app"
|
|
|
|
chmod 640 "/etc/cron.d/$app"
|
|
|
|
|
|
|
|
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
|
|
|
|
ynh_add_swap --size="$swap_needed"
|
|
|
|
fi
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2020-12-24 12:11:42 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2020-12-24 12:11:42 +01:00
|
|
|
#=================================================
|
2024-01-15 22:37:42 +01:00
|
|
|
ynh_script_progression --message="Starting systemd services..." --weight=1
|
2020-12-24 12:11:42 +01:00
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-api-gateway" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/api-gateway.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-auth" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-auth-worker" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth-worker.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-files" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/files.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-syncing-server" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/syncing-server.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--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.*$'
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:37:42 +01:00
|
|
|
--service_name="$app-workspace" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/workspace.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|