upgrade 4.6 KB

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