#!/bin/bash source _common.sh source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) key=$(ynh_string_random --length=50) #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression "Storing installation settings..." ynh_app_setting_set --key=used_forge --value=$used_forge ynh_app_setting_set --key=forge_username --value=$forge_username ynh_app_setting_set --key=forge_token --value=$forge_token # Remove trailing "/" from the path path_no_slash=${path%/} #================================================= # CREATE A POSTGRESQL DATABASE #================================================= ynh_script_progression "Creating a PostgreSQL database..." ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression "Setting up source files..." mkdir -p "$install_dir/avatar-cache" mkdir -p "$install_dir/data" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression "Configuring NGINX web server..." ynh_config_add_nginx #================================================= # INSTALL XXHASH #================================================= ynh_script_progression "Installing xxHash..." tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" pushd $tempdir make make install popd ynh_safe_rm "$tempdir" #================================================= # CONFIGURE HUB #================================================= if [ $used_forge = "GitHub" ] ; then ynh_script_progression "Configure hub..." mkdir "$install_dir/.config/" ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub" cat < "$install_dir/.bashrc" eval "$(hub alias -s /bin/bash)" EOF fi #================================================= # PIP INSTALLATION #================================================= ynh_script_progression "Install weblate using PIP..." virtualenv --python=python3 "${install_dir}/venv" chown -R $app: "$install_dir" #run source in a 'sub shell' ( set +o nounset source "${install_dir}/venv/bin/activate" set -o nounset cd "${install_dir}" sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules sudo --user=$app $install_dir/venv/bin/pip install --force-reinstall --no-binary :all: cffi # Still needed with latest version of weblate? sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $install_dir/venv/bin/pip install Weblate=="$(ynh_app_upstream_version)" sudo --user=$app $install_dir/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply boto3 google openai #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml # specific to YunoHost package: sudo --user=$app $install_dir/venv/bin/pip install django_sendmail_backend ) #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression "Adding $app's configuration..." redis_db=$(ynh_redis_get_free_db) ynh_app_setting_set --key=redis_db --value="$redis_db" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" set_forge_variables ynh_config_add --template="settings.py" --destination="$settings" ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate" ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" 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" # Set permissions to app files 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" #================================================= # SPECIFIC SETUP Filling up the database # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database #========================================== ynh_script_progression "Filling up the database..." ( set +o nounset source "${install_dir}/venv/bin/activate" set -o nounset export DJANGO_SETTINGS_MODULE="weblate.settings" cd "${install_dir}" # the user needs to be weblate for postgresql ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \ --password "$password" \ --username "$admin" \ --email "$admin_mail" # generate static files ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput # https://docs.weblate.org/en/latest/admin/install/venv-debian.html ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate compress # Check the configuration # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true ) #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression "Configuring $app's systemd service..." ynh_config_add_systemd --template="weblate.service" ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service" #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression "Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_config_add_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI" ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone" #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Installation of $app completed"