1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00
weblate_ynh/scripts/install

199 lines
7.1 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-05-30 20:51:22 +02:00
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2022-03-04 08:23:50 +01:00
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
key=$(ynh_string_random --length=50)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2024-01-17 19:12:51 +01:00
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge
ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2022-03-04 08:23:50 +01:00
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
2024-01-17 19:48:00 +01:00
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
2022-03-04 08:23:50 +01:00
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
2024-01-17 14:07:41 +01:00
mkdir -p "$install_dir/avatar-cache"
mkdir -p "$install_dir/data"
2024-01-17 14:07:41 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-06-28 18:24:51 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2019-05-30 20:51:22 +02:00
2022-03-04 08:23:50 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
2022-03-04 08:23:50 +01:00
# SPECIFIC SETUP
2022-07-13 02:11:01 +02:00
#=================================================
# INSTALL XXHASH
#=================================================
ynh_script_progression --message="Installing xxHash..."
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
pushd $tempdir
make
make install
popd
ynh_secure_remove --file="$tempdir"
2017-10-04 10:46:26 +02:00
#=================================================
2020-10-28 12:02:15 +01:00
# CONFIGURE HUB
2017-10-04 10:46:26 +02:00
#=================================================
2022-08-11 20:43:28 +02:00
if [ $used_forge = "GitHub" ] ; then
2022-08-11 20:50:47 +02:00
ynh_script_progression --message="Configure hub..." --weight=1
2024-01-17 14:07:41 +01:00
mkdir "$install_dir/.config/"
ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub"
2024-01-17 14:07:41 +01:00
cat <<EOF > "$install_dir/.bashrc"
2022-08-11 20:50:47 +02:00
eval "$(hub alias -s /bin/bash)"
2017-10-17 15:46:35 +02:00
EOF
2022-08-11 20:50:47 +02:00
fi
2017-10-04 13:42:18 +02:00
#=================================================
# PIP INSTALLATION
#=================================================
2024-01-18 19:57:54 +01:00
ynh_script_progression --message="Install weblate using PIP..." --weight=5
2019-05-30 20:51:22 +02:00
2024-01-18 19:57:54 +01:00
pushd $install_dir
python3 -m venv $install_dir/venv
source $install_dir/venv/bin/activate
ynh_exec_warn_less pip install --upgrade pip setuptools wheel pkgconfig xxhash
# Read the "Note" section in https://docs.weblate.org/en/weblate-5.3/admin/install/venv-debian.html#python-modules
ynh_exec_warn_less pip install install --force-reinstall --no-binary :all: cffi
ynh_exec_warn_less pip install Weblate=="$(ynh_app_upstream_version)"
ynh_exec_warn_less pip install psycopg2-binary ruamel.yaml aeidon phply
2020-10-28 17:21:00 +01:00
2017-10-04 10:46:26 +02:00
# specific to YunoHost package:
2024-01-18 19:57:54 +01:00
ynh_exec_warn_less pip install django_sendmail_backend
popd
#=================================================
2022-03-04 08:23:50 +01:00
# ADD A CONFIGURATION
#=================================================
2022-03-04 08:23:50 +01:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
2019-05-30 20:51:22 +02:00
2024-01-18 19:57:54 +01:00
# Configure redis
redis_db=$(ynh_redis_get_free_db)
2024-01-18 19:57:54 +01:00
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
2024-01-17 14:07:41 +01:00
path="${path%/}"
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
2021-06-28 15:32:27 +02:00
set_forge_variables
2021-06-28 15:32:27 +02:00
ynh_add_config --template="../conf/settings.py" --destination="$settings"
2024-01-17 14:07:41 +01:00
ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate"
2022-03-04 08:23:50 +01:00
ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
2024-01-17 14:07:41 +01:00
touch "$install_dir/local_settings.py"
ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
2020-10-28 17:21:00 +01:00
2022-03-04 08:23:50 +01:00
# Set permissions to app files
2024-01-17 14:07:41 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app: "$install_dir"
chown "$app:www-data" "$install_dir"
chown -R "$app:www-data" "$install_dir/data"
2022-03-04 08:23:50 +01:00
#=================================================
# SPECIFIC SETUP Filling up the database
# https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database
#==========================================
2020-11-03 17:19:19 +01:00
ynh_script_progression --message="Filling up the database..." --weight=10
2020-10-28 12:02:15 +01:00
2024-01-18 19:57:54 +01:00
export DJANGO_SETTINGS_MODULE="weblate.settings"
ynh_exec_warn_less $install_dir/venv/bin/weblate migrate --noinput
ynh_exec_warn_less $install_dir/venv/bin/weblate collectstatic --noinput
ynh_exec_warn_less $install_dir/venv/bin/weblate createadmin --no-color \
2021-01-05 11:59:39 +01:00
--password "$password" \
2017-09-27 00:27:06 +02:00
--username "$admin" \
--email "$admin_mail"
2020-11-03 16:26:23 +01:00
2024-01-18 19:57:54 +01:00
# Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
ynh_exec_warn_less $install_dir/venv/bin/weblate check --deploy || true
2020-10-28 12:02:15 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2022-03-04 08:23:50 +01:00
ynh_script_progression --message="Configuring a systemd service..." --weight=3
2022-03-04 08:23:50 +01:00
ynh_add_systemd_config --service=$app --template="weblate.service"
2020-10-28 12:02:15 +01:00
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service"
#=================================================
# GENERIC FINALIZATION
2019-08-23 08:32:02 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2021-06-28 18:24:51 +02:00
ynh_script_progression --message="Configuring log rotation..." --weight=1
2019-08-23 08:32:02 +02:00
# Use logrotate to manage application logfile(s)
2020-10-28 12:02:15 +01:00
ynh_use_logrotate --non-append
2019-08-23 08:32:02 +02:00
#=================================================
2020-10-28 12:02:15 +01:00
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2021-06-28 18:24:51 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
2022-03-04 08:23:50 +01:00
yunohost service add $app --log="/var/log/$app/weblate.log"
2024-01-18 19:57:54 +01:00
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery.log"
2022-03-04 08:23:50 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
2024-01-18 19:57:54 +01:00
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery.log" --line_match="mingle: all alone"
2020-10-28 12:02:15 +01:00
2021-06-28 15:32:27 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-11-03 17:19:19 +01:00
ynh_script_progression --message="Installation of $app completed" --last