upgrade 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # 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. ynh_systemd_action --service_name=$app --action="stop"
  15. # stop couchdb
  16. ynh_systemd_action --service_name=couchdb --action="stop"
  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.00~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. echo "\
  28. couchdb couchdb/mode select standalone
  29. couchdb couchdb/mode seen true
  30. couchdb couchdb/bindaddress string 127.0.0.1
  31. couchdb couchdb/bindaddress seen true
  32. couchdb couchdb/cookie string $couchdb_magic_cookie
  33. couchdb couchdb/adminpass password $password_couchdb_admin
  34. couchdb couchdb/adminpass seen true
  35. couchdb couchdb/adminpass_again password $password_couchdb_admin
  36. couchdb couchdb/adminpass_again seen true" | debconf-set-selections
  37. DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
  38. ynh_install_extra_app_dependencies \
  39. --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
  40. --key="https://couchdb.apache.org/repo/keys.asc" \
  41. --package="couchdb"
  42. # upgrade couchdb config
  43. ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
  44. ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  45. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  46. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  47. # start couchdb to pick up changes
  48. ynh_script_progression --message="Starting couchdb..." --weight=1
  49. ynh_systemd_action --service_name=couchdb --action="start"
  50. systemctl status couchdb
  51. # install upgrade for flohmarkt
  52. ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
  53. ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
  54. ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
  55. # upgrade python environment / install new dependencies
  56. flohmarkt_ynh_venv_requirements
  57. # upgrade flohmarkt.conf
  58. ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
  59. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
  60. ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
  61. # run initialize_couchdb.py
  62. (
  63. set +o nounset
  64. source "$flohmarkt_venv_dir/bin/activate"
  65. set -o nounset
  66. cd "$flohmarkt_app_dir"
  67. # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
  68. # give it 45 seconds to finish and then fail
  69. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
  70. timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
  71. )
  72. # systemd service upgrade
  73. ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
  74. ynh_add_systemd_config --service=$flohmarkt_filename
  75. # INTEGRATE SERVICE IN YUNOHOST
  76. ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
  77. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  78. # upgrade logrotate
  79. ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
  80. # Use logrotate to manage app-specific logfile(s)
  81. ynh_use_logrotate --non-append
  82. # upgrade nginx configuration
  83. ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
  84. ynh_add_nginx_config
  85. # UPGRADE FAIL2BAN
  86. ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
  87. ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
  88. # start flohmarkt
  89. ynh_script_progression --message="Starting flohmarkt..." --weight=3
  90. ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" --timeout=30
  91. ynh_script_progression --message="Upgrade of $app completed" --last