mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
294 lines
11 KiB
Bash
Executable file
294 lines
11 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
#REMOVEME? ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
#REMOVEME? ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
#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
|
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
key=$(ynh_string_random --length=50)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1
|
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1
|
|
|
|
#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
|
|
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
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=40
|
|
|
|
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
# Create a system user
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" --use_shell
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
|
|
|
#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
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
#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"
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# CONFIGURE HUB
|
|
#=================================================
|
|
|
|
if [ $used_forge = "GitHub" ] ; then
|
|
ynh_script_progression --message="Configure hub..." --weight=1
|
|
|
|
mkdir "$install_dir/.config/"
|
|
ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub"
|
|
|
|
cat <<EOF > "$install_dir/.bashrc"
|
|
eval "$(hub alias -s /bin/bash)"
|
|
EOF
|
|
fi
|
|
|
|
#=================================================
|
|
# PIP INSTALLATION
|
|
#=================================================
|
|
ynh_script_progression --message="Install weblate using PIP..." --weight=80
|
|
|
|
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
|
|
#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 --message="Adding a configuration file..." --weight=1
|
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
|
|
path="${path%/}"
|
|
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
|
|
|
set_forge_variables
|
|
|
|
ynh_add_config --template="../conf/settings.py" --destination="$settings"
|
|
ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate"
|
|
ynh_add_config --template="../conf/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 --message="Filling up the database..." --weight=10
|
|
|
|
(
|
|
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_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput
|
|
# generate static files
|
|
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 \
|
|
--password "$password" \
|
|
--username "$admin" \
|
|
--email "$admin_mail"
|
|
|
|
# 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 sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true
|
|
)
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=3
|
|
|
|
ynh_add_systemd_config --service=$app --template="weblate.service"
|
|
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1
|
|
|
|
# Make app public if necessary
|
|
#REMOVEME? if [ $is_public -eq 1 ]
|
|
then
|
|
# Everyone can access the app.
|
|
# The "main" permission is automatically created before the install script.
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="nginx" --action="reload"
|
|
|
|
#=================================================
|
|
# 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
|
|
"
|
|
|
|
ynh_send_readme_to_admin "$message" "$admin"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|