2017-09-13 14:49:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_clean_setup () {
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-09-13 14:49:10 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_abort_if_errors
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
#REMOVEME? path=$YNH_APP_ARG_PATH
|
|
|
|
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
|
|
|
|
#REMOVEME? password=$YNH_APP_ARG_PASSWORD
|
|
|
|
#REMOVEME? used_forge=$YNH_APP_ARG_USED_FORGE
|
|
|
|
#REMOVEME? forge_username=$YNH_APP_ARG_FORGE_USERNAME
|
|
|
|
#REMOVEME? forge_token=$YNH_APP_ARG_FORGE_TOKEN
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
2017-09-13 14:49:10 +02:00
|
|
|
|
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
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
2020-10-28 12:02:15 +01:00
|
|
|
|
|
|
|
# Register (book) web path
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin
|
2022-08-11 19:48:34 +02:00
|
|
|
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
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=40
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
# Create a system user
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" --use_shell
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
#REMOVEME? db_user=$db_name
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
#REMOVEME? ynh_psql_test_if_first_run
|
|
|
|
#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
|
|
|
mkdir -p "$install_dir"
|
|
|
|
mkdir -p "$install_dir/avatar-cache"
|
|
|
|
mkdir -p "$install_dir/data"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
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"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
2017-09-13 14:49:10 +02:00
|
|
|
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"
|
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
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Install weblate using PIP..." --weight=80
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
virtualenv --python=python3 "${install_dir}/venv"
|
|
|
|
chown -R $app: "$install_dir"
|
2020-10-28 17:21:00 +01:00
|
|
|
|
2017-09-14 17:40:26 +02:00
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
2017-12-16 01:06:49 +01:00
|
|
|
set +o nounset
|
2024-01-17 14:07:41 +01:00
|
|
|
source "${install_dir}/venv/bin/activate"
|
2017-12-16 01:06:49 +01:00
|
|
|
set -o nounset
|
2024-01-17 14:07:41 +01:00
|
|
|
cd "${install_dir}"
|
2021-05-04 16:06:04 +02:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash
|
2022-03-11 17:37:20 +01:00
|
|
|
|
|
|
|
# Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules
|
2024-01-17 14:07:41 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --force-reinstall --no-binary :all: cffi
|
2020-10-28 12:02:15 +01:00
|
|
|
# Still needed with latest version of weblate?
|
2024-01-17 14:07:41 +01:00
|
|
|
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
|
2020-10-28 12:02:15 +01:00
|
|
|
#pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml
|
2017-10-04 10:46:26 +02:00
|
|
|
# specific to YunoHost package:
|
2024-01-17 14:07:41 +01:00
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install django_sendmail_backend
|
2017-09-14 17:40:26 +02:00
|
|
|
)
|
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
|
|
|
#=================================================
|
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
|
|
|
|
2018-10-19 23:28:40 +02:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
2022-03-04 08:23:50 +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
|
|
|
|
2022-08-11 19:48:34 +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"
|
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-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
|
|
|
|
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
|
|
|
|
#==========================================
|
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
|
|
|
|
2017-09-14 17:40:26 +02:00
|
|
|
(
|
2017-12-16 01:06:49 +01:00
|
|
|
set +o nounset
|
2024-01-17 14:07:41 +01:00
|
|
|
source "${install_dir}/venv/bin/activate"
|
2017-12-16 01:06:49 +01:00
|
|
|
set -o nounset
|
2017-09-15 10:44:45 +02:00
|
|
|
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
2024-01-17 14:07:41 +01:00
|
|
|
cd "${install_dir}"
|
2021-05-04 16:06:04 +02:00
|
|
|
|
2017-09-20 03:26:27 +02:00
|
|
|
# the user needs to be weblate for postgresql
|
2024-01-17 14:07:41 +01:00
|
|
|
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput
|
2017-09-14 17:40:26 +02:00
|
|
|
# generate static files
|
2024-01-17 14:07:41 +01:00
|
|
|
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput
|
|
|
|
ynh_exec_warn_less 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
|
|
|
|
|
|
|
# Check the configuration
|
|
|
|
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
2024-01-17 14:07:41 +01:00
|
|
|
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true
|
2017-09-14 17:40:26 +02:00
|
|
|
)
|
2017-09-13 14:49:10 +02:00
|
|
|
|
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
|
2018-10-19 23:28:40 +02:00
|
|
|
|
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"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
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
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
|
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"
|
|
|
|
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
|
2020-10-28 12:02:15 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1
|
2021-03-15 00:27:49 +01:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
# Make app public if necessary
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? if [ $is_public -eq 1 ]
|
2017-09-13 14:49:10 +02:00
|
|
|
then
|
2022-07-13 00:48:56 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2017-09-13 14:49:10 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2024-01-17 14:07:41 +01:00
|
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2019-05-30 20:51:22 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="nginx" --action="reload"
|
2018-04-01 12:50:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
message="
|
|
|
|
Weblate settings file : $settings
|
|
|
|
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/weblate_ynh
|
|
|
|
"
|
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_send_readme_to_admin "$message" "$admin"
|
|
|
|
|
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
|