install 4.2 KB

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