mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
239 lines
8.3 KiB
Bash
239 lines
8.3 KiB
Bash
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression "Loading installation settings..."
|
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
key=$(ynh_string_random --length=50)
|
|
|
|
# Remove trailing "/" from the path
|
|
path_no_slash=${path%/}
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Stopping systemd services..."
|
|
|
|
ynh_systemctl --service=$app --action="stop" --log_path="/var/log/$app/weblate.log" --wait_until="goodbye to uWSGI"
|
|
ynh_systemctl --service="$app-celery" --action="stop" --log_path="systemd"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression "Ensuring downward compatibility..."
|
|
|
|
# If used_forge, forge_username, forge_token don't exist, create them
|
|
if [ -z "$used_forge" ]; then
|
|
used_forge="GitHub"
|
|
forge_username=$(ynh_app_setting_get --key=github_account)
|
|
forge_token=$(ynh_app_setting_get --key=github_token)
|
|
ynh_app_setting_set --key=used_forge --value=$used_forge
|
|
ynh_app_setting_set --key=forge_username --value=$forge_username
|
|
ynh_app_setting_set --key=forge_token --value=$forge_token
|
|
fi
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Upgrading NGINX web server configuration..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_config_add_nginx
|
|
|
|
#=================================================
|
|
# INSTALL XXHASH
|
|
#=================================================
|
|
ynh_script_progression "Installing xxHash..."
|
|
|
|
tempdir="$(mktemp -d)"
|
|
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
|
|
pushd $tempdir
|
|
make
|
|
make install
|
|
popd
|
|
ynh_safe_rm "$tempdir"
|
|
|
|
#=================================================
|
|
# CONFIGURE HUB
|
|
#=================================================
|
|
|
|
if [ $used_forge = "GitHub" ] ; then
|
|
ynh_script_progression "Configure hub..."
|
|
|
|
#mkdir "$install_dir/.config/"
|
|
ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub"
|
|
|
|
cat <<EOF > "$install_dir/.bashrc"
|
|
eval "$(hub alias -s /bin/bash)"
|
|
EOF
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression "Updating configuration..."
|
|
|
|
ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
|
|
chmod 600 "/etc/uwsgi/apps-available/$app.ini"
|
|
|
|
ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression "Configuring $app's systemd service..."
|
|
|
|
ynh_config_add_systemd --template="weblate.service"
|
|
ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service"
|
|
|
|
#=================================================
|
|
# UPGRADE WEBLATE
|
|
#=================================================
|
|
|
|
upgrade() {
|
|
new_version=$1
|
|
settings_template=$2
|
|
#=================================================
|
|
# PIP INSTALLATION
|
|
#=================================================
|
|
ynh_script_progression "Install weblate using PIP..."
|
|
|
|
ynh_safe_rm "${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 boto3 google openai
|
|
#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
|
|
)
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression "Create weblate configuration file..."
|
|
|
|
# save old settings file
|
|
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
|
|
path="${path%/}"
|
|
|
|
set_forge_variables
|
|
|
|
ynh_config_add --template="settings.py" --destination="$settings"
|
|
|
|
ynh_app_setting_set --key=redis_db --value="$redis_db"
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum "$settings"
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# MIGRATE WEBLATE
|
|
#=================================================
|
|
ynh_script_progression "Run migration scripts..."
|
|
|
|
ynh_systemctl --service="$app-celery" --action="start"
|
|
|
|
(
|
|
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
|
|
sudo --user=$app $install_dir/venv/bin/weblate compress
|
|
|
|
# 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
|
|
)
|
|
|
|
ynh_systemctl --service="$app-celery" --action="stop"
|
|
}
|
|
|
|
file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py"
|
|
if [ -e $file_version ]
|
|
then
|
|
current_version=$(cat $file_version | grep "^VERSION = " | grep -o "[0-9].[0-9]" | head -n1 | cut -d"." -f1)
|
|
if [ -z "$current_version" ]
|
|
then
|
|
file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/utils/version.py"
|
|
current_version=$(cat $file_version | grep "^VERSION = " | grep -o "[0-9].[0-9]" | head -n1 | cut -d"." -f1)
|
|
fi
|
|
else
|
|
current_version=3
|
|
fi
|
|
|
|
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
|
|
if [ "$current_version" -lt "5" ]
|
|
then
|
|
upgrade "5.0.2" "../conf/settings.py"
|
|
fi
|
|
|
|
upgrade $(ynh_app_upstream_version) "../conf/settings.py"
|
|
|
|
# Set right permissions for curl installation
|
|
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"
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression "Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_config_add_logrotate
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression "Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --log="/var/log/$app/weblate.log"
|
|
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICES
|
|
#=================================================
|
|
ynh_script_progression "Starting systemd services..."
|
|
|
|
ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI"
|
|
ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Upgrade of $app completed"
|