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

Merge pull request #116 from yunohost-bot/auto-helpers-2.1

[autopatch] Automatic patch attempt for helpers 2.1
This commit is contained in:
Thomas 2024-09-30 18:14:40 +02:00 committed by GitHub
commit 77994d07c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 150 additions and 264 deletions

3
.gitignore vendored
View file

@ -99,3 +99,6 @@ ENV/
# mypy # mypy
.mypy_cache/ .mypy_cache/
*~
*.sw[op]
.DS_Store

View file

@ -23,6 +23,7 @@ fund = "https://weblate.org/fr/donate/"
[integration] [integration]
yunohost = ">= 12.0.0" yunohost = ">= 12.0.0"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = true multi_instance = true
ldap = false ldap = false
@ -86,6 +87,7 @@ ram.runtime = "3G"
[resources.system_user] [resources.system_user]
[resources.install_dir] [resources.install_dir]
group = "www-data:r-x"
[resources.permissions] [resources.permissions]
main.url = "/" main.url = "/"

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
debian_maj_version=$(sed 's/\..*//' /etc/debian_version) debian_maj_version=$(sed 's/\..*//' /etc/debian_version)
@ -16,10 +16,6 @@ elif [ "$debian_maj_version" -eq 12 ] ; then
weblate_pypath="python3.11" weblate_pypath="python3.11"
fi fi
#=================================================
# PERSONAL HELPERS
#=================================================
set_forge_variables() { set_forge_variables() {
if [ $used_forge = "GitHub" ] ; then if [ $used_forge = "GitHub" ] ; then
github_username="$forge_username" github_username="$forge_username"
@ -33,11 +29,3 @@ set_forge_variables() {
gitlab_token="$forge_token" gitlab_token="$forge_token"
fi fi
} }
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,62 +1,38 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= ynh_backup "/etc/logrotate.d/$app"
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app-celery.service"
#================================================= ynh_backup "/etc/uwsgi/apps-available/$app.ini"
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app-celery.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..." ynh_print_info "Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql ynh_psql_dump_db > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,87 +1,75 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1 ynh_script_progression "Stopping systemd services..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI" ynh_systemctl --service=$app --action="stop" --log_path="/var/log/$app/weblate.log" --wait_until="goodbye to uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" ynh_systemctl --service="$app-celery" --action="stop" --log_path="systemd"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#=================================================
# SPECIFIC MODIFICATIONS
#================================================= #=================================================
# MODIFY SETTINGS # MODIFY SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Modify weblate's config file..." --weight=1 ynh_script_progression "Modify weblate's config file..."
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
ynh_backup_if_checksum_is_different --file="$settings" ynh_backup_if_checksum_is_different "$settings"
# Change the path in the nginx config file # Change the path in the nginx config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
ynh_replace_string --match_string="URL_PREFIX = \"${old_path%/}\"" --replace_string="URL_PREFIX = \"${new_path%/}\"" --target_file="$settings" ynh_replace --match="URL_PREFIX = \"${old_path%/}\"" --replace="URL_PREFIX = \"${new_path%/}\"" --file="$settings"
fi fi
# Change the domain for nginx # Change the domain for nginx
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# replace SERVER_EMAIL # replace SERVER_EMAIL
ynh_replace_string --match_string="noreply@$old_domain" --replace_string="noreply@$new_domain" --target_file="$settings" ynh_replace --match="noreply@$old_domain" --replace="noreply@$new_domain" --file="$settings"
# replace SITE_DOMAIN # replace SITE_DOMAIN
ynh_replace_string --match_string="SITE_DOMAIN = \"$old_domain\"" --replace_string="SITE_DOMAIN = \"$new_domain\"" --target_file="$settings" ynh_replace --match="SITE_DOMAIN = \"$old_domain\"" --replace="SITE_DOMAIN = \"$new_domain\"" --file="$settings"
# replace ALLOWED_HOSTS # replace ALLOWED_HOSTS
ynh_replace_string --match_string="ALLOWED_HOSTS = \[\"$old_domain\"\]" --replace_string="ALLOWED_HOSTS = \[\"$new_domain\"\]" --target_file="$settings" ynh_replace --match="ALLOWED_HOSTS = \[\"$old_domain\"\]" --replace="ALLOWED_HOSTS = \[\"$new_domain\"\]" --file="$settings"
fi fi
ynh_store_file_checksum --file="$settings" ynh_store_file_checksum "$settings"
#================================================= #=================================================
# MODIFY UWSGI # MODIFY UWSGI
#================================================= #=================================================
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
ynh_backup_if_checksum_is_different --file="$finaluwsgiini" ynh_backup_if_checksum_is_different "$finaluwsgiini"
# Change the path in the nginx config file # Change the path in the nginx config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
ynh_replace_string --match_string="mount = $old_path=" --replace_string="mount = $new_path=" --target_file="$finaluwsgiini" ynh_replace --match="mount = $old_path=" --replace="mount = $new_path=" --file="$finaluwsgiini"
fi fi
ynh_store_file_checksum --file="$finaluwsgiini" ynh_store_file_checksum "$finaluwsgiini"
#=================================================
# GENERIC FINALISATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -19,11 +13,11 @@ key=$(ynh_string_random --length=50)
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_script_progression "Storing installation settings..."
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge ynh_app_setting_set --key=used_forge --value=$used_forge
ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username ynh_app_setting_set --key=forge_username --value=$forge_username
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token ynh_app_setting_set --key=forge_token --value=$forge_token
# Remove trailing "/" from the path # Remove trailing "/" from the path
path_no_slash=${path%/} path_no_slash=${path%/}
@ -31,14 +25,14 @@ path_no_slash=${path%/}
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 ynh_script_progression "Creating a PostgreSQL database..."
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." ynh_script_progression "Setting up source files..."
mkdir -p "$install_dir/avatar-cache" mkdir -p "$install_dir/avatar-cache"
mkdir -p "$install_dir/data" mkdir -p "$install_dir/data"
@ -50,17 +44,14 @@ chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2 ynh_script_progression "Configuring NGINX web server..."
# Create a dedicated NGINX config ynh_config_add_nginx
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#================================================= #=================================================
# INSTALL XXHASH # INSTALL XXHASH
#================================================= #=================================================
ynh_script_progression --message="Installing xxHash..." ynh_script_progression "Installing xxHash..."
tempdir="$(mktemp -d)" tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
@ -68,17 +59,17 @@ pushd $tempdir
make make
make install make install
popd popd
ynh_secure_remove --file="$tempdir" ynh_safe_rm "$tempdir"
#================================================= #=================================================
# CONFIGURE HUB # CONFIGURE HUB
#================================================= #=================================================
if [ $used_forge = "GitHub" ] ; then if [ $used_forge = "GitHub" ] ; then
ynh_script_progression --message="Configure hub..." --weight=1 ynh_script_progression "Configure hub..."
mkdir "$install_dir/.config/" mkdir "$install_dir/.config/"
ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub" ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub"
cat <<EOF > "$install_dir/.bashrc" cat <<EOF > "$install_dir/.bashrc"
eval "$(hub alias -s /bin/bash)" eval "$(hub alias -s /bin/bash)"
@ -88,11 +79,10 @@ fi
#================================================= #=================================================
# PIP INSTALLATION # PIP INSTALLATION
#================================================= #=================================================
ynh_script_progression --message="Install weblate using PIP..." --weight=80 ynh_script_progression "Install weblate using PIP..."
virtualenv --python=python3 "${install_dir}/venv" virtualenv --python=python3 "${install_dir}/venv"
chown -R $app: "$install_dir" chown -R $app: "$install_dir"
#run source in a 'sub shell' #run source in a 'sub shell'
( (
set +o nounset set +o nounset
@ -116,17 +106,17 @@ chown -R $app: "$install_dir"
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression "Adding $app's configuration..."
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" ynh_app_setting_set --key=redis_db --value="$redis_db"
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
set_forge_variables set_forge_variables
ynh_add_config --template="../conf/settings.py" --destination="$settings" ynh_config_add --template="settings.py" --destination="$settings"
ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate" ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate"
ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
touch "$install_dir/local_settings.py" 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" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
@ -142,7 +132,7 @@ chown -R "$app:www-data" "$install_dir/data"
# SPECIFIC SETUP Filling up the database # SPECIFIC SETUP Filling up the database
# https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database
#========================================== #==========================================
ynh_script_progression --message="Filling up the database..." --weight=10 ynh_script_progression "Filling up the database..."
( (
set +o nounset set +o nounset
@ -152,46 +142,44 @@ ynh_script_progression --message="Filling up the database..." --weight=10
cd "${install_dir}" cd "${install_dir}"
# the user needs to be weblate for postgresql # the user needs to be weblate for postgresql
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate migrate --noinput
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \ ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate createadmin --no-color \
--password "$password" \ --password "$password" \
--username "$admin" \ --username "$admin" \
--email "$admin_mail" --email "$admin_mail"
# generate static files # generate static files
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate collectstatic --noinput
# https://docs.weblate.org/en/latest/admin/install/venv-debian.html # https://docs.weblate.org/en/latest/admin/install/venv-debian.html
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate compress ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate compress
# Check the configuration # Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later. # This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
ynh_exec_warn_less sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true ynh_hide_warnings sudo --user=$app $install_dir/venv/bin/weblate check --deploy || true
) )
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=3 ynh_script_progression "Configuring $app's systemd service..."
ynh_add_systemd_config --service=$app --template="weblate.service" ynh_config_add_systemd --template="weblate.service"
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1 ynh_script_progression "Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --non-append ynh_config_add_logrotate
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
@ -199,13 +187,13 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,63 +1,33 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# STANDARD REMOVE # REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_hide_warnings yunohost service status $app >/dev/null; then
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app yunohost service remove $app
fi fi
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_hide_warnings yunohost service status "$app-celery" >/dev/null; then
if ynh_exec_warn_less yunohost service status "$app-celery" >/dev/null
then
ynh_script_progression --message="Removing $app-celery service integration..." --weight=1
yunohost service remove "$app-celery" yunohost service remove "$app-celery"
fi fi
#================================================= ynh_config_remove_systemd
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=5
# Remove the dedicated systemd config ynh_config_remove_systemd"$app-celery"
ynh_remove_systemd_config --service=$app
ynh_remove_systemd_config --service="$app-celery"
#================================================= ynh_config_remove_logrotate
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config ynh_config_remove_nginx
ynh_remove_logrotate
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE XXHASH # REMOVE XXHASH
#================================================= #=================================================
ynh_script_progression --message="Removing xxHash..." ynh_script_progression "Removing xxHash..."
tempdir="$(mktemp -d)" tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
@ -65,18 +35,16 @@ pushd $tempdir
make make
make uninstall make uninstall
popd popd
ynh_secure_remove --file="$tempdir" ynh_safe_rm "$tempdir"
#=================================================
# SPECIFIC REMOVE
#================================================= #=================================================
# REMOVE VARIOUS FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..." ynh_script_progression "Removing various files..."
ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini" ynh_safe_rm "/etc/uwsgi/apps-available/$app.ini"
ynh_secure_remove --file="/var/run/$app-celery" ynh_safe_rm "/var/run/$app-celery"
ynh_redis_remove_db ynh_redis_remove_db
@ -84,4 +52,4 @@ ynh_redis_remove_db
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,21 +1,14 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=4 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
touch "$install_dir/local_settings.py" 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" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
@ -29,21 +22,21 @@ chown -R $app:www-data "$install_dir/data"
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql ynh_psql_db_shell < ./db.sql
#================================================= #=================================================
# INSTALL XXHASH # INSTALL XXHASH
#================================================= #=================================================
ynh_script_progression --message="Installing xxHash..." ynh_script_progression "Installing xxHash..."
tempdir="$(mktemp -d)" tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
@ -51,37 +44,37 @@ pushd $tempdir
make make
make install make install
popd popd
ynh_secure_remove --file="$tempdir" ynh_safe_rm "$tempdir"
#================================================= #=================================================
# RESTORE VARIOUS FILES # RESTORE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Restoring various files..." --weight=1 ynh_script_progression "Restoring various files..."
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini" ynh_restore "/etc/uwsgi/apps-available/$app.ini"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=4 ynh_script_progression "Restoring $app's systemd service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-celery.service" ynh_restore "/etc/systemd/system/$app-celery.service"
systemctl enable "$app-celery" --quiet systemctl enable "$app-celery" --quiet
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." ynh_script_progression "Restoring the logrotate configuration..."
mkdir -p "/var/log/$app" mkdir -p "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
@ -89,22 +82,20 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-w1.log" --line_match="mingle: all alone" ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-w1.log" --wait_until="mingle: all alone"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_script_progression "Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,18 +1,12 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression "Loading installation settings..."
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
key=$(ynh_string_random --length=50) key=$(ynh_string_random --length=50)
@ -20,51 +14,41 @@ key=$(ynh_string_random --length=50)
# Remove trailing "/" from the path # Remove trailing "/" from the path
path_no_slash=${path%/} path_no_slash=${path%/}
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=5 ynh_script_progression "Stopping systemd services..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI" ynh_systemctl --service=$app --action="stop" --log_path="/var/log/$app/weblate.log" --wait_until="goodbye to uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" ynh_systemctl --service="$app-celery" --action="stop" --log_path="systemd"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
# If used_forge, forge_username, forge_token don't exist, create them # If used_forge, forge_username, forge_token don't exist, create them
if [ -z "$used_forge" ]; then if [ -z "$used_forge" ]; then
used_forge="GitHub" used_forge="GitHub"
forge_username=$(ynh_app_setting_get --app=$app --key=github_account) forge_username=$(ynh_app_setting_get --key=github_account)
forge_token=$(ynh_app_setting_get --app=$app --key=github_token) forge_token=$(ynh_app_setting_get --key=github_token)
ynh_app_setting_set --app=$app --key=used_forge --value=$used_forge ynh_app_setting_set --key=used_forge --value=$used_forge
ynh_app_setting_set --app=$app --key=forge_username --value=$forge_username ynh_app_setting_set --key=forge_username --value=$forge_username
ynh_app_setting_set --app=$app --key=forge_token --value=$forge_token ynh_app_setting_set --key=forge_token --value=$forge_token
fi fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 ynh_script_progression "Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# INSTALL XXHASH # INSTALL XXHASH
#================================================= #=================================================
ynh_script_progression --message="Installing xxHash..." ynh_script_progression "Installing xxHash..."
tempdir="$(mktemp -d)" tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash" ynh_setup_source --dest_dir=$tempdir --source_id="libxxhash"
@ -72,17 +56,17 @@ pushd $tempdir
make make
make install make install
popd popd
ynh_secure_remove --file="$tempdir" ynh_safe_rm "$tempdir"
#================================================= #=================================================
# CONFIGURE HUB # CONFIGURE HUB
#================================================= #=================================================
if [ $used_forge = "GitHub" ] ; then if [ $used_forge = "GitHub" ] ; then
ynh_script_progression --message="Configure hub..." --weight=1 ynh_script_progression "Configure hub..."
#mkdir "$install_dir/.config/" #mkdir "$install_dir/.config/"
ynh_add_config --template="../conf/hub_config" --destination="$install_dir/.config/hub" ynh_config_add --template="hub_config" --destination="$install_dir/.config/hub"
cat <<EOF > "$install_dir/.bashrc" cat <<EOF > "$install_dir/.bashrc"
eval "$(hub alias -s /bin/bash)" eval "$(hub alias -s /bin/bash)"
@ -92,19 +76,19 @@ fi
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=2 ynh_script_progression "Updating configuration..."
ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" ynh_config_add --template="uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
ynh_add_config --template="../conf/celery-weblate" --destination="$install_dir/celery-weblate" ynh_config_add --template="celery-weblate" --destination="$install_dir/celery-weblate"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=3 ynh_script_progression "Configuring $app's systemd service..."
ynh_add_systemd_config --service=$app --template="weblate.service" ynh_config_add_systemd --template="weblate.service"
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" ynh_config_add_systemd --service="$app-celery" --template="celery-weblate.service"
#================================================= #=================================================
# UPGRADE WEBLATE # UPGRADE WEBLATE
@ -116,12 +100,11 @@ upgrade() {
#================================================= #=================================================
# PIP INSTALLATION # PIP INSTALLATION
#================================================= #=================================================
ynh_script_progression --message="Install weblate using PIP..." --weight=15 ynh_script_progression "Install weblate using PIP..."
ynh_secure_remove --file="${install_dir}/venv" ynh_safe_rm "${install_dir}/venv"
virtualenv --python=python3 "${install_dir}/venv" virtualenv --python=python3 "${install_dir}/venv"
chown -R $app: "$install_dir" chown -R $app: "$install_dir"
#run source in a 'sub shell' #run source in a 'sub shell'
( (
set +o nounset set +o nounset
@ -144,19 +127,20 @@ upgrade() {
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Create weblate configuration file..." --weight=2 ynh_script_progression "Create weblate configuration file..."
# save old settings file # save old settings file
settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" settings="$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
path="${path%/}" path="${path%/}"
set_forge_variables set_forge_variables
ynh_add_config --template="../conf/settings.py" --destination="$settings" ynh_config_add --template="settings.py" --destination="$settings"
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" ynh_app_setting_set --key=redis_db --value="$redis_db"
# Recalculate and store the config file checksum into the app settings # Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$settings" ynh_store_file_checksum "$settings"
touch "$install_dir/local_settings.py" 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" ln -sf "$install_dir/local_settings.py" "$install_dir/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
@ -164,9 +148,9 @@ upgrade() {
#================================================= #=================================================
# MIGRATE WEBLATE # MIGRATE WEBLATE
#================================================= #=================================================
ynh_script_progression --message="Run migration scripts..." --weight=10 ynh_script_progression "Run migration scripts..."
ynh_systemd_action --service_name="$app-celery" --action="start" ynh_systemctl --service="$app-celery" --action="start"
( (
set +o nounset set +o nounset
@ -189,7 +173,7 @@ upgrade() {
fi fi
) )
ynh_systemd_action --service_name="$app-celery" --action="stop" ynh_systemctl --service="$app-celery" --action="stop"
} }
file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py" file_version="${install_dir}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py"
@ -205,7 +189,7 @@ else
current_version=3 current_version=3
fi fi
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
if [ "$current_version" -lt "5" ] if [ "$current_version" -lt "5" ]
then then
@ -223,20 +207,18 @@ chown -R "$app:www-data" "$install_dir/data"
chmod 750 "$install_dir" chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir" chmod -R o-rwx "$install_dir"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 ynh_script_progression "Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_config_add_logrotate
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
@ -244,13 +226,13 @@ yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#================================================= #=================================================
# START SYSTEMD SERVICES # START SYSTEMD SERVICES
#================================================= #=================================================
ynh_script_progression --message="Starting systemd services..." --weight=5 ynh_script_progression "Starting systemd services..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI" ynh_systemctl --service=$app --action="start" --log_path="/var/log/$app/weblate.log" --wait_until="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" ynh_systemctl --service="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --wait_until="mingle: all alone"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"