upgrade 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. source /usr/share/yunohost/helpers
  3. source _common.sh
  4. # UPGRADE_PACKAGE if only the YunoHost package has changed
  5. # UPGRADE_APP if the upstream app version has changed
  6. # DOWNGRADE
  7. # UPGRADE_SAME
  8. upgrade_type=$(ynh_check_app_version_changed)
  9. # show variables - used from installed or from to be upgraded version?
  10. # variables of the new upgrade version are used
  11. # env
  12. ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
  13. # stop flohmarkt
  14. flohmarkt_ynh_stop_service
  15. # stop couchdb
  16. flohmarkt_ynh_stop_couchdb
  17. # Upgrade ynh4 → ynh5, change of paths and filenames
  18. # https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr
  19. # and follow-ups
  20. if ynh_compare_current_package_version --comparison lt --version 0.0~ynh5 &&
  21. ( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
  22. then
  23. flohmarkt_ynh_upgrade_path_ynh5
  24. fi
  25. # upgrade couchdb
  26. ynh_script_progression --message="Upgrading CouchDB..." --weight=50
  27. flohmarkt_ynh_up_inst_couchdb
  28. # stop couchdb
  29. ynh_script_progression --message="Stop couchdb before updating configuration file..." --weight=1
  30. flohmarkt_ynh_stop_couchdb
  31. # upgrade couchdb config
  32. ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
  33. ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  34. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  35. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  36. # start couchdb
  37. ynh_script_progression --message="Starting couchdb..." --weight=1
  38. flohmarkt_ynh_start_couchdb
  39. # install upgrade for flohmarkt
  40. ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
  41. ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
  42. ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
  43. # upgrade python environment / install new dependencies
  44. flohmarkt_ynh_venv_requirements
  45. # upgrade flohmarkt.conf
  46. ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
  47. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
  48. ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
  49. # run initialize_couchdb.py
  50. (
  51. set +o nounset
  52. source "$flohmarkt_venv_dir/bin/activate"
  53. set -o nounset
  54. cd "$flohmarkt_app_dir"
  55. # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
  56. # give it 45 seconds to finish and then fail
  57. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
  58. timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
  59. )
  60. # set file permissions for install dir
  61. flohmarkt_ynh_set_permission
  62. # systemd service upgrade
  63. ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
  64. ynh_add_systemd_config --service=$flohmarkt_filename
  65. # INTEGRATE SERVICE IN YUNOHOST
  66. ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
  67. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  68. # upgrade logrotate
  69. ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
  70. # Use logrotate to manage app-specific logfile(s)
  71. ynh_use_logrotate --non-append
  72. # upgrade nginx configuration
  73. ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
  74. ynh_add_nginx_config
  75. # UPGRADE FAIL2BAN
  76. ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
  77. ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
  78. # start flohmarkt
  79. ynh_script_progression --message="Starting flohmarkt..." --weight=3
  80. flohmarkt_ynh_start_service
  81. ynh_script_progression --message="Upgrade of $app completed" --last