1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kresus_ynh.git synced 2024-09-03 19:36:10 +02:00
kresus_ynh/scripts/upgrade

153 lines
5.5 KiB
Text
Raw Normal View History

2016-09-09 11:07:28 +02:00
#!/bin/bash
2018-04-14 22:02:50 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2022-02-09 00:51:15 +01:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2022-02-09 00:51:15 +01:00
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped"
2018-04-15 00:27:48 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2018-04-15 00:27:48 +02:00
2023-05-22 23:31:46 +02:00
if [ -d "/home/ynh$app" ]; then
mv "/home/ynh$app/data" "$install_dir/data"
2020-04-11 14:18:16 +02:00
ynh_secure_remove --file="/home/ynh$app"
2018-07-30 22:53:00 +02:00
fi
2023-05-22 23:31:46 +02:00
if [ -z "${salt:-}" ]; then
2019-02-27 22:56:36 +01:00
salt=$(ynh_string_random 40)
2023-05-22 23:31:46 +02:00
ynh_app_setting_set --app=$app --key=salt --value=$salt
2019-02-27 22:56:36 +01:00
fi
2023-05-22 23:31:46 +02:00
usermod -d $install_dir $app
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
2020-12-13 21:40:17 +01:00
then
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2020-12-13 21:40:17 +01:00
2022-02-09 00:51:15 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2023-05-22 23:31:46 +02:00
ynh_setup_source --dest_dir="$install_dir" --keep="config.ini"
2020-12-13 21:40:17 +01:00
fi
2018-04-15 00:27:48 +02:00
2023-05-22 23:31:46 +02:00
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2022-02-09 00:51:15 +01:00
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
# UPGRADE DEPENDENCIES
2018-04-15 00:27:48 +02:00
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2018-04-15 00:27:48 +02:00
2022-06-15 01:48:45 +02:00
#=================================================
2023-05-22 23:31:46 +02:00
# REAPPLY SYSTEM CONFIGURATIONS
2022-06-15 01:48:45 +02:00
#=================================================
2023-05-22 23:31:46 +02:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2022-06-15 01:48:45 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2023-05-22 23:31:46 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
mkdir -p "/var/log/$app/"
touch "/var/log/$app/$app.log"
chown -R $app:$app "/var/log/$app/"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
yunohost service add $app --description="Personal finance manager" --log="/var/log/$app/$app.log"
2018-04-15 00:27:48 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
2022-02-09 00:51:15 +01:00
# INSTALL WOOB WITH PIP
2018-04-15 00:27:48 +02:00
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Installing woob..." --weight=1
2020-12-13 21:40:17 +01:00
2022-10-03 08:37:22 +02:00
locale-gen C.UTF-8
update-locale C.UTF-8
2023-05-22 23:31:46 +02:00
ynh_secure_remove --file="${install_dir}/venv"
ynh_exec_as $app virtualenv --python=python3 --system-site-packages "${install_dir}/venv"
2018-04-15 00:27:48 +02:00
(
set +o nounset
2023-05-22 23:31:46 +02:00
source "${install_dir}/venv/bin/activate"
2018-04-15 00:27:48 +02:00
set -o nounset
2023-05-22 23:31:46 +02:00
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$install_dir"/.rustup CARGO_HOME="$install_dir"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y --default-toolchain=stable --profile=minimal'
export PATH="$install_dir/.cargo/bin:$PATH"
2022-10-03 08:37:22 +02:00
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade pip
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade setuptools
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install woob simplejson BeautifulSoup4 PyExecJS typing-extensions pdfminer.six Pillow --ignore-installed
2023-05-22 23:31:46 +02:00
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cache"
ynh_secure_remove --file="$install_dir/.local"
2018-04-15 00:27:48 +02:00
)
#=================================================
2022-02-09 00:51:15 +01:00
# INSTALL KRESUS WITH NPM
2018-04-15 00:27:48 +02:00
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Installing app..." --weight=1
2020-12-13 21:40:17 +01:00
2023-05-22 23:31:46 +02:00
pushd $install_dir
ynh_use_nodejs
2020-04-11 14:18:16 +02:00
# In case of nodejs upgrade, remove the current node_modules to make sure there are no errors
# linked to modules compiled for the previous version.
2023-05-22 23:31:46 +02:00
ynh_secure_remove --file="$install_dir/node_modules"
2020-04-11 14:18:16 +02:00
2023-05-22 23:31:46 +02:00
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production
2022-11-03 14:36:03 +01:00
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production
2022-10-03 08:37:22 +02:00
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all
2023-05-22 23:31:46 +02:00
ynh_secure_remove --file="$install_dir/.cache"
ynh_secure_remove --file="$install_dir/.yarn"
popd
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
# UPDATE A CONFIG FILE
2018-04-15 00:27:48 +02:00
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Updating a configuration file..." --weight=1
2018-04-15 00:27:48 +02:00
2023-05-22 23:31:46 +02:00
ynh_add_config --template="../conf/config.ini" --destination="$install_dir/config.ini"
2019-02-27 13:39:34 +01:00
2023-05-22 23:31:46 +02:00
chmod 400 "$install_dir/config.ini"
chown $app:$app "$install_dir/config.ini"
2018-04-15 00:27:48 +02:00
2020-12-13 21:40:17 +01:00
#=================================================
2022-02-09 00:51:15 +01:00
# START SYSTEMD SERVICE
2020-12-13 21:40:17 +01:00
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2020-12-13 21:40:17 +01:00
2022-02-09 00:51:15 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Server is ready"
2020-12-13 21:40:17 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2022-10-03 08:37:22 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last