1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Add migration from 2.16

This commit is contained in:
Jean-Baptiste Holcroft 2017-12-28 17:16:07 +01:00
parent fe71170644
commit 0d0a384078
7 changed files with 85 additions and 26 deletions

32
scripts/_future.sh Normal file
View file

@ -0,0 +1,32 @@
#!/bin/bash
# source: https://github.com/YunoHost/yunohost/commit/4f62eb5320323d4f4de83b2af306ae53e89bc5ba
# Define and install dependencies with a equivs control file
# This helper can/should only be called once per app
#
# usage: ynh_install_app_dependencies dep [dep [...]]
# | arg: dep - the package name to install in dependence
ynh_install_app_dependencies () {
dependencies=$@
manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi
version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
dep_app=${app//_/-} # Replace all '_' by '-'
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
Section: misc
Priority: optional
Package: ${dep_app}-ynh-deps
Version: ${version}
Depends: ${dependencies// /, }
Architecture: all
Description: Fake package for ${app} (YunoHost app) dependencies
This meta-package is only responsible of installing its dependencies.
EOF
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
rm /tmp/${dep_app}-ynh-deps.control
ynh_app_setting_set $app apt_dependencies $dependencies
}

View file

@ -14,6 +14,7 @@ fi
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
ynh_abort_if_errors ynh_abort_if_errors

View file

@ -8,6 +8,7 @@
set -eu set -eu
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS

View file

@ -8,6 +8,7 @@
set -eu set -eu
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE

View file

@ -8,6 +8,7 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS

View file

@ -14,6 +14,7 @@ fi
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
ynh_abort_if_errors ynh_abort_if_errors

View file

@ -7,6 +7,7 @@
#================================================= #=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _future.sh
ynh_abort_if_errors ynh_abort_if_errors
@ -44,28 +45,6 @@ previous_version=$(cat freeze.pip | grep "Weblate==" | sed "s|Weblate==||")
previous_version_file="../conf/settings_history/settings.$previous_version.py" previous_version_file="../conf/settings_history/settings.$previous_version.py"
test -e "$previous_version_file" || ynh_die "Previous version unknown: $previous_version" test -e "$previous_version_file" || ynh_die "Previous version unknown: $previous_version"
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
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
@ -83,6 +62,26 @@ if [ -z "$db_name" ]; then # If db_name doesn't exist, create it
ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_name "$db_name"
fi fi
# handle python3 migration (because of django 2.0)
if [[ -e "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ]]
then
settings="$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
migrate_py2to3=true
else
settings="$final_path/venv/lib/python3.4/site-packages/weblate/settings.py"
migrate_py2to3=false
fi
# 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
# migrade old uwsgi files if existing
if [ -e "/etc/systemd/system/$app.service" ] if [ -e "/etc/systemd/system/$app.service" ]
then then
systemctl stop "$app.service" systemctl stop "$app.service"
@ -103,10 +102,6 @@ path_url=$(ynh_normalize_url_path "$path_url")
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -131,6 +126,14 @@ chsh --shell /bin/bash "$app"
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#=================================================
# Update dependencies
#=================================================
ynh_install_app_dependencies libxml2-dev libxslt-dev libfreetype6-dev \
libjpeg-dev libz-dev libyaml-dev python3-dev python3-pip python3-virtualenv python-virtualenv \
postgresql libpq-dev uwsgi uwsgi-plugin-python3 memcached
#================================================= #=================================================
# SPECIFIC SETUP uwsgi # SPECIFIC SETUP uwsgi
#================================================= #=================================================
@ -141,6 +144,24 @@ ynh_add_uwsgi_service
# PIP INSTALLATION # PIP INSTALLATION
#================================================= #=================================================
# save old settings file
cp "$settings" "$final_path/settings.$previous_version.old.py"
# handle python3 migration
if [[ "$migrate_py2to3" = true ]]
then
ynh_secure_remove "$final_path/venv"
virtualenv --python=python3 "${final_path}/venv"
set +o nounset
source "${final_path}/venv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install Weblate=="$current_version"
settings="$final_path/venv/lib/python3.4/site-packages/weblate/settings.py"
cp "$final_path/settings.$previous_version.old.py" "$settings"
ynh_store_file_checksum "$settings"
fi
old_settings="./settings.$previous_version.old.py" old_settings="./settings.$previous_version.old.py"
settings_diff="$final_path/settings.${previous_version}_${current_version}.diff" settings_diff="$final_path/settings.${previous_version}_${current_version}.diff"
@ -148,6 +169,7 @@ settings_diff="$final_path/settings.${previous_version}_${current_version}.diff"
set +o nounset set +o nounset
source "${final_path}/venv/bin/activate" source "${final_path}/venv/bin/activate"
set -o nounset set -o nounset
pip install --upgrade pip
pip install Weblate=="$current_version" pip install Weblate=="$current_version"
pip install python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2 python-memcached pip install python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2 python-memcached
# specific to YunoHost package: # specific to YunoHost package: