2017-09-13 14:49:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2024-01-18 14:23:24 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-10-18 23:10:32 +02:00
|
|
|
|
2022-07-13 00:48:56 +02:00
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
|
|
key=$(ynh_string_random --length=50)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
2021-03-15 00:27:49 +01:00
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# STANDARD UPGRADE STEPS
|
2021-03-15 00:27:49 +01:00
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping systemd services..." --weight=5
|
2021-03-15 00:27:49 +01:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI"
|
2024-01-18 13:12:54 +01:00
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd"
|
2021-03-15 00:27:49 +01:00
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2022-08-11 20:00:25 +02:00
|
|
|
# If used_forge, forge_username, forge_token don't exist, create them
|
2022-08-11 19:48:34 +02:00
|
|
|
if [ -z "$used_forge" ]; then
|
|
|
|
used_forge="GitHub"
|
2024-01-18 13:12:54 +01:00
|
|
|
forge_username=$(ynh_app_setting_get --app=$app --key=github_account)
|
|
|
|
forge_token=$(ynh_app_setting_get --app=$app --key=github_token)
|
2022-08-11 19:48:34 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge
|
2022-08-11 20:00:25 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username
|
2022-08-11 19:48:34 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token
|
|
|
|
fi
|
|
|
|
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2022-07-13 00:48:56 +02:00
|
|
|
# NGINX CONFIGURATION
|
2017-09-13 14:49:10 +02:00
|
|
|
#=================================================
|
2022-07-13 00:48:56 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2022-07-13 00:48:56 +02:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2017-09-13 14:49:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# SPECIFIC UPGRADE
|
2022-07-13 02:11:01 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL XXHASH
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing xxHash..."
|
|
|
|
|
|
|
|
tempdir="$(mktemp -d)"
|
|
|
|
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
|
|
|
|
pushd $tempdir
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
popd
|
|
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
|
2020-11-03 10:19:34 +01:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE HUB
|
|
|
|
#=================================================
|
|
|
|
|
2022-08-11 20:43:28 +02:00
|
|
|
if [ $used_forge = "GitHub" ] ; then
|
2022-08-11 20:50:47 +02:00
|
|
|
ynh_script_progression --message="Configure hub..." --weight=1
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
#mkdir "$install_dir/.config/"
|
|
|
|
ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub"
|
2020-11-03 10:19:34 +01:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
cat <<EOF > "$install_dir/.bashrc"
|
2022-08-11 20:50:47 +02:00
|
|
|
eval "$(hub alias -s /bin/bash)"
|
2020-11-03 10:19:34 +01:00
|
|
|
EOF
|
2022-08-11 20:50:47 +02:00
|
|
|
fi
|
2020-11-03 10:19:34 +01:00
|
|
|
|
2017-09-26 17:01:57 +02:00
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
# UPDATE A CONFIG FILE
|
2017-11-20 15:58:51 +01:00
|
|
|
#=================================================
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=2
|
2017-11-20 15:58:51 +01:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
|
2020-10-28 12:02:15 +01:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate"
|
2020-05-01 22:09:37 +02:00
|
|
|
|
2020-10-28 12:02:15 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=3
|
2019-03-10 21:57:52 +01:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_add_systemd_config --service=$app --template="weblate.service"
|
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
|
2024-01-19 08:23:09 +01:00
|
|
|
#=================================================
|
|
|
|
# PIP INSTALLATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Install weblate using PIP..." --weight=15
|
|
|
|
|
|
|
|
ynh_secure_remove --file="${install_dir}/venv"
|
|
|
|
virtualenv --python=python3 "${install_dir}/venv"
|
|
|
|
chown -R $app: "$install_dir"
|
|
|
|
|
|
|
|
#run source in a 'sub shell'
|
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${install_dir}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
cd "${install_dir}"
|
|
|
|
|
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --upgrade pip setuptools wheel pkgconfig xxhash
|
|
|
|
|
|
|
|
# Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules
|
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --force-reinstall --no-binary :all: cffi
|
|
|
|
# Still needed with latest version of weblate?
|
|
|
|
sudo --user=$app $install_dir/venv/bin/pip install --upgrade Weblate=="$new_version"
|
|
|
|
sudo --user=$app $install_dir/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 --user=$app $install_dir/venv/bin/pip install django_sendmail_backend
|
|
|
|
)
|
2020-10-28 19:20:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Create weblate configuration file..." --weight=2
|
2020-10-28 19:20:46 +01:00
|
|
|
# save old settings file
|
2024-01-17 14:07:41 +01:00
|
|
|
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
|
|
|
path="${path%/}"
|
2020-10-28 19:20:46 +01:00
|
|
|
|
2022-08-11 19:48:34 +02:00
|
|
|
set_forge_variables
|
|
|
|
|
2021-06-28 15:32:27 +02:00
|
|
|
ynh_add_config --template="../conf/settings.py" --destination="$settings"
|
2020-10-28 19:20:46 +01:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
|
2020-10-28 19:20:46 +01:00
|
|
|
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum --file="$settings"
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
touch "$install_dir/local_settings.py"
|
|
|
|
ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
|
2020-10-28 19:20:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MIGRATE WEBLATE
|
|
|
|
#=================================================
|
2020-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Run migration scripts..." --weight=10
|
2020-10-28 19:20:46 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start"
|
|
|
|
|
2024-01-19 08:23:09 +01:00
|
|
|
(
|
|
|
|
set +o nounset
|
|
|
|
source "${install_dir}/venv/bin/activate"
|
|
|
|
set -o nounset
|
|
|
|
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
|
|
|
cd "${install_dir}"
|
|
|
|
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate setuplang
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate setupgroups
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate compilemessages
|
|
|
|
|
|
|
|
# Check the configuration
|
|
|
|
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
|
|
|
|
if [ "$new_version" == "$(ynh_app_upstream_version)" ]; then
|
|
|
|
sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true
|
|
|
|
fi
|
|
|
|
)
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="stop"
|
2020-10-28 19:20:46 +01:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py"
|
2020-11-03 10:19:34 +01:00
|
|
|
if [ -e $file_version ]
|
2020-10-28 19:20:46 +01:00
|
|
|
then
|
|
|
|
current_version=$(cat $file_version | grep "^VERSION = " | grep -o "[0-9].[0-9]" | head -n1 | cut -d"." -f1)
|
2021-04-12 16:39:05 +02:00
|
|
|
if [ -z "$current_version" ]
|
|
|
|
then
|
2024-01-17 14:07:41 +01:00
|
|
|
file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/utils/version.py"
|
2021-04-12 16:39:05 +02:00
|
|
|
current_version=$(cat $file_version | grep "^VERSION = " | grep -o "[0-9].[0-9]" | head -n1 | cut -d"." -f1)
|
|
|
|
fi
|
2020-10-28 19:20:46 +01:00
|
|
|
else
|
|
|
|
current_version=3
|
|
|
|
fi
|
|
|
|
|
2020-10-28 20:22:25 +01:00
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
|
2022-07-13 00:48:56 +02:00
|
|
|
upgrade $(ynh_app_upstream_version) "../conf/settings.py"
|
2017-09-13 16:55:01 +02:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
# Set right permissions for curl installation
|
2024-01-17 14:07:41 +01:00
|
|
|
mkdir -p "$install_dir/avatar-cache"
|
|
|
|
chown -R $app: "$install_dir"
|
|
|
|
chown "$app:www-data" "$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir/data"
|
2022-03-04 08:23:50 +01:00
|
|
|
|
2024-01-17 14:07:41 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
2022-03-04 08:23:50 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
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
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --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
|
|
|
#=================================================
|
2021-06-28 18:24:51 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
2019-08-23 08:32:02 +02:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
yunohost service add $app --log="/var/log/$app/weblate.log"
|
2024-01-19 08:23:09 +01:00
|
|
|
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
|
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-11-03 17:19:19 +01:00
|
|
|
ynh_script_progression --message="Starting systemd services..." --weight=5
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2022-03-04 08:23:50 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
|
2024-01-19 08:23:09 +01:00
|
|
|
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
|
2017-09-13 14:49:10 +02:00
|
|
|
|
2019-05-30 20:51:22 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-06-28 15:32:27 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|