install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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=$(openssl rand 32 | base32 -w 0 | head -c-4)
  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. # add couchdb configuration
  42. ynh_script_progression --message="Adding a configuration file..." --weight=2
  43. # customize couchdb config
  44. ynh_add_config --template="../conf/couch_ynh.ini" --destination="/opt/couchdb/etc/local.d/couch_ynh.ini"
  45. # @@ todo need to create a couchdb user and set the files to be readable/executable by it
  46. chmod 750 "$install_dir"
  47. chmod -R o-rwx "$install_dir"
  48. chown -R "$app:$app" "$install_dir"
  49. # INTEGRATE SERVICE IN YUNOHOST
  50. # ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  51. # yunohost service add $app --description="war mal couchdb" --log="/var/log/$app/$app.log"
  52. # get flohmarkt
  53. ynh_setup_source --dest_dir="$install_dir/$app/"
  54. # setup python environment for flohmarkt
  55. ynh_secure_remove "$install_dir/venv"
  56. python3 -m venv --without-pip "$install_dir/venv"
  57. # install python dependencies
  58. (
  59. set +o nounset
  60. source "$install_dir/venv/bin/activate"
  61. set -o nounset
  62. set -x
  63. $install_dir/venv/bin/python3 -m ensurepip
  64. $install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
  65. )
  66. # JwtSecret
  67. jwtsecret=$(openssl rand 256 | base64 -w 0)
  68. # generate flohmarkt.conf
  69. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
  70. # setup couchdb
  71. (
  72. set +o nounset
  73. source "$install_dir/venv/bin/activate"
  74. set -o nounset
  75. cd "$install_dir/$app"
  76. # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
  77. # give it 45 seconds to finish and then fail
  78. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
  79. timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
  80. )
  81. # SETUP LOGROTATE
  82. ynh_script_progression --message="Configuring log rotation..." --weight=2
  83. # Use logrotate to manage application logfile(s)
  84. # @@ how does this know where the logfiles are?
  85. ynh_use_logrotate
  86. # NGINX CONFIGURATION
  87. ynh_script_progression --message="Configuring NGINX web server..." --weight=3
  88. # Create a dedicated NGINX config
  89. ynh_add_nginx_config
  90. # systemd.service
  91. ynh_script_progression --message="Configuring a systemd service..." --weight=1
  92. # Create a dedicated systemd config
  93. ynh_add_systemd_config
  94. # integrate into yunohost
  95. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  96. yunohost service add $app --description="A self-hosted, single-user, ActivityPub powered microblog." --log="/var/log/$app/$app.log"
  97. # start service
  98. ynh_systemd_action --service_name=$app --action="start"
  99. # SETUP FAIL2BAN
  100. # no need for couchdb, because it will not listen externally
  101. # ynh_script_progression --message="Configuring Fail2Ban..." --weight=3
  102. #
  103. # # Create a dedicated Fail2Ban config
  104. # ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
  105. # @@ logrotation
  106. ynh_script_progression --message="Installation of $app completed" --last
  107. # qed