1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/fab-manager_ynh.git synced 2024-09-03 18:36:16 +02:00
fab-manager_ynh/scripts/upgrade

122 lines
4.6 KiB
Bash

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove "$app"
fi
ynh_remove_logrotate
ynh_secure_remove --file="/etc/supervisor/conf.d/$app.conf"
ynh_secure_remove --file="/var/log/supervisor/$app-app-stderr.log"
ynh_secure_remove --file="/var/log/supervisor/$app-app-stdout.log"
ynh_secure_remove --file="/var/log/supervisor/$app-worker-stderr.log"
ynh_secure_remove --file="/var/log/supervisor/$app-worker-stdout.log"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Updating NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
ynh_script_progression --message="Updating Ruby..." --weight=4
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
to_keep=(
# Basically inspired from the docker-compose.yml
.env config/database.yml config/auth_provider.yml public/packs public/uploads
invoices payment_schedules exports imports supporting_document_files plugins accounting
)
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="${to_keep[*]}"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="dot_env" --destination="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown "$app:$app" "$install_dir/.env"
ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml"
chmod 400 "$install_dir/config/database.yml"
chown "$app:$app" "$install_dir/config/database.yml"
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..." --weight=7
ynh_secure_remove --file="$install_dir/.cache"
ynh_secure_remove --file="$install_dir/node_modules"
ynh_secure_remove --file="$install_dir/tmp/cache"
fabmanager_build_ruby
fabmanager_build_ui
fabmanager_migrate_db
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-app" --template="fab-manager-app.service"
yunohost service add "$app-app" --description="$app app service"
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service"
yunohost service add "$app-worker" --description="$app worker service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last