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
|
2021-03-06 21:39:49 +01:00
|
|
|
source ynh_redis
|
2020-01-18 10:28:47 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2022-08-04 17:28:39 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2020-12-24 12:11:42 +01:00
|
|
|
db_user=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
|
2021-07-08 11:50:04 +02:00
|
|
|
port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
|
|
|
|
port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
|
2022-08-04 17:28:39 +02:00
|
|
|
port_files=$(ynh_app_setting_get --app=$app --key=port_files)
|
|
|
|
port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
|
|
|
|
port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2021-03-06 21:39:49 +01:00
|
|
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
jwt_secret=$(ynh_app_setting_get --app=$app --key=jwt_secret)
|
|
|
|
legacy_jwt_secret=$(ynh_app_setting_get --app=$app --key=legacy_jwt_secret)
|
|
|
|
auth_jwt_secret=$(ynh_app_setting_get --app=$app --key=auth_jwt_secret)
|
|
|
|
pseudo_key_params_key=$(ynh_app_setting_get --app=$app --key=pseudo_key_params_key)
|
|
|
|
encryption_server_key=$(ynh_app_setting_get --app=$app --key=encryption_server_key)
|
2022-08-04 17:28:39 +02:00
|
|
|
valet_token_secret=$(ynh_app_setting_get --app=$app --key=valet_token_secret)
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_server_version)
|
2021-07-08 11:50:04 +02:00
|
|
|
auth_version_installed=$(ynh_app_setting_get --app=$app --key=auth_version)
|
|
|
|
api_gateway_version_installed=$(ynh_app_setting_get --app=$app --key=api_gateway_version)
|
|
|
|
|
2022-08-09 09:59:02 +02:00
|
|
|
disable_user_registration=$(ynh_app_setting_get --app=$app --key=DISABLE_USER_REGISTRATION)
|
|
|
|
files_size=$(ynh_app_setting_get --app=$app --key=FILES_SIZE)
|
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
config_api_gateway="$final_path/live/api-gateway.env"
|
2021-07-08 11:50:04 +02:00
|
|
|
config_auth="$final_path/live/auth.env"
|
|
|
|
config_auth_worker="$final_path/live/auth-worker.env"
|
2022-08-04 17:28:39 +02:00
|
|
|
config_files="$final_path/live/files.env"
|
|
|
|
config_syncing_server="$final_path/live/syncing-server.env"
|
|
|
|
config_syncing_server_worker="$final_path/live/syncing-server-worker.env"
|
2021-07-08 11:50:04 +02:00
|
|
|
|
2021-11-26 20:51:16 +01:00
|
|
|
nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK 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)
|
|
|
|
|
2021-02-06 21:41:33 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-api-gateway" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/api-gateway.log"
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-auth" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/auth.log"
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-auth-worker" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/auth-worker.log"
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-files" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/files.log"
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-syncing-server" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/syncing-server.log"
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-syncing-server-worker" \
|
|
|
|
--action="stop" \
|
|
|
|
--log_path="/var/log/$app/syncing-server-worker.log"
|
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
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
2020-12-27 23:18:55 +01:00
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2020-01-18 10:28:47 +01:00
|
|
|
fi
|
|
|
|
|
2021-03-06 21:39:49 +01:00
|
|
|
# If redis_db doesn't exist, create it
|
|
|
|
if [ -z "$redis_db" ]; then
|
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
|
|
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
# If port_api_gateway doesn't exist, create it
|
|
|
|
if [ -z "$port_api_gateway" ]; then
|
|
|
|
port_api_gateway=$(ynh_find_port --port=3000)
|
|
|
|
ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
|
2021-03-06 21:39:49 +01:00
|
|
|
fi
|
2021-07-08 11:50:04 +02:00
|
|
|
# If port_auth doesn't exist, create it
|
|
|
|
if [ -z "$port_auth" ]; then
|
2022-08-04 17:28:39 +02:00
|
|
|
port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
|
|
|
|
fi
|
|
|
|
# If port_auth_worker doesn't exist, create it
|
|
|
|
if [ -z "$port_auth_worker" ]; then
|
|
|
|
port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
|
|
|
|
ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
|
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
# If port_files doesn't exist, create it
|
|
|
|
if [ -z "$port_files" ]; then
|
|
|
|
port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
|
|
|
|
ynh_app_setting_set --app=$app --key=port_files --value=$port_files
|
|
|
|
fi
|
|
|
|
# If port_syncing_server doesn't exist, create it
|
|
|
|
if [ -z "$port_syncing_server" ]; then
|
|
|
|
port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
|
|
|
|
ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
# If port_syncing_server_worker doesn't exist, create it
|
|
|
|
if [ -z "$port_syncing_server_worker" ]; then
|
|
|
|
port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
|
|
|
|
ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
|
|
|
|
fi
|
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
|
|
|
|
# If jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$jwt_secret" ]; then
|
|
|
|
jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret
|
|
|
|
fi
|
|
|
|
# If legacy_jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$legacy_jwt_secret" ]; then
|
|
|
|
legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret
|
|
|
|
fi
|
|
|
|
# If auth_jwt_secret doesn't exist, create it
|
|
|
|
if [ -z "$auth_jwt_secret" ]; then
|
|
|
|
auth_jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret
|
|
|
|
fi
|
|
|
|
# If pseudo_key_params_key doesn't exist, create it
|
|
|
|
if [ -z "$pseudo_key_params_key" ]; then
|
|
|
|
pseudo_key_params_key=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key
|
|
|
|
fi
|
|
|
|
# If encryption_server_key doesn't exist, create it
|
|
|
|
if [ -z "$encryption_server_key" ]; then
|
|
|
|
encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required
|
|
|
|
ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key
|
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
# If valet_token_secret doesn't exist, create it
|
|
|
|
if [ -z "$valet_token_secret" ]; then
|
|
|
|
valet_token_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret
|
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
|
|
|
|
if [ -z "$diable_user_registration" ]; then
|
|
|
|
disable_user_registration=false
|
|
|
|
ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
|
|
|
|
fi
|
|
|
|
# If files_zise doesn't exist, create it
|
|
|
|
if [ -z "$files_size" ]; then
|
|
|
|
files_size=100
|
|
|
|
ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
|
|
|
|
fi
|
2021-07-11 14:10:21 +02:00
|
|
|
|
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
# Remove old Settings, Services, Files, Dependencies
|
|
|
|
# If final_path_www exist, delete it
|
|
|
|
final_path_www=$(ynh_app_setting_get --app=$app --key=final_path_www)
|
|
|
|
if [ -n ${final_path_www+x} ]; then
|
2022-08-01 21:46:14 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=final_path_www
|
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
# If final_path_extensions exist, delete it
|
|
|
|
final_path_extensions=$(ynh_app_setting_get --app=$app --key=final_path_extensions)
|
|
|
|
if [ -n ${final_path_extensions+x} ]; then
|
2022-08-01 21:46:14 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=final_path_extensions
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If permission help exists, delete it
|
|
|
|
if ynh_permission_exists --permission="help"
|
|
|
|
then
|
|
|
|
ynh_permission_delete --permission="help"
|
|
|
|
fi
|
|
|
|
|
2021-07-11 14:10:21 +02:00
|
|
|
# If old service exsits; remove it
|
2022-08-04 17:28:39 +02:00
|
|
|
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null
|
2021-07-14 21:25:17 +02:00
|
|
|
then
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_script_progression --message="Removing old service..." --weight=1
|
|
|
|
yunohost service remove "$app-syncing-server-js"
|
2021-07-11 17:36:53 +02:00
|
|
|
fi
|
2022-08-04 17:28:39 +02:00
|
|
|
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null
|
2021-07-08 11:50:04 +02:00
|
|
|
then
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_script_progression --message="Removing old service..." --weight=1
|
|
|
|
yunohost service remove "$app-syncing-server-js-worker"
|
2021-07-08 11:50:04 +02:00
|
|
|
fi
|
2021-07-11 14:10:21 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
|
2021-10-30 09:59:53 +02:00
|
|
|
# Remove unneeded data
|
2022-08-01 21:46:14 +02:00
|
|
|
if [ -e "/var/www/$app" ]; then
|
|
|
|
ynh_secure_remove --file="/var/www/$app"
|
|
|
|
fi
|
2021-10-30 09:59:53 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
# If datadir doesn't exist, create it
|
|
|
|
# CREATE DATA DIRECTORY
|
|
|
|
if [ -z "$datadir" ]; then
|
|
|
|
datadir=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
|
|
|
|
mkdir -p $datadir/uploads
|
|
|
|
|
|
|
|
chmod -R 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
chown -R $app:$app "$datadir"
|
|
|
|
fi
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
# CREATE DEDICATED USER
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-08-04 17:28:39 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
2020-01-18 10:28:47 +01:00
|
|
|
then
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2021-07-08 11:50:04 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_secure_remove --file="$final_path/live"
|
2021-07-08 11:50:04 +02:00
|
|
|
mkdir -p "$final_path/live"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
|
2022-08-08 01:37:39 +02:00
|
|
|
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$final_path/cron.sh"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:$app "$final_path"
|
2021-02-07 00:02:09 +01:00
|
|
|
fi
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2021-05-09 14:50:38 +02:00
|
|
|
ynh_add_nginx_config
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2021-11-26 20:51:16 +01:00
|
|
|
# Remove old nodejs version
|
|
|
|
if [[ "$nodejs_version_installed" < "$NODEJS_VERSION" && -n "$nodejs_version_installed" ]]
|
|
|
|
then
|
|
|
|
ynh_remove_nodejs
|
|
|
|
fi
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2021-07-08 11:50:04 +02:00
|
|
|
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"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
#=================================================
|
2021-08-29 00:17:52 +02:00
|
|
|
# ADD SWAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Adding swap..."
|
|
|
|
|
|
|
|
ynh_add_swap --size=$swap_needed
|
|
|
|
|
|
|
|
#=================================================
|
2020-12-20 14:22:36 +01:00
|
|
|
# MODIFY A CONFIG FILE
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_script_progression --message="Modify a config file..." --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"
|
2021-01-24 11:36:36 +01:00
|
|
|
|
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
|
|
|
#=================================================
|
2020-12-20 14:22:36 +01:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2021-05-01 21:48:58 +02:00
|
|
|
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_use_nodejs
|
2022-08-04 17:28:39 +02:00
|
|
|
pushd "$final_path/live"
|
|
|
|
#ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn install --pure-lockfile
|
|
|
|
#ynh_exec_warn_less ynh_exec_as $app env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" PATH=$ynh_node_load_PATH yarn build
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app PATH=$ynh_node_load_PATH yarn install --immutable
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app PATH=$ynh_node_load_PATH yarn build
|
|
|
|
popd
|
2020-12-20 14:22:36 +01:00
|
|
|
fi
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
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"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-12-20 14:22:36 +01:00
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_script_progression --message="Storing the config file checksum..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2020-12-20 14:22:36 +01:00
|
|
|
# Calculate and store the config file checksum into the app settings
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_store_file_checksum --file="$config_api_gateway"
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_store_file_checksum --file="$config_auth"
|
|
|
|
ynh_store_file_checksum --file="$config_auth_worker"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_store_file_checksum --file="$config_files"
|
|
|
|
ynh_store_file_checksum --file="$config_syncing_server"
|
|
|
|
ynh_store_file_checksum --file="$config_syncing_server_worker"
|
2020-12-20 14:22:36 +01:00
|
|
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2020-12-20 14:22:36 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
# SETUP LOGROTATE
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2020-12-27 23:18:55 +01:00
|
|
|
mkdir -p "/var/log/$app"
|
2021-07-08 11:50:04 +02:00
|
|
|
chown -R "$app": "/var/log/$app"
|
|
|
|
|
|
|
|
# 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"
|
2020-12-20 14:22:36 +01:00
|
|
|
|
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2020-12-20 14:22:36 +01:00
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1
|
2020-12-20 14:22:36 +01:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
|
2021-07-08 11:50:04 +02:00
|
|
|
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"
|
2022-08-04 17:28:39 +02:00
|
|
|
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"
|
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
|
|
|
#=================================================
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --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 \
|
2022-08-04 17:28:39 +02:00
|
|
|
--service_name="$app-api-gateway" \
|
2021-07-08 11:50:04 +02:00
|
|
|
--action="start" \
|
2022-08-04 17:28:39 +02:00
|
|
|
--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 \
|
|
|
|
--service_name="$app-auth" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth.log" \
|
2022-08-04 17:28:39 +02:00
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-auth-worker" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth-worker.log" \
|
2022-08-04 17:28:39 +02:00
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-08 11:50:04 +02:00
|
|
|
ynh_systemd_action \
|
2022-08-04 17:28:39 +02:00
|
|
|
--service_name="$app-files" \
|
2021-07-08 11:50:04 +02:00
|
|
|
--action="start" \
|
2022-08-04 17:28:39 +02:00
|
|
|
--log_path="/var/log/$app/files.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-syncing-server" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/syncing-server.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
|
|
|
ynh_systemd_action \
|
|
|
|
--service_name="$app-syncing-server-worker" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/syncing-server-worker.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2020-12-24 12:11:42 +01:00
|
|
|
|
2022-08-08 01:37:39 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP A CRON
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setup a cron..."
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/cron.env" --destination="__finalpath__/$app.env"
|
|
|
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
|
|
|
|
|
|
|
|
chown root: "/etc/cron.d/$app"
|
|
|
|
chmod 640 "/etc/cron.d/$app"
|
|
|
|
|
2020-12-20 14:22:36 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
2021-01-02 19:42:20 +01:00
|
|
|
ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1
|
2020-12-20 14:22:36 +01:00
|
|
|
|
|
|
|
# Create a dedicated fail2ban config
|
2021-05-09 14:50:38 +02:00
|
|
|
ynh_add_fail2ban_config --use_template
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-12-24 12:11:42 +01:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
2021-07-08 11:50:04 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_app_setting_set --app=$app --key=standalone --value="true"
|
|
|
|
|
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
|