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

110 lines
4.4 KiB
Text
Raw Normal View History

2024-02-21 16:50:15 +01:00
#!/bin/bash
source _common.sh
2024-06-12 14:33:45 +02:00
source /usr/share/yunohost/helpers
2024-02-21 16:50:15 +01:00
2024-04-22 14:37:16 +02:00
# UPGRADE_PACKAGE if only the YunoHost package has changed
# UPGRADE_APP if the upstream app version has changed
# DOWNGRADE
# UPGRADE_SAME
2024-02-21 16:50:15 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2024-04-22 14:37:16 +02:00
ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
# stop flohmarkt
2024-05-08 16:14:04 +02:00
flohmarkt_ynh_stop_service
2024-04-22 14:37:16 +02:00
# stop couchdb
2024-05-10 09:15:22 +02:00
flohmarkt_ynh_stop_couchdb
2024-04-22 14:37:16 +02:00
# Upgrade ynh4 → ynh5, change of paths and filenames
# https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr
# and follow-ups
2024-05-09 14:00:54 +02:00
if ynh_compare_current_package_version --comparison lt --version 0.0~ynh5 &&
( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
then
flohmarkt_ynh_upgrade_path_ynh5
fi
2024-04-22 14:37:16 +02:00
# upgrade couchdb
ynh_script_progression --message="Upgrading CouchDB..." --weight=50
2024-05-10 09:15:22 +02:00
flohmarkt_ynh_up_inst_couchdb
# stop couchdb
ynh_script_progression --message="Stop couchdb before updating configuration file..." --weight=1
flohmarkt_ynh_stop_couchdb
2024-04-22 14:37:16 +02:00
# upgrade couchdb config
ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
2024-05-10 09:15:22 +02:00
# start couchdb
2024-04-22 14:37:16 +02:00
ynh_script_progression --message="Starting couchdb..." --weight=1
2024-05-10 09:15:22 +02:00
flohmarkt_ynh_start_couchdb
2024-04-22 14:37:16 +02:00
# install upgrade for flohmarkt
ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
2024-04-22 14:37:16 +02:00
ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
2024-04-22 14:37:16 +02:00
# upgrade python environment / install new dependencies
flohmarkt_ynh_venv_requirements
2024-04-22 14:37:16 +02:00
# upgrade flohmarkt.conf
ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
2024-04-22 14:37:16 +02:00
ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
flohmarkt_ynh_initialize_couchdb
2024-04-22 14:37:16 +02:00
2024-05-08 16:14:04 +02:00
# set file permissions for install dir
flohmarkt_ynh_set_permission
2024-04-22 14:37:16 +02:00
# systemd service upgrade
ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
ynh_add_systemd_config --service=$flohmarkt_filename
2024-04-22 14:37:16 +02:00
# INTEGRATE SERVICE IN YUNOHOST
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
2024-02-21 16:50:15 +01:00
2024-04-22 14:37:16 +02:00
# upgrade logrotate
2024-02-21 16:50:15 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2024-04-22 14:37:16 +02:00
# upgrade nginx configuration
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
ynh_add_nginx_config
2024-02-21 16:50:15 +01:00
# UPGRADE FAIL2BAN
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
2024-02-21 16:50:15 +01:00
2024-04-22 14:37:16 +02:00
# start flohmarkt
ynh_script_progression --message="Starting flohmarkt..." --weight=3
2024-05-08 16:14:04 +02:00
flohmarkt_ynh_start_service
2024-02-21 16:50:15 +01:00
# check if admin_mail is already set and if not use a default
if ! [[ -v admin_mail ]] || [[ -z "${admin_mail}" ]]; then
ynh_print_warn --message="new setting admin_mail - trying to set a default"
# try to read admin email address from flohmarkt installation
admin_mail=$( flohmarkt_ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \
-H "Accept: application/json" -H "Content-Type: application/json" -s none \
-d '{"selector": { "role": "User", "admin": true }, "fields": ["email"]}' \
--location 'http://127.0.0.1:5984/flohmarkt/_find' \
| jq -r '.docs[0] .email'
)
if [[ -z "${admin_mail}" ]] || [[ "${admin_mail}" == 'null' ]]; then
# use yunohost admin group
admin_mail="admin@$(yunohost domain main-domain | cut -d' ' -f2)"
fi
ynh_print_warn --message="using ${admin_mail} for new setting admin_mail"
ynh_app_setting_set --app=$app --key=admin_mail --value="${admin_mail}"
fi
# upgrade urlwatch configuration
ynh_script_progression --message="Upgrade urlwatch configuration..." --weight=1
flohmarkt_ynh_urlwatch_cron
2024-02-21 16:50:15 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last