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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2021-01-05 11:59:39 +01:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2017-09-13 14:49:10 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2017-10-04 10:46:26 +02:00
|
|
|
github_account=$YNH_APP_ARG_GITHUB_ACCOUNT
|
|
|
|
github_token=$YNH_APP_ARG_GITHUB_TOKEN
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
2020-10-28 12:02:15 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2017-09-19 10:53:37 +02:00
|
|
|
mkdir -p "$final_path"
|
2017-09-15 17:25:04 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
|
|
|
|
ynh_app_setting_set --app="$app" --key=path --value="$path_url"
|
|
|
|
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
|
|
|
|
ynh_app_setting_set --app="$app" --key=is_public --value="$is_public"
|
|
|
|
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
|
|
|
ynh_app_setting_set --app="$app" --key=github_account --value="$github_account"
|
|
|
|
ynh_app_setting_set --app="$app" --key=github_token --value="$github_token"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=40
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2020-11-03 16:26:23 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-09-19 10:53:37 +02:00
|
|
|
# CREATE A PostgreSQL DATABASE
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name="$app")
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
|
2018-05-20 14:43:15 +02:00
|
|
|
|
2017-09-19 10:53:37 +02:00
|
|
|
ynh_psql_test_if_first_run
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2017-09-19 10:53:37 +02:00
|
|
|
# Initialize database and store postgres password for upgrade
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2017-10-04 10:46:26 +02:00
|
|
|
# Hub needs a home directory with a config file
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell
|
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
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configure hub..."
|
2017-10-04 10:46:26 +02:00
|
|
|
|
|
|
|
mkdir "$final_path/.config/"
|
|
|
|
cp ../conf/hub_config "$final_path/.config/hub"
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_replace_string --match_string="__GITHUBUSER__" --replace_string="$github_account" --target_file="$final_path/.config/hub"
|
|
|
|
ynh_replace_string --match_string="__GITHUBTOKEN__" --replace_string="$github_token" --target_file="$final_path/.config/hub"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2017-10-17 15:46:35 +02:00
|
|
|
cat <<EOF > "$final_path/.bashrc"
|
2020-10-28 12:02:15 +01:00
|
|
|
eval "$(hub alias -s /bin/bash)"
|
2017-10-17 15:46:35 +02:00
|
|
|
EOF
|
2017-10-04 13:42:18 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
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
|
|
|
|
2020-10-28 20:22:25 +01:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
|
2018-10-19 23:28:40 +02:00
|
|
|
virtualenv --python=python3 "${final_path}/venv"
|
2021-05-04 16:06:04 +02:00
|
|
|
chown -R "$app": "$final_path"
|
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
|
2017-09-19 10:53:37 +02:00
|
|
|
source "${final_path}/venv/bin/activate"
|
2017-12-16 01:06:49 +01:00
|
|
|
set -o nounset
|
2021-05-04 16:06:04 +02:00
|
|
|
cd "${final_path}"
|
|
|
|
|
|
|
|
sudo --user=$app $final_path/venv/bin/pip install --upgrade pip setuptools wheel
|
2020-10-28 12:02:15 +01:00
|
|
|
# Still needed with latest version of weblate?
|
2021-05-04 16:06:04 +02:00
|
|
|
sudo --user=$app $final_path/venv/bin/pip install Weblate=="$weblate_version"
|
|
|
|
sudo --user=$app $final_path/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:
|
2021-05-04 16:06:04 +02:00
|
|
|
sudo --user=$app $final_path/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
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP settings.py
|
|
|
|
# https://docs.weblate.org/en/latest/admin/install.html#installation
|
2017-09-15 17:25:04 +02:00
|
|
|
# TODO: use --extra-search-dir=/path/to/dists
|
2017-09-15 16:59:22 +02:00
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Create weblate configuration file..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
|
|
key=$(ynh_string_random --length=50)
|
2018-10-19 23:28:40 +02:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
|
|
|
2020-05-01 22:09:37 +02:00
|
|
|
settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
2020-10-28 12:02:15 +01:00
|
|
|
cp "../conf/settings.py" "$settings"
|
|
|
|
|
|
|
|
ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__GITHUBUSER__" --replace_string="$github_account" --target_file="$settings"
|
2020-11-03 10:19:34 +01:00
|
|
|
ynh_replace_string --match_string="__GITHUBTOKEN__" --replace_string="$github_token" --target_file="$settings"
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$settings"
|
|
|
|
ynh_replace_string --match_string="__PYTHONPATH__" --replace_string="$weblate_pypath" --target_file="$settings"
|
2021-01-05 12:01:49 +01:00
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$settings"
|
2020-10-28 12:02:15 +01:00
|
|
|
|
|
|
|
# remove last "/" of $path_url
|
|
|
|
ynh_replace_string --match_string="__PATHURL__" --replace_string="${path_url%/}" --target_file="$settings"
|
2017-10-17 15:46:35 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
2017-09-15 16:59:22 +02:00
|
|
|
|
2020-10-28 17:21:00 +01:00
|
|
|
touch "$final_path/local_settings.py"
|
|
|
|
ln -sf "$final_path/local_settings.py" "$final_path/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
|
|
|
|
|
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
|
2017-09-19 10:53:37 +02:00
|
|
|
source "${final_path}/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"
|
2021-05-04 16:06:04 +02:00
|
|
|
cd "${final_path}"
|
|
|
|
|
2017-09-20 03:26:27 +02:00
|
|
|
# the user needs to be weblate for postgresql
|
2021-05-04 16:06:04 +02:00
|
|
|
sudo --user=$app $final_path/venv/bin/weblate migrate --noinput
|
2017-09-14 17:40:26 +02:00
|
|
|
# generate static files
|
2021-05-04 16:06:04 +02:00
|
|
|
sudo --user=$app $final_path/venv/bin/weblate collectstatic --noinput
|
|
|
|
sudo --user=$app $final_path/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.
|
2021-05-04 16:06:04 +02:00
|
|
|
sudo --user=$app $final_path/venv/bin/weblate check --deploy || true
|
2017-09-14 17:40:26 +02:00
|
|
|
)
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_store_file_checksum --file="$settings"
|
2018-10-19 23:28:40 +02:00
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# SPECIFIC SETUP UWSGI
|
2019-02-25 23:09:47 +01:00
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configure uwsgi..."
|
2020-10-28 12:02:15 +01:00
|
|
|
|
2019-02-25 23:09:47 +01:00
|
|
|
|
|
|
|
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
|
|
|
|
cp ../conf/uwsgi.ini "$finaluwsgiini"
|
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finaluwsgiini"
|
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$finaluwsgiini"
|
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finaluwsgiini"
|
|
|
|
ynh_replace_string --match_string="__PYTHONPATH__" --replace_string="$weblate_pypath" --target_file="$finaluwsgiini"
|
2020-05-01 22:09:37 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_store_file_checksum --file="$finaluwsgiini"
|
2019-02-25 23:09:47 +01:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2019-02-25 23:09:47 +01:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_add_systemd_config --service="$app" --template="weblate.service"
|
2019-02-25 23:09:47 +01:00
|
|
|
|
2018-10-19 23:28:40 +02:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE CELERY
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configure celery..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2018-10-19 23:28:40 +02:00
|
|
|
celeryconf="$final_path/celery-weblate"
|
|
|
|
cp ../conf/celery-weblate "$celeryconf"
|
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$celeryconf"
|
|
|
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$celeryconf"
|
2018-10-19 23:28:40 +02:00
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2018-04-08 10:27:26 +02:00
|
|
|
mkdir -p "$final_path/avatar-cache"
|
2021-04-12 15:21:09 +02:00
|
|
|
chown -R "$app": "$final_path"
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2019-08-23 08:32:02 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
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
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
# Make app public if necessary
|
2017-09-19 10:53:37 +02:00
|
|
|
if [ "$is_public" -eq 1 ]
|
2017-09-13 14:49:10 +02:00
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
|
2017-09-13 14:49:10 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-20 14:43:15 +02:00
|
|
|
#=================================================
|
|
|
|
# Start weblate
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Starting weblate's services..." --weight=5
|
2018-05-20 14:43:15 +02:00
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start"
|
2018-05-20 14:43:15 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
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"
|
|
|
|
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|