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

256 lines
8 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
2020-12-13 21:40:17 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
2016-09-09 11:07:28 +02:00
2020-12-13 21:40:17 +01:00
app=$YNH_APP_INSTANCE_NAME
2020-04-11 14:18:16 +02:00
2020-12-13 21:40:17 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
salt=$(ynh_app_setting_get --app=$app --key=salt)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# 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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Ensuring downward compatibility..."
2018-04-15 00:27:48 +02:00
# Previous versions did not set the DB name as a setting, so we need to set it now (will be used on
# remove).
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
db_user=$db_name
fi
2018-04-15 00:27:48 +02:00
# If final_path doesn't exist, create it
2020-12-13 21:40:17 +01:00
if [ -z "$final_path" ]
then
2018-04-15 00:27:48 +02:00
final_path=/var/www/$app
2019-02-27 22:56:36 +01:00
ynh_app_setting_set "$app" final_path "$final_path"
2018-04-15 00:27:48 +02:00
fi
2020-12-13 21:40:17 +01:00
if [ -d "/home/ynh$app" ]
then
2018-07-30 22:53:00 +02:00
mv "/home/ynh$app/data" "$final_path/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
2020-12-13 21:40:17 +01:00
if [ -z "$salt" ]
then
2019-02-27 22:56:36 +01:00
salt=$(ynh_string_random 40)
ynh_app_setting_set "$app" salt "$salt"
fi
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
# CREATE DEDICATED USER
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Upgrading source files..."
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
ynh_setup_source --dest_dir="$final_path"
2020-12-13 21:40:17 +01:00
2022-02-09 00:51:15 +01:00
if [ -z "$final_path/data" ]
then
mkdir "$final_path/data"
fi
2020-12-13 21:40:17 +01:00
fi
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2018-04-15 00:27:48 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-13 21:40:17 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2018-04-15 00:27:48 +02:00
2020-12-13 21:40:17 +01:00
# Create a dedicated NGINX config
2018-04-15 00:27:48 +02:00
ynh_add_nginx_config
#=================================================
2022-02-09 00:51:15 +01:00
# UPGRADE DEPENDENCIES
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# Now that postgresql is installed, check the db exists and the user is set up
if [ -z "$db_pwd" ]
then
ynh_script_progression --message="Setting up database"
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
fi
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Installing woob..."
2020-12-13 21:40:17 +01:00
2020-04-11 14:18:16 +02:00
ynh_secure_remove --file="${final_path}/venv"
2019-11-24 15:28:40 +01:00
virtualenv --python=python3 --system-site-packages "${final_path}/venv"
2018-04-15 00:27:48 +02:00
(
set +o nounset
source "${final_path}/venv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install woob html2text simplejson BeautifulSoup4 PyExecJS typing-extensions pdfminer.six --ignore-installed
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Installing app..."
2020-12-13 21:40:17 +01:00
2018-04-15 00:27:48 +02:00
ynh_use_nodejs
(
cd "$final_path"
2020-12-13 21:40:17 +01:00
chown -R $app: "$final_path"
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.
ynh_secure_remove --file="$final_path/node_modules"
ynh_exec_warn_less $ynh_npm install --production --unsafe-perm
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Updating a configuration file..."
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
ynh_add_config --template="../conf/config.ini" --destination="$final_path/config.ini"
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
chmod 400 "$final_path/config.ini"
chown $app:$app "$final_path/config.ini"
2018-04-15 00:27:48 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2022-02-09 00:51:15 +01:00
ynh_script_progression --message="Upgrading systemd configuration..."
2018-04-15 00:27:48 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
2022-02-09 00:51:15 +01:00
# SETUP LOGROTATE
2018-04-15 00:27:48 +02:00
#=================================================
2022-02-09 00:51:15 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2018-04-15 00:27:48 +02:00
2022-02-09 00:51:15 +01:00
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
2018-08-08 23:28:10 +02:00
2022-02-09 00:51:15 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2019-02-27 13:39:34 +01:00
2022-02-09 00:51:15 +01:00
yunohost service add $app --log="/var/log/$app/$app.log"
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-02-09 00:51:15 +01:00
ynh_script_progression --message="Starting a systemd service..."
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
2018-04-15 00:27:48 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-12-13 21:40:17 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2016-09-09 11:07:28 +02:00
2020-12-13 21:40:17 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# SEND README TO ADMIN
#=================================================
message="
Kresus was successfully updated!
Domain: $domain
Path : $path_url
Config: $final_path/config.ini
Note about config.ini: this package will regenerate the config file on upgrade.
If you changed it manually and upgrade Kresus, you'll find a backup in $final_path.
Are you facing an issue, want to improve this app or say thank you?
Please open a new issue in this project: https://github.com/YunoHost-Apps/kresus_ynh
"
ynh_send_readme_to_admin "$message"
2020-05-03 14:03:03 +02:00
2020-12-13 21:40:17 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2022-02-09 00:51:15 +01:00
ynh_script_progression --message="Upgrade of $app completed"