2021-03-29 16:24:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
#ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
#
|
|
|
|
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
|
|
|
|
# of what you may want to do in some cases (e.g. a setting was not defined on
|
|
|
|
# some legacy installs and you therefore want to initiaze stuff during upgrade)
|
|
|
|
#
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
#if [ -z "$db_name" ]; then
|
|
|
|
# db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
#fi
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
# If install_dir doesn't exist, create it
|
|
|
|
#if [ -z "$install_dir" ]; then
|
|
|
|
# install_dir=/var/www/$app
|
|
|
|
# ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
|
|
|
#fi
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-02-26 00:48:16 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2021-03-31 19:55:10 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2022-07-03 23:32:02 +02:00
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...)
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=10
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2022-07-03 23:32:02 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --keep="config.ini"
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
grep -v electron "$install_dir/package.json" > "$install_dir/server-package.json"
|
|
|
|
mv "$install_dir/server-package.json" "$install_dir/package.json"
|
2022-07-03 23:32:02 +02:00
|
|
|
fi
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
# $install_dir will automatically be initialized with some decent
|
|
|
|
# permission by default ... however, you may need to recursively reapply
|
|
|
|
# ownership to all files such as after the ynh_setup_source step
|
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# UPGRADE NODEJS
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_script_progression --message="Upgrading nodejs..." --weight=5
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-03-31 19:55:10 +02:00
|
|
|
# INSTALL NODE PACKAGES
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2022-07-03 23:32:02 +02:00
|
|
|
ynh_script_progression --message="Installing Node.js packages ..." --weight=45
|
2021-03-31 19:55:10 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
pushd "$install_dir"
|
2022-07-03 23:32:02 +02:00
|
|
|
ynh_use_nodejs
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install ./
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm rebuild ./
|
2022-07-03 23:32:02 +02:00
|
|
|
popd
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2022-07-03 23:32:02 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
# This should be a literal copypasta of what happened in the install's "System configuration" section
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_add_nginx_config
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2022-07-03 23:32:02 +02:00
|
|
|
ynh_add_systemd_config
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
yunohost service add $app --description="Trilium Notes app" --log="systemd"
|
|
|
|
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...)
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2023-02-24 20:00:57 +01:00
|
|
|
# UPDATE A CONFIG FILE
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
2023-02-26 00:48:16 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2023-02-24 20:00:57 +01:00
|
|
|
|
|
|
|
ynh_add_config --template="../conf/config.ini" --destination="$install_dir/config.ini"
|
|
|
|
ln -sf $install_dir/config.ini $data_dir/config.ini
|
|
|
|
|
|
|
|
chmod 400 "$install_dir/config.ini"
|
|
|
|
chown $app:$app "$install_dir/config.ini"
|
|
|
|
|
2021-03-29 16:24:15 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-02-26 00:48:16 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2021-03-29 16:24:15 +02:00
|
|
|
|
2022-07-03 23:32:02 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Listening on port"
|
2021-03-29 16:24:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-24 20:00:57 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|