mirror of
https://github.com/YunoHost-Apps/snweb_ynh.git
synced 2024-09-03 20:26:22 +02:00
100 lines
4.2 KiB
Bash
Executable file
100 lines
4.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
if [ -z "${snserver_domain:-}" ]; then
|
|
snserver_domain="api.standardnotes.com"
|
|
ynh_app_setting_set --app="$app" --key=snserver_domain --value="$snserver_domain"
|
|
fi
|
|
|
|
if ynh_compare_current_package_version --comparison lt --version 3.66.0~ynh1; then
|
|
# Remove old service
|
|
ynh_script_progression --message="Removing $app service..." --weight=1
|
|
yunohost service remove "$app"
|
|
ynh_remove_systemd_config --service="$app"
|
|
|
|
# Remove unneeded ruby
|
|
ynh_remove_ruby
|
|
ynh_secure_remove --file="$install_dir/.bundle"
|
|
ynh_secure_remove --file="$install_dir/.ruby-version"
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL NODEJS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NodeJS..." --weight=30
|
|
|
|
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..." --weight=17
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1
|
|
|
|
# Set permissions to app files
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
#=================================================
|
|
# BUILDING
|
|
#=================================================
|
|
ynh_script_progression --message="Building... ( This may take a while... )" --weight=100 #131
|
|
|
|
pushd "$install_dir/live"
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn install --immutable
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn build:web
|
|
popd
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
#=================================================
|
|
# Modify Config
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring..." --weight=1
|
|
|
|
# If $path is used modify .js file for a working app on a subpath
|
|
cp "$install_dir/live/packages/web/dist/app.js" "$install_dir/live/packages/web/dist/app.js.orginal"
|
|
if [ "$path" != "/" ]; then
|
|
ynh_replace_string --match_string="/components/" --replace_string="$path/components/" --target_file="$install_dir/live/packages/web/dist/app.js"
|
|
fi
|
|
|
|
# Modify Config
|
|
index_file="$install_dir/live/packages/web/dist/index.html"
|
|
ynh_replace_string --match_string="\(defaultSyncServer = \).*" --replace_string="\1\"https://$snserver_domain\"" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(defaultFilesHost = \).*" --replace_string="\1\"\"" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(enabledUnfinishedFeatures = \).*" --replace_string="\1false" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(websocketUrl = \).*" --replace_string="\1\"\"" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(purchaseUrl = \).*" --replace_string="\1\"\"" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(plansUrl = \).*" --replace_string="\1\"\"" --target_file="$index_file"
|
|
ynh_replace_string --match_string="\(dashboardUrl =\).*" --replace_string="\1\"\"" --target_file="$index_file"
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|