2024-02-21 16:50:15 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
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-05-08 11:18:05 +02:00
|
|
|
# show variables - used from installed or from to be upgraded version?
|
|
|
|
# variables of the new upgrade version are used
|
|
|
|
# env
|
|
|
|
|
2024-04-22 14:37:16 +02:00
|
|
|
ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
|
|
|
|
# stop flohmarkt
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
|
|
|
# stop couchdb
|
|
|
|
ynh_systemd_action --service_name=couchdb --action="stop"
|
|
|
|
|
2024-05-06 07:47:13 +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-08 11:18:05 +02:00
|
|
|
if ynh_compare_current_package_version --comparison lt --version 0.00~ynh5 &&
|
|
|
|
( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
|
2024-05-06 07:47:13 +02:00
|
|
|
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
|
|
|
|
echo "\
|
|
|
|
couchdb couchdb/mode select standalone
|
|
|
|
couchdb couchdb/mode seen true
|
|
|
|
couchdb couchdb/bindaddress string 127.0.0.1
|
|
|
|
couchdb couchdb/bindaddress seen true
|
2024-04-22 15:02:30 +02:00
|
|
|
couchdb couchdb/cookie string $couchdb_magic_cookie
|
|
|
|
couchdb couchdb/adminpass password $password_couchdb_admin
|
2024-04-22 14:37:16 +02:00
|
|
|
couchdb couchdb/adminpass seen true
|
2024-04-22 15:02:30 +02:00
|
|
|
couchdb couchdb/adminpass_again password $password_couchdb_admin
|
2024-04-22 14:37:16 +02:00
|
|
|
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
|
|
|
|
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
|
|
|
|
ynh_install_extra_app_dependencies \
|
|
|
|
--repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
|
|
|
|
--key="https://couchdb.apache.org/repo/keys.asc" \
|
|
|
|
--package="couchdb"
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# start couchdb to pick up changes
|
|
|
|
ynh_script_progression --message="Starting couchdb..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=couchdb --action="start"
|
|
|
|
systemctl status couchdb
|
|
|
|
|
|
|
|
# install upgrade for flohmarkt
|
|
|
|
ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
|
2024-05-06 07:47:13 +02:00
|
|
|
ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
|
2024-04-22 14:37:16 +02:00
|
|
|
|
2024-05-06 07:47:13 +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
|
2024-05-08 11:18:05 +02:00
|
|
|
flohmarkt_ynh_venv_requirements
|
2024-04-22 14:37:16 +02:00
|
|
|
|
|
|
|
# upgrade flohmarkt.conf
|
|
|
|
ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
|
2024-05-06 07:47:13 +02:00
|
|
|
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
|
|
|
|
# run initialize_couchdb.py
|
|
|
|
(
|
|
|
|
set +o nounset
|
2024-04-30 14:12:49 +02:00
|
|
|
source "$flohmarkt_venv_dir/bin/activate"
|
2024-04-22 14:37:16 +02:00
|
|
|
set -o nounset
|
2024-05-06 07:47:13 +02:00
|
|
|
cd "$flohmarkt_app_dir"
|
2024-04-22 14:37:16 +02:00
|
|
|
# initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
|
|
|
|
# give it 45 seconds to finish and then fail
|
|
|
|
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
|
|
|
|
timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
|
|
|
|
)
|
|
|
|
|
|
|
|
# systemd service upgrade
|
|
|
|
ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
|
2024-05-06 07:47:13 +02:00
|
|
|
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
|
2024-05-06 07:47:13 +02:00
|
|
|
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
|
2024-04-27 14:04:21 +02:00
|
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
|
2024-05-06 07:47:13 +02:00
|
|
|
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 11:18:05 +02:00
|
|
|
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" --timeout=30
|
2024-02-21 16:50:15 +01:00
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|