install 4.0 KB

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