2017-09-13 14:49:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
path_url=$(ynh_app_setting_get --app="$app" --key=path)
|
|
|
|
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
|
|
|
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
|
|
|
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
2017-10-27 12:47:10 +02:00
|
|
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
2020-10-28 12:02:15 +01:00
|
|
|
github_account=$(ynh_app_setting_get --app="$app" --key=github_account)
|
|
|
|
key=$(ynh_string_random 50)
|
|
|
|
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2019-05-12 17:18:42 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
2019-05-12 17:18:42 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
# Fix is_public as a boolean value
|
2017-09-13 14:49:10 +02:00
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
2017-09-13 14:49:10 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
2017-09-13 14:49:10 +02:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
if [[ -d "$final_path/bin/" ]]
|
|
|
|
then
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_secure_remove --file="$final_path/bin/"
|
2019-03-10 21:57:52 +01:00
|
|
|
fi
|
|
|
|
|
2019-08-28 00:09:23 +02:00
|
|
|
# (<3.8) log cleanups
|
|
|
|
if [[ -e "/var/log/uwsgi/app/$app" ]]
|
|
|
|
then
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop"
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_secure_remove --file="/var/log/uwsgi/app/$app"
|
|
|
|
ynh_secure_remove --file="/var/log/$app-celery"
|
2019-08-28 00:09:23 +02:00
|
|
|
fi
|
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
2020-10-28 12:02:15 +01:00
|
|
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2019-02-25 23:09:47 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Stopping systemd services..." --time --weight=1
|
2019-05-30 20:51:22 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
|
2019-02-25 23:09:47 +01:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# Update dependencies
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
# CREATE DEDICATED USER
|
2017-12-28 17:16:07 +01:00
|
|
|
#=================================================
|
2020-05-01 22:55:31 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2017-12-28 17:16:07 +01:00
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
# Create a system user
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell
|
2017-12-28 17:16:07 +01:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# SPECIFIC SETUP UWSGI
|
2017-11-20 15:58:51 +01:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Configure uwsgi..." --time --weight=1
|
2017-11-20 15:58:51 +01:00
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_backup_if_checksum_is_different --file="$finaluwsgiini"
|
2019-03-10 21:57:52 +01:00
|
|
|
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"
|
|
|
|
|
|
|
|
ynh_store_file_checksum --file="$finaluwsgiini"
|
2020-05-01 22:09:37 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_add_systemd_config --service="$app" --template="weblate.service"
|
2017-09-26 17:01:57 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE CELERY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configure celery..." --time --weight=1
|
|
|
|
|
|
|
|
celeryconf="$final_path/celery-weblate"
|
|
|
|
cp ../conf/celery-weblate "$celeryconf"
|
2018-05-20 14:43:15 +02:00
|
|
|
|
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"
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service"
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
2020-10-28 19:20:46 +01:00
|
|
|
# UPGRADE WEBLATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade() {
|
|
|
|
new_version=$1
|
|
|
|
settings_template=$2
|
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Install weblate using PIP..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop"
|
|
|
|
|
|
|
|
virtualenv --python=python3 "${final_path}/venv"
|
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${final_path}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
sudo -u $app $final_path/venv/bin/pip install --upgrade pip setuptools wheel
|
|
|
|
# Still needed with latest version of weblate?
|
|
|
|
sudo -u $app $final_path/venv/bin/pip install --upgrade Weblate=="$new_version"
|
|
|
|
sudo -u $app $final_path/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 -u $app $final_path/venv/bin/pip install django_sendmail_backend
|
|
|
|
)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Create weblate configuration file..."
|
|
|
|
# save old settings file
|
|
|
|
settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
|
|
|
|
|
|
|
ynh_backup_if_checksum_is_different --file="$settings"
|
|
|
|
cp "$settings_template" "$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"
|
|
|
|
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"
|
|
|
|
|
|
|
|
# remove last "/" of $path_url
|
|
|
|
ynh_replace_string --match_string="__PATHURL__" --replace_string="${path_url%/}" --target_file="$settings"
|
|
|
|
|
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum --file="$settings"
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MIGRATE WEBLATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Run migration scripts..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start"
|
|
|
|
|
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${final_path}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
|
|
|
cd "${final_path}"
|
|
|
|
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate migrate --noinput
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate collectstatic --noinput
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate setuplang
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate setupgroups
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate compilemessages
|
|
|
|
sudo -u $app $final_path/venv/bin/weblate check --deploy
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
file_version="${final_path}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py"
|
|
|
|
if [ -e $file_version ];
|
|
|
|
then
|
|
|
|
current_version=$(cat $file_version | grep "^VERSION = " | grep -o "[0-9].[0-9]" | head -n1 | cut -d"." -f1)
|
|
|
|
else
|
|
|
|
current_version=3
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$current_version" -lt "4" ];
|
|
|
|
then
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
upgrade "4.1.1" "../conf/settings.4.1.1.py"
|
|
|
|
fi
|
|
|
|
|
|
|
|
upgrade $weblate_version "../conf/settings.py"
|
2017-09-13 16:55:01 +02:00
|
|
|
|
2018-06-13 23:49:24 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# SETUP LOGROTATE
|
2018-06-13 23:49:24 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
2019-05-30 20:51:22 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2018-06-13 23:49:24 +02:00
|
|
|
|
2019-08-23 08:32:02 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2019-08-23 08:32:02 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
|
2019-08-23 08:32:02 +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"
|
2019-08-23 08:32:02 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2018-04-08 10:27:26 +02:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set right permissions for curl installation
|
2020-10-28 16:10:55 +01:00
|
|
|
chown -R "$app": "$final_path"
|
2018-04-08 10:27:26 +02:00
|
|
|
|
|
|
|
mkdir -p "$final_path/avatar-cache"
|
|
|
|
chown -R "$app": "$final_path/avatar-cache"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# START SYSTEMD SERVICES
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Starting systemd services..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2018-05-20 14:43:15 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
# SETUP SSOWAT
|
2018-05-20 14:43:15 +02:00
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1
|
2018-05-20 14:43:15 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ "$is_public" -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
|
|
|
|
fi
|
2018-05-20 14:43:15 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-05-30 20:51:22 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --time --last
|