2017-09-13 14:49:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Storing installation settings..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
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
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-01-23 19:32:15 +01:00
|
|
|
# Remove trailing "/" from the path
|
2024-01-23 19:24:08 +01:00
|
|
|
path_no_slash=${path%/}
|
2024-01-23 16:33:31 +01:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Creating a PostgreSQL database..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Setting up source files..."
|
2022-03-04 08:23:50 +01:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
mkdir -p "$install_dir/avatar-cache"
|
|
|
|
mkdir -p "$install_dir/data"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-09-18 20:34:28 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Configuring NGINX web server..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_config_add_nginx
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2022-07-13 02:11:01 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL XXHASH
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Installing xxHash..."
|
2022-07-13 02:11:01 +02:00
|
|
|
|
|
|
|
tempdir="$(mktemp -d)"
|
|
|
|
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
|
|
|
|
pushd $tempdir
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
popd
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_safe_rm "$tempdir"
|
2022-07-13 02:11:01 +02:00
|
|
|
|
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
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Configure hub..."
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
mkdir "$install_dir/.config/"
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
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
|
|
|
|
2017-09-14 17:40:26 +02:00
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Install weblate using PIP..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2024-01-19 08:22:14 +01:00
|
|
|
virtualenv --python=python3 "${install_dir}/venv"
|
2024-09-18 20:34:28 +02:00
|
|
|
chown -R $app: "$install_dir"
|
2024-09-30 18:33:33 +02:00
|
|
|
|
2024-01-19 08:22:14 +01:00
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${install_dir}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
cd "${install_dir}"
|
|
|
|
|
2024-01-21 09:09:51 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash
|
2024-01-19 08:22:14 +01:00
|
|
|
|
|
|
|
# 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)"
|
2024-01-24 14:05:57 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply boto3 google openai
|
2024-01-19 08:22:14 +01:00
|
|
|
#pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml
|
2024-01-20 19:25:40 +01:00
|
|
|
|
2017-10-04 10:46:26 +02:00
|
|
|
# specific to YunoHost package:
|
2024-01-19 08:22:14 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install django_sendmail_backend
|
|
|
|
)
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2017-09-15 16:59:22 +02:00
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# ADD A CONFIGURATION
|
2017-09-15 16:59:22 +02:00
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Adding $app's configuration..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2018-10-19 23:28:40 +02:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_app_setting_set --key=redis_db --value="$redis_db"
|
2024-01-17 14:07:41 +01:00
|
|
|
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
2021-06-28 15:32:27 +02:00
|
|
|
|
2022-08-11 19:48:34 +02:00
|
|
|
set_forge_variables
|
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
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"
|
2017-09-15 16:59:22 +02:00
|
|
|
|
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-09-18 20:34:28 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app: "$install_dir"
|
|
|
|
chown "$app:www-data" "$install_dir"
|
2024-01-17 14:07:41 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir/data"
|
2022-03-04 08:23:50 +01:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP Filling up the database
|
|
|
|
# https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database
|
|
|
|
#==========================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Filling up the database..."
|
2020-10-28 12:02:15 +01:00
|
|
|
|
2024-01-19 08:22:14 +01:00
|
|
|
(
|
|
|
|
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
|
2024-08-31 03:55:10 +02:00
|
|
|
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 \
|
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-21 12:21:47 +01:00
|
|
|
# generate static files
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput
|
2024-01-21 12:21:47 +01:00
|
|
|
|
|
|
|
# https://docs.weblate.org/en/latest/admin/install/venv-debian.html
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate compress
|
2024-01-21 12:21:47 +01:00
|
|
|
|
2024-01-19 08:22:14 +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.
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true
|
2024-01-19 08:22:14 +01:00
|
|
|
)
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Configuring $app's systemd service..."
|
2018-10-19 23:28:40 +02:00
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_config_add_systemd --template="weblate.service"
|
|
|
|
ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2019-08-23 08:32:02 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Configuring log rotation..."
|
2019-08-23 08:32:02 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_config_add_logrotate
|
2019-08-23 08:32:02 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Integrating service in YunoHost..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
yunohost service add $app --log="/var/log/$app/weblate.log"
|
2024-01-19 08:22:14 +01:00
|
|
|
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Starting $app's systemd service..."
|
2022-03-04 08:23:50 +01:00
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
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"
|
2020-10-28 12:02:15 +01:00
|
|
|
|
2021-06-28 15:32:27 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2024-08-31 03:55:10 +02:00
|
|
|
ynh_script_progression "Installation of $app completed"
|