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
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2017-10-04 15:22:54 +02:00
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2017-10-27 12:47:10 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
|
|
|
admin=$(ynh_app_setting_get "$app" admin)
|
|
|
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
|
|
|
memc_port=$(ynh_app_setting_get "$app" memc_port)
|
|
|
|
github_account=$(ynh_app_setting_get "$app" github_account)
|
2018-09-01 15:16:50 +02:00
|
|
|
migration311=$(ynh_app_setting_get "$app" migration311)
|
2018-09-02 14:18:13 +02:00
|
|
|
key=$(ynh_string_random 24)$(ynh_string_random 24)$(ynh_string_random 2)
|
2018-10-25 08:01:56 +02:00
|
|
|
redis_db=$(ynh_app_setting_get "$app" redis_db)
|
2017-10-27 12:47:10 +02:00
|
|
|
|
2017-10-18 23:10:32 +02:00
|
|
|
#=================================================
|
|
|
|
# Get previous version number
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Get previous version number..." --time --weight=1
|
2017-10-18 23:10:32 +02:00
|
|
|
|
|
|
|
(
|
2017-12-17 17:19:48 +01:00
|
|
|
set +o nounset
|
2017-10-18 23:10:32 +02:00
|
|
|
source "${final_path}/venv/bin/activate"
|
2017-12-17 17:19:48 +01:00
|
|
|
set -o nounset
|
|
|
|
pip install --upgrade pip
|
|
|
|
pip freeze --local > freeze.pip
|
2017-10-18 23:10:32 +02:00
|
|
|
)
|
|
|
|
previous_version=$(cat freeze.pip | grep "Weblate==" | sed "s|Weblate==||")
|
|
|
|
|
2018-09-01 22:42:51 +02:00
|
|
|
ynh_secure_remove freeze.pip
|
|
|
|
|
|
|
|
previous_version_template="../conf/settings_history/settings.$previous_version.py"
|
|
|
|
test -e "$previous_version_template" || ynh_die "Previous version unknown: $previous_version"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2019-05-12 17:18:42 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02: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
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2017-10-04 15:22:54 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 1 # Fix is_public as a boolean value
|
2017-09-13 14:49:10 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2017-10-04 15:22:54 +02:00
|
|
|
ynh_app_setting_set "$app" is_public 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
|
|
|
|
ynh_secure_remove "$final_path/bin/"
|
|
|
|
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"
|
|
|
|
ynh_secure_remove "/var/log/uwsgi/app/$app"
|
|
|
|
ynh_secure_remove "/var/log/$app-celery"
|
|
|
|
fi
|
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
|
|
|
|
2019-02-25 23:09:47 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Stopping systemd services..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop"
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
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
|
|
|
|
|
2017-10-17 15:46:35 +02:00
|
|
|
if [ "$path_url" == "/" ]
|
|
|
|
then
|
|
|
|
# $finalnginxconf comes from ynh_add_nginx_config
|
|
|
|
ynh_replace_string "location //" "location /" "$finalnginxconf"
|
|
|
|
|
|
|
|
# ynh panel is only comptable with non-root installation
|
|
|
|
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
|
|
|
|
|
|
|
ynh_store_file_checksum "$finalnginxconf"
|
|
|
|
fi
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# Update dependencies
|
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
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
2017-12-28 17:16:07 +01:00
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create "$app" "/home/$app"
|
|
|
|
chsh --shell /bin/bash "$app"
|
2017-12-28 17:16:07 +01:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
2017-11-20 15:58:51 +01:00
|
|
|
# SPECIFIC SETUP uwsgi
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02: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"
|
|
|
|
cp ../conf/uwsgi.ini "$finaluwsgiini"
|
|
|
|
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini"
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini"
|
|
|
|
ynh_replace_string "__APP__" "$app" "$finaluwsgiini"
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
|
2018-05-20 14:43:15 +02:00
|
|
|
# root install doesn't require uwsgi to handle script names
|
|
|
|
if [ "$path_url" == "/" ]
|
|
|
|
then
|
|
|
|
ynh_replace_string "manage-script-name = true" "manage-script-name = false" "$finaluwsgiini"
|
|
|
|
fi
|
|
|
|
|
2019-03-10 21:57:52 +01:00
|
|
|
ynh_add_systemd_config "$app" "weblate.service"
|
|
|
|
|
|
|
|
ynh_store_file_checksum "$finaluwsgiini"
|
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
|
2019-08-28 08:31:15 +02:00
|
|
|
ynh_script_progression --message="Install weblate using PIP..." --time --weight=10
|
2018-10-26 22:48:09 +02:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
(
|
2017-12-17 17:19:48 +01:00
|
|
|
set +o nounset
|
2017-09-26 17:01:57 +02:00
|
|
|
source "${final_path}/venv/bin/activate"
|
2017-12-17 17:19:48 +01:00
|
|
|
set -o nounset
|
2017-12-28 17:16:07 +01:00
|
|
|
pip install --upgrade pip
|
2018-04-07 10:13:07 +02:00
|
|
|
# prevent error: "command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers"
|
|
|
|
pip install --upgrade setuptools
|
2017-12-17 17:19:48 +01:00
|
|
|
pip install Weblate=="$current_version"
|
2019-08-28 18:23:05 +02: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:
|
2017-12-17 17:19:48 +01:00
|
|
|
pip install django_sendmail_backend
|
2018-10-25 08:01:56 +02:00
|
|
|
)
|
2017-09-26 17:01:57 +02:00
|
|
|
|
2018-09-01 22:42:51 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIG FILE UPGRADE
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Create weblate configuration file..." --time --weight=1
|
2018-09-01 22:42:51 +02:00
|
|
|
# save old settings file
|
2019-08-28 08:31:15 +02:00
|
|
|
settings="$final_path/venv/lib/python3.5/site-packages/weblate/settings.py"
|
2018-09-01 22:42:51 +02:00
|
|
|
|
|
|
|
old_settings="$final_path/settings.$previous_version.old.py"
|
|
|
|
|
|
|
|
cp "$settings" "$old_settings"
|
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
check=$(ynh_check_if_checksum_is_different "$settings")
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
if [[ "$check" -eq 1 ]]
|
|
|
|
then
|
|
|
|
echo "Settings.py was modified localy, running diff before using the new default file for $current_version."
|
|
|
|
# generate previous defaults settings
|
2018-09-01 22:42:51 +02:00
|
|
|
cp "$previous_version_template" "$old_settings"
|
2017-10-19 11:01:39 +02:00
|
|
|
weblate_fill_settings "$old_settings"
|
|
|
|
|
|
|
|
# store diff between defaults and local settings
|
2018-09-01 22:42:51 +02:00
|
|
|
set +eu
|
|
|
|
diff --unified "$old_settings" "$settings" > "$final_path/settings.${previous_version}_${current_version}.diff"
|
|
|
|
set -eu
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
# send diff to the server administrator
|
|
|
|
mail_message="
|
|
|
|
Weblate was updated from version $previous_version to $current_version
|
2018-09-01 22:42:51 +02:00
|
|
|
Please read:
|
|
|
|
https://docs.weblate.org/en/latest/admin/upgrade.html
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2018-09-01 22:42:51 +02:00
|
|
|
A new settings.py has been created:
|
2017-10-19 11:01:39 +02:00
|
|
|
$settings
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
You may have changed your defaults settings.
|
2018-09-01 22:42:51 +02:00
|
|
|
To help you, here is a diff file with every changes you did.
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-27 12:47:10 +02:00
|
|
|
Diff has been created in:
|
2018-09-01 22:42:51 +02:00
|
|
|
$final_path/settings.${previous_version}_${current_version}.diff
|
2017-10-27 12:47:10 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
Please note secret key is updated, this is normal.
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
For any issue, please file a bug in: https://github.com/YunoHost-Apps/weblate_ynh
|
|
|
|
"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2018-04-01 12:50:02 +02:00
|
|
|
ynh_send_readme_to_admin "$mail_message" root "$admin_mail"
|
2017-10-19 11:01:39 +02:00
|
|
|
else
|
|
|
|
echo "Settings.py was not modified, using the new default file for $current_version."
|
|
|
|
fi
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2018-09-01 22:42:51 +02:00
|
|
|
# generate new defaults settings
|
|
|
|
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
|
|
|
weblate_fill_settings "$settings"
|
|
|
|
|
|
|
|
ynh_secure_remove "$old_settings"
|
|
|
|
|
2018-10-26 22:48:09 +02:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE CELERY
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Configure celery..." --time --weight=1
|
2018-10-26 22:48:09 +02:00
|
|
|
|
|
|
|
celeryconf="$final_path/celery-weblate"
|
|
|
|
cp ../conf/celery-weblate "$celeryconf"
|
|
|
|
|
|
|
|
ynh_replace_string "__APP__" "$app" "$celeryconf"
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path" "$celeryconf"
|
|
|
|
|
|
|
|
ynh_add_systemd_config "$app-celery" "celery-weblate.service"
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2017-10-18 23:10:32 +02:00
|
|
|
# Run migration scripts
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Run migration scripts..." --time --weight=1
|
2017-09-15 20:59:21 +02:00
|
|
|
(
|
2017-12-17 17:19:48 +01:00
|
|
|
set +o nounset
|
|
|
|
source "${final_path}/venv/bin/activate"
|
|
|
|
set -o nounset
|
2017-09-15 20:59:21 +02:00
|
|
|
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
2017-10-04 15:22:54 +02:00
|
|
|
cd "${final_path}"
|
2018-06-06 00:23:36 +02:00
|
|
|
|
2017-09-15 20:59:21 +02:00
|
|
|
weblate migrate --noinput
|
2017-10-18 23:10:32 +02:00
|
|
|
weblate collectstatic --noinput
|
|
|
|
weblate setuplang
|
|
|
|
weblate setupgroups
|
2017-09-15 20:59:21 +02:00
|
|
|
)
|
2017-09-13 16:55:01 +02:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
# Recalculate and store the config file checksum into the app settings
|
2018-10-26 22:48:09 +02:00
|
|
|
ynh_store_file_checksum "$final_path/venv/lib/python3.5/site-packages/weblate/settings.py"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2018-06-13 23:49:24 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Configure cron file..." --time --weight=1
|
|
|
|
|
2018-06-13 23:49:24 +02:00
|
|
|
cp ../conf/cron "/etc/cron.d/$app"
|
|
|
|
ynh_replace_string "__APP__" "$app" "/etc/cron.d/$app"
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
|
|
|
|
|
2019-08-23 08:32:02 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2019-08-28 00:09:23 +02:00
|
|
|
ynh_use_logrotate
|
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
|
|
|
|
chown -R root:root "$final_path"
|
|
|
|
chown -R "$app": "$final_path/data"
|
|
|
|
|
|
|
|
mkdir -p "$final_path/avatar-cache"
|
|
|
|
chown -R "$app": "$final_path/avatar-cache"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
if [ $is_public -eq 0 ]
|
|
|
|
then # Remove the public access
|
2017-10-04 15:22:54 +02:00
|
|
|
ynh_app_setting_delete "$app" skipped_uris
|
2017-09-13 14:49:10 +02:00
|
|
|
fi
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2017-10-04 15:22:54 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2017-10-17 15:46:35 +02:00
|
|
|
|
|
|
|
# ynh panel is not needed
|
|
|
|
ynh_replace_string " include conf.d/" " #include conf.d/" "$finalnginxconf"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
|
|
|
ynh_store_file_checksum "$finalnginxconf"
|
2017-09-13 14:49:10 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-20 14:43:15 +02:00
|
|
|
#=================================================
|
|
|
|
# Restart weblate
|
|
|
|
#=================================================
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Starting weblate's services..." --time --weight=1
|
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
|
|
|
|
#=================================================
|
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name="nginx" --action="reload"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --time --last
|