1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flohmarkt_ynh.git synced 2024-09-03 18:36:30 +02:00
flohmarkt_ynh/scripts/install

133 lines
5.1 KiB
Text
Raw Normal View History

#!/bin/bash
# IMPORT GENERIC HELPERS
source _common.sh
source /usr/share/yunohost/helpers
2024-04-10 14:33:26 +02:00
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/9
# check if couchdb is already installed
2024-04-17 15:06:48 +02:00
if [[ -e /opt/couchdb ]] || pgrep epmd > /dev/null || pgrep beam.smp || dpkg-query -W couchdb > /dev/null 2>&1;
then
2024-04-17 15:10:30 +02:00
ynh_die --message="CouchDB already installed on this host - will not proceed."
2024-04-17 15:06:48 +02:00
exit 1
fi
2024-04-17 15:21:52 +02:00
# INITIALIZE AND STORE SETTINGS
# todo: do we need to store the password un-encrypted somewhere on the system?
# → there's no way to get the admin password later if sometimes in the future deleting
# the app will delete its specific database only (instead of the whole couchdb server as
# of now in the earliest versions of the integration).
ynh_app_setting_set --app=$app --key=password_couchdb_admin --value="$password_couchdb_admin"
2024-04-10 14:33:26 +02:00
# get port, admin_pw for already installed couchdb
# skip the installation steps below
ynh_script_progression --message="Installing CouchDB..." --weight=60
2024-04-17 14:55:10 +02:00
# A CouchDB node has an Erlang magic cookie value set at startup.
# This value must match for all nodes in the cluster. If they do not match,
# attempts to connect the node to the cluster will be rejected.
2024-04-18 14:54:50 +02:00
couchdb_magic_cookie=$(ynh_string_random --length=23 --filter='A-Za-z0-9_')
2024-04-17 20:01:14 +02:00
ynh_app_setting_set --app=$app --key=erlang_cookie --value="$couchdb_magic_cookie"
2024-04-17 14:55:10 +02: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-04-17 14:55:10 +02:00
couchdb couchdb/cookie string $couchdb_magic_cookie
2024-02-24 15:31:30 +01:00
couchdb couchdb/adminpass password $password_couchdb_admin
couchdb couchdb/adminpass seen true
2024-02-24 15:31:30 +01:00
couchdb couchdb/adminpass_again password $password_couchdb_admin
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
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-04-10 15:10:22 +02:00
# @@ todo need to create a couchdb user and set the files to be readable/executable by it
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
2024-04-11 19:53:18 +02:00
# INTEGRATE SERVICE IN YUNOHOST
# ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
# yunohost service add $app --description="war mal couchdb" --log="/var/log/$app/$app.log"
2024-04-10 14:55:12 +02:00
# get flohmarkt
2024-04-10 21:08:02 +02:00
ynh_setup_source --dest_dir="$install_dir/$app/"
2024-04-10 14:55:12 +02:00
# 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
2024-04-10 15:16:12 +02:00
$install_dir/venv/bin/python3 -m ensurepip
2024-04-10 21:08:02 +02:00
$install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
2024-04-10 14:55:12 +02:00
)
2024-04-10 14:33:26 +02:00
2024-04-11 15:00:40 +02:00
# JwtSecret
2024-04-18 14:54:50 +02:00
jwtsecret=$(ynh_string_random --length=344 --filter='a-zA-Z0-9/+')
2024-04-11 15:00:40 +02:00
password_couchdb_flohmarkt=$(ynh_string_random --length=31 --filter='A-Za-z0-9_+/;.,')
ynh_app_setting_set --app=$app --key=erlang_cookie --value="$password_couchdb_flohmarkt"
2024-04-11 19:53:18 +02:00
# generate flohmarkt.conf
2024-04-10 21:17:58 +02:00
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
2024-04-10 14:33:26 +02:00
2024-04-11 19:53:18 +02:00
# setup couchdb
(
set +o nounset
source "$install_dir/venv/bin/activate"
set -o nounset
cd "$install_dir/$app"
2024-04-17 16:37:22 +02:00
# initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
2024-04-17 20:00:10 +02:00
# give it 45 seconds to finish and then fail
2024-04-17 16:52:01 +02:00
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
2024-04-17 20:00:10 +02:00
timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
2024-04-11 19:53:18 +02: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-04-11 19:53:18 +02:00
# systemd.service
ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
# integrate into yunohost
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2024-04-18 14:43:23 +02:00
yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
2024-04-12 08:20:16 +02:00
# start service
ynh_systemd_action --service_name=$app --action="start"
# 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-11 19:53:18 +02:00
# @@ logrotation
ynh_script_progression --message="Installation of $app completed" --last
2024-04-11 19:53:18 +02:00
# qed