2024-02-12 15:13:34 +01:00
#!/bin/bash
# IMPORT GENERIC HELPERS
source _common.sh
source /usr/share/yunohost/helpers
# INITIALIZE AND STORE SETTINGS
2024-04-10 14:33:26 +02:00
# @@ todo do we need to store the password un-encrypted somewhere on the system?
2024-02-24 15:31:30 +01:00
ynh_app_setting_set --app=$app --key=password_couchdb_admin --value="$password_couchdb_admin"
2024-02-12 15:13:34 +01:00
# INSTALL COUCHDB
2024-04-10 14:33:26 +02:00
# @@ todo
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/9
# check if couchdb is already installed
# get port, admin_pw for already installed couchdb
# skip the installation steps below
2024-02-12 15:13:34 +01:00
ynh_script_progression --message="Installing CouchDB..." --weight=60
2024-04-10 14:33:26 +02:00
# @@ todo: why is 'cookie string' and 'admin password' below the same?
2024-02-12 15:13:34 +01:00
echo "\
couchdb couchdb/mode select standalone
couchdb couchdb/mode seen true
couchdb couchdb/bindaddress string 127.0.0.1
couchdb couchdb/bindaddress seen true
2024-02-24 15:31:30 +01:00
couchdb couchdb/cookie string $password_couchdb_admin
couchdb couchdb/adminpass password $password_couchdb_admin
2024-02-12 15:13:34 +01:00
couchdb couchdb/adminpass seen true
2024-02-24 15:31:30 +01:00
couchdb couchdb/adminpass_again password $password_couchdb_admin
2024-02-12 15:13:34 +01:00
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
ynh_install_extra_app_dependencies \
--repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
--key="https://couchdb.apache.org/repo/keys.asc" \
--package="couchdb"
2024-04-10 14:33:26 +02:00
# add couchdb configuration
2024-02-12 15:13:34 +01:00
ynh_script_progression --message="Adding a configuration file..." --weight=2
2024-04-10 14:33:26 +02:00
# customize couchdb config
2024-04-08 15:30:46 +02:00
ynh_add_config --template="../conf/couch_ynh.ini" --destination="/opt/couchdb/etc/local.d/couch_ynh.ini"
2024-02-12 15:13:34 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
2024-04-10 14:55:12 +02:00
# get flohmarkt
ynh_setup_source --dest-dir="$install_dir"
# setup python environment for flohmarkt
ynh_secure_remove "$install_dir/venv"
python3 -m venv --without-pip "$install_dir/venv"
# install python dependencies
(
set +o nounset
source "$install_dir/venv/bin/activate"
set -o nounset
set -x
ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $data_dir/venv/bin/pip3 install -r "$install_dir/flohmarkt/requirements.txt"
)
2024-04-10 14:33:26 +02:00
# @@ configure
2024-02-12 15:13:34 +01:00
# SETUP LOGROTATE
ynh_script_progression --message="Configuring log rotation..." --weight=2
# Use logrotate to manage application logfile(s)
# @@ how does this know where the logfiles are?
ynh_use_logrotate
2024-04-10 14:33:26 +02:00
# NGINX CONFIGURATION
ynh_script_progression --message="Configuring NGINX web server..." --weight=3
# Create a dedicated NGINX config
ynh_add_nginx_config
2024-02-12 15:13:34 +01:00
# INTEGRATE SERVICE IN YUNOHOST
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Open-source document-oriented NoSQL database" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port"
# SETUP FAIL2BAN
# no need for couchdb, because it will not listen externally
# ynh_script_progression --message="Configuring Fail2Ban..." --weight=3
#
# # Create a dedicated Fail2Ban config
# ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
2024-04-10 14:33:26 +02:00
# qed
2024-02-12 15:13:34 +01:00
ynh_script_progression --message="Installation of $app completed" --last