install 4.8 KB

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