2017-09-13 14:49:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-10-06 10:37:19 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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)
|
|
|
|
key=$(ynh_string_random)
|
|
|
|
|
2017-10-18 23:10:32 +02:00
|
|
|
#=================================================
|
|
|
|
# Get previous version number
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
(
|
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==||")
|
|
|
|
|
|
|
|
previous_version_file="../conf/settings_history/settings.$previous_version.py"
|
|
|
|
test -e "$previous_version_file" || ynh_die "Previous version unknown: $previous_version"
|
|
|
|
|
2017-12-28 08:04:17 +01:00
|
|
|
case "$previous_version" in
|
|
|
|
|
|
|
|
2.16) python_ver=2.7
|
|
|
|
;;
|
|
|
|
2.17.1) python_ver=2.7
|
|
|
|
;;
|
|
|
|
*) python_ver=3.4
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
settings="$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
|
|
|
|
|
|
|
#save memc_port if it doesn't exist
|
|
|
|
if [[ -z "$memc_port" ]]
|
|
|
|
then
|
|
|
|
memc_port=$(cat "$settings" \
|
|
|
|
| grep "'LOCATION': '127.0.0.1:" \
|
|
|
|
| sed "s|.*:\\(.*\\)'.*|\\1|")
|
|
|
|
ynh_app_setting_set "$app" memc_port "$memc_port"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-10-04 15:22:54 +02:00
|
|
|
if [ -z "$db_name" ]; then # If db_name doesn't exist, create it
|
|
|
|
db_name=$(ynh_sanitize_dbid "$app")
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
2017-09-13 14:49:10 +02:00
|
|
|
fi
|
|
|
|
|
2017-11-23 15:17:04 +01:00
|
|
|
if [ -e "/etc/systemd/system/$app.service" ]
|
|
|
|
then
|
|
|
|
systemctl stop "$app.service"
|
|
|
|
systemctl disable "$app.service"
|
|
|
|
yunohost service remove "$app.service"
|
|
|
|
ynh_secure_remove "$final_path/uwsgi.ini"
|
|
|
|
ynh_secure_remove "/etc/systemd/system/$app.service"
|
|
|
|
fi
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
2017-10-04 15:22:54 +02:00
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
2017-09-28 16:42:10 +02:00
|
|
|
ynh_system_user_create "$app" "/home/$app"
|
2017-10-04 10:46:26 +02:00
|
|
|
chsh --shell /bin/bash "$app"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
2017-11-20 15:58:51 +01:00
|
|
|
# SPECIFIC SETUP uwsgi
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-21 13:09:12 +01:00
|
|
|
ynh_add_uwsgi_service
|
2017-09-26 17:01:57 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-18 23:10:32 +02:00
|
|
|
old_settings="./settings.$previous_version.old.py"
|
2017-10-27 12:47:10 +02:00
|
|
|
settings_diff="$final_path/settings.${previous_version}_${current_version}.diff"
|
2017-10-18 23:10:32 +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
|
|
|
|
pip install Weblate=="$current_version"
|
2017-12-28 08:04:17 +01:00
|
|
|
pip install python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2 python-memcached
|
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
|
2017-09-26 17:01:57 +02:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
cp "$previous_version_file" "$old_settings"
|
|
|
|
weblate_fill_settings "$old_settings"
|
|
|
|
|
|
|
|
# store diff between defaults and local settings
|
|
|
|
diff --unified "$old_settings" "$settings" > "$settings_diff"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
# generate new defaults settings
|
2017-12-16 01:06:49 +01:00
|
|
|
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
2017-10-19 11:01:39 +02:00
|
|
|
weblate_fill_settings "$settings"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
# send diff to the server administrator
|
|
|
|
mail_subject="'$app' settings diff from $previous_version to $current_version"
|
|
|
|
mail_message="
|
|
|
|
Weblate was updated from version $previous_version to $current_version
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
A new settings.py has been created in:
|
|
|
|
$settings
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
You may have changed your defaults settings.
|
|
|
|
To help you to apply it again, 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:
|
|
|
|
$settings_diff
|
|
|
|
|
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
|
|
|
|
2017-10-27 12:47:10 +02:00
|
|
|
# Email server admin - for ACTION
|
|
|
|
echo "$mail_message" | mail -s "$mail_subject" root -u root
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
# inform weblate's admin
|
|
|
|
mail_subject="'$app' was updated from $previous_version to $current_version"
|
|
|
|
mail_message="
|
|
|
|
Weblate was updated from version $previous_version to $current_version
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-19 11:01:39 +02:00
|
|
|
A new settings.py has been created and a diff has been sent to root user.
|
|
|
|
Your administrator may have to update your settings.py to have a fully working installation.
|
|
|
|
"
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2017-10-27 12:47:10 +02:00
|
|
|
# Email weblate's admin - for INFO
|
2017-10-19 11:01:39 +02:00
|
|
|
echo "$mail_subject" | mail -s "$mail_subject" "$admin_mail"
|
|
|
|
else
|
|
|
|
echo "Settings.py was not modified, using the new default file for $current_version."
|
|
|
|
# generate new defaults settings
|
2017-12-16 01:06:49 +01:00
|
|
|
cp "../conf/settings_history/settings.$current_version.py" "$settings"
|
2017-10-19 11:01:39 +02:00
|
|
|
weblate_fill_settings "$settings"
|
|
|
|
fi
|
2017-10-18 23:10:32 +02:00
|
|
|
|
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
|
|
|
#=================================================
|
|
|
|
|
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}"
|
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
|
2017-12-16 01:06:49 +01:00
|
|
|
ynh_store_file_checksum "$final_path/venv/lib/python3.4/site-packages/weblate/settings.py"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl reload nginx
|