install 4.4 KB

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