upgrade 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. source _common.sh
  3. source /usr/share/yunohost/helpers
  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. ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
  10. # stop flohmarkt
  11. flohmarkt_ynh_stop_service
  12. # stop couchdb
  13. flohmarkt_ynh_stop_couchdb
  14. # Upgrade ynh4 → ynh5, change of paths and filenames
  15. # https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr
  16. # and follow-ups
  17. if ynh_compare_current_package_version --comparison lt --version 0.0~ynh5 &&
  18. ( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
  19. then
  20. flohmarkt_ynh_upgrade_path_ynh5
  21. fi
  22. # Upgrade from 0.2.0: remove requirements.txt which is replaced by pyproject.toml
  23. if ynh_compare_current_package_version --comparison lt --version 0.6.1~ynh1 &&
  24. ( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
  25. then
  26. ynh_secure_remove "${flohmarkt_app_dir}/requirements.txt"
  27. fi
  28. # upgrade couchdb
  29. ynh_script_progression --message="Upgrading CouchDB..." --weight=50
  30. flohmarkt_ynh_up_inst_couchdb
  31. # stop couchdb
  32. ynh_script_progression --message="Stop couchdb before updating configuration file..." --weight=1
  33. flohmarkt_ynh_stop_couchdb
  34. # upgrade couchdb config
  35. ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
  36. ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  37. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  38. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  39. # start couchdb
  40. ynh_script_progression --message="Starting couchdb..." --weight=1
  41. flohmarkt_ynh_start_couchdb
  42. # install upgrade for flohmarkt
  43. ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
  44. ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
  45. ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
  46. # upgrade python environment / install new dependencies
  47. flohmarkt_ynh_venv_upgrade
  48. flohmarkt_ynh_venv_requirements
  49. # upgrade flohmarkt.conf
  50. ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
  51. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
  52. ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
  53. flohmarkt_ynh_initialize_couchdb
  54. # set file permissions for install dir
  55. flohmarkt_ynh_set_permission
  56. # systemd service upgrade
  57. ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
  58. ynh_add_systemd_config --service=$flohmarkt_filename
  59. # INTEGRATE SERVICE IN YUNOHOST
  60. ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
  61. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  62. # upgrade logrotate
  63. ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
  64. # Use logrotate to manage app-specific logfile(s)
  65. ynh_use_logrotate --non-append
  66. # upgrade nginx configuration
  67. ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
  68. ynh_add_nginx_config
  69. # UPGRADE FAIL2BAN
  70. ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
  71. ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
  72. # start flohmarkt
  73. ynh_script_progression --message="Starting flohmarkt..." --weight=3
  74. flohmarkt_ynh_start_service
  75. # check if admin_mail is already set and if not use a default
  76. if ! [[ -v admin_mail ]] || [[ -z "${admin_mail}" ]]; then
  77. ynh_print_warn --message="new setting admin_mail - trying to set a default"
  78. # try to read admin email address from flohmarkt installation
  79. admin_mail=$( flohmarkt_ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \
  80. -H "Accept: application/json" -H "Content-Type: application/json" -s none \
  81. -d '{"selector": { "role": "User", "admin": true }, "fields": ["email"]}' \
  82. --location 'http://127.0.0.1:5984/flohmarkt/_find' \
  83. | jq -r '.docs[0] .email'
  84. )
  85. if [[ -z "${admin_mail}" ]] || [[ "${admin_mail}" == 'null' ]]; then
  86. # use yunohost admin group
  87. admin_mail="admin@$(yunohost domain main-domain | cut -d' ' -f2)"
  88. fi
  89. ynh_print_warn --message="using ${admin_mail} for new setting admin_mail"
  90. ynh_app_setting_set --app=$app --key=admin_mail --value="${admin_mail}"
  91. fi
  92. # upgrade urlwatch configuration
  93. ynh_script_progression --message="Upgrade urlwatch configuration..." --weight=1
  94. flohmarkt_ynh_urlwatch_cron
  95. ynh_script_progression --message="Upgrade of $app completed" --last