install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. # IMPORT GENERIC HELPERS
  3. source _common.sh
  4. source /usr/share/yunohost/helpers
  5. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/9
  6. # check if couchdb is already installed
  7. if [[ -e /opt/couchdb ]] || pgrep epmd > /dev/null || pgrep beam.smp || dpkg-query -W couchdb > /dev/null 2>&1;
  8. then
  9. ynh_die --message="CouchDB already installed on this host - will not proceed."
  10. exit 1
  11. fi
  12. # INITIALIZE AND STORE SETTINGS
  13. # todo: do we need to store the password un-encrypted somewhere on the system?
  14. # → there's no way to get the admin password later if sometimes in the future deleting
  15. # the app will delete its specific database only (instead of the whole couchdb server as
  16. # of now in the earliest versions of the integration).
  17. ynh_app_setting_set --app=$app --key=password_couchdb_admin --value="$password_couchdb_admin"
  18. # get port, admin_pw for already installed couchdb
  19. # skip the installation steps below
  20. ynh_script_progression --message="Installing CouchDB..." --weight=60
  21. # A CouchDB node has an Erlang magic cookie value set at startup.
  22. # This value must match for all nodes in the cluster. If they do not match,
  23. # attempts to connect the node to the cluster will be rejected.
  24. couchdb_magic_cookie=$(ynh_string_random --length=23 --filter='A-Za-z0-9_')
  25. ynh_app_setting_set --app=$app --key=erlang_cookie --value="$couchdb_magic_cookie"
  26. echo "\
  27. couchdb couchdb/mode select standalone
  28. couchdb couchdb/mode seen true
  29. couchdb couchdb/bindaddress string 127.0.0.1
  30. couchdb couchdb/bindaddress seen true
  31. couchdb couchdb/cookie string $couchdb_magic_cookie
  32. couchdb couchdb/adminpass password $password_couchdb_admin
  33. couchdb couchdb/adminpass seen true
  34. couchdb couchdb/adminpass_again password $password_couchdb_admin
  35. couchdb couchdb/adminpass_again seen true" | debconf-set-selections
  36. DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
  37. # ynh_install_extra_app_dependencies \
  38. # --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
  39. # --key="https://couchdb.apache.org/repo/keys.asc" \
  40. # --package="couchdb"
  41. #
  42. # replaced by:
  43. ynh_package_install couchdb
  44. # add couchdb configuration
  45. ynh_script_progression --message="Adding a configuration file..." --weight=2
  46. # customize couchdb config
  47. ynh_add_config --template="../conf/couch_ynh.ini" --destination="/opt/couchdb/etc/local.d/couch_ynh.ini"
  48. # @@ todo need to create a couchdb user and set the files to be readable/executable by it
  49. chmod 750 "$install_dir"
  50. chmod -R o-rwx "$install_dir"
  51. chown -R "$app:$app" "$install_dir"
  52. # INTEGRATE SERVICE IN YUNOHOST
  53. # ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  54. # yunohost service add $app --description="war mal couchdb" --log="/var/log/$app/$app.log"
  55. # get flohmarkt
  56. ynh_setup_source --dest_dir="$install_dir/$app/"
  57. # setup python environment for flohmarkt
  58. ynh_secure_remove "$install_dir/venv"
  59. python3 -m venv --without-pip "$install_dir/venv"
  60. # install python dependencies
  61. (
  62. set +o nounset
  63. source "$install_dir/venv/bin/activate"
  64. set -o nounset
  65. set -x
  66. $install_dir/venv/bin/python3 -m ensurepip
  67. $install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
  68. )
  69. # JwtSecret
  70. jwtsecret=$(ynh_string_random --length=344 --filter='a-zA-Z0-9/+')
  71. # generate flohmarkt.conf
  72. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
  73. # setup couchdb
  74. (
  75. set +o nounset
  76. source "$install_dir/venv/bin/activate"
  77. set -o nounset
  78. cd "$install_dir/$app"
  79. # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
  80. # give it 45 seconds to finish and then fail
  81. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
  82. timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
  83. )
  84. # SETUP LOGROTATE
  85. ynh_script_progression --message="Configuring log rotation..." --weight=2
  86. # Use logrotate to manage application logfile(s)
  87. # @@ how does this know where the logfiles are?
  88. ynh_use_logrotate
  89. # NGINX CONFIGURATION
  90. ynh_script_progression --message="Configuring NGINX web server..." --weight=3
  91. # Create a dedicated NGINX config
  92. ynh_add_nginx_config
  93. # systemd.service
  94. ynh_script_progression --message="Configuring a systemd service..." --weight=1
  95. # Create a dedicated systemd config
  96. ynh_add_systemd_config
  97. # integrate into yunohost
  98. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  99. yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
  100. # start service
  101. ynh_systemd_action --service_name=$app --action="start"
  102. # SETUP FAIL2BAN
  103. # no need for couchdb, because it will not listen externally
  104. # ynh_script_progression --message="Configuring Fail2Ban..." --weight=3
  105. #
  106. # # Create a dedicated Fail2Ban config
  107. # ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
  108. # @@ logrotation
  109. ynh_script_progression --message="Installation of $app completed" --last
  110. # qed