diff --git a/scripts/_future.sh b/scripts/_future.sh new file mode 100644 index 0000000..d603e2d --- /dev/null +++ b/scripts/_future.sh @@ -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 +} diff --git a/scripts/backup b/scripts/backup index 19d6d74..074e25f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,6 +14,7 @@ fi source _common.sh source /usr/share/yunohost/helpers +source _future.sh ynh_abort_if_errors diff --git a/scripts/change_url b/scripts/change_url index 9ba67e8..cd43236 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -8,6 +8,7 @@ set -eu source _common.sh source /usr/share/yunohost/helpers +source _future.sh #================================================= # RETRIEVE ARGUMENTS diff --git a/scripts/install b/scripts/install index 8e6d436..f8e19f6 100755 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ set -eu source _common.sh source /usr/share/yunohost/helpers +source _future.sh #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/remove b/scripts/remove index a8452b3..2739c8a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,6 +8,7 @@ source _common.sh source /usr/share/yunohost/helpers +source _future.sh #================================================= # LOAD SETTINGS diff --git a/scripts/restore b/scripts/restore index ca4b584..505f851 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,6 +14,7 @@ fi source _common.sh source /usr/share/yunohost/helpers +source _future.sh ynh_abort_if_errors diff --git a/scripts/upgrade b/scripts/upgrade index 1eef08d..1367678 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh source /usr/share/yunohost/helpers +source _future.sh 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" 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 #================================================= @@ -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" 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" ] then systemctl stop "$app.service" @@ -103,10 +102,6 @@ path_url=$(ynh_normalize_url_path "$path_url") # STANDARD UPGRADE STEPS #================================================= -#================================================= -# NGINX CONFIGURATION -#================================================= - # Create a dedicated nginx config ynh_add_nginx_config @@ -131,6 +126,14 @@ chsh --shell /bin/bash "$app" #================================================= # 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 #================================================= @@ -141,6 +144,24 @@ ynh_add_uwsgi_service # 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" 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 source "${final_path}/venv/bin/activate" set -o nounset + pip install --upgrade pip pip install Weblate=="$current_version" pip install python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2 python-memcached # specific to YunoHost package: