[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:49:13 +02:00 committed by Alexandre Aubin
parent 869c14c61a
commit 2263083526
9 changed files with 116 additions and 128 deletions

3
.gitignore vendored
View file

@ -9,3 +9,6 @@ secret.txt
/local_test/
/coverage.xml
/htmlcov/
*~
*.sw[op]
.DS_Store

View file

@ -15,7 +15,8 @@ license = "GPL-3.0"
code = "https://github.com/jedie/django-fritzconnection"
[integration]
yunohost = ">= 11.2.12"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = true
@ -43,6 +44,7 @@ ram.runtime = "100M"
[resources.system_user]
[resources.install_dir]
group = "www-data:r-x"
[resources.permissions]
main.url = "/"

View file

@ -1,36 +1,23 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
log_path=/var/log/$app
log_file="${log_path}/${app}.log"
#=================================================
# PERSONAL HELPERS
#=================================================
_venv_install() {
ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv"
ynh_exec_as_app python3 -m venv --upgrade "$install_dir/venv"
venvpy="$install_dir/venv/bin/python3"
ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip
ynh_exec_as_app "$venvpy" -m pip install --upgrade --no-cache-dir pip
ynh_exec_as "$app" "$venvpy" -m pip install setuptools wheel pyyaml
ynh_exec_as_app "$venvpy" -m pip install setuptools wheel pyyaml
}
_build_app() {
ynh_exec_as "$app" "$venvpy" -m ensurepip
ynh_exec_as "$app" "$venvpy" -m pip install --upgrade wheel pip setuptools
ynh_exec_as "$app" "$venvpy" -m pip install --no-deps -r "$install_dir/app/requirements.txt"
ynh_exec_as_app "$venvpy" -m ensurepip
ynh_exec_as_app "$venvpy" -m pip install --upgrade wheel pip setuptools
ynh_exec_as_app "$venvpy" -m pip install --no-deps -r "$install_dir/app/requirements.txt"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -7,44 +7,41 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
# Backup the nginx configuration
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
# Backup the systemd service unit
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
# Backup the logrotate configuration
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/var/log/$app/"
ynh_backup "/var/log/$app/"
#=================================================
# BACKUP THE PostgreSQL DATABASE
#=================================================
ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db > db.sql
#=================================================
# 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

@ -10,33 +10,33 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping systemd service '$app'..."
ynh_script_progression "Stopping systemd service '$app'..."
ynh_systemd_action --service_name="$app" --action="stop"
ynh_systemctl --service="$app" --action="stop"
#=================================================
# 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
#=================================================
ynh_script_progression --message="Modify $app config file..."
ynh_script_progression "Modify $app config file..."
ynh_add_config --template="settings.py" --destination="$install_dir/app/settings.py"
ynh_config_add --template="settings.py" --destination="$install_dir/app/settings.py"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#=================================================
# 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

@ -12,52 +12,51 @@ source /usr/share/yunohost/helpers
#=================================================
admin_email="$(ynh_user_get_info "$admin" mail)"
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
ynh_app_setting_set --key=admin_email --value="$admin_email"
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"
#-------------------------------------------------
# config_panel.toml settings:
debug_enabled="0"
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
log_level="WARNING"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
ynh_app_setting_set --key=log_level --value="$log_level"
default_from_email="${app}@${domain}"
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_script_progression "Setting up source files..."
mkdir -p "$install_dir/"{app,public/media,public/static}
ynh_add_config --template="requirements.txt" --destination="$install_dir/app/requirements.txt"
ynh_config_add --template="requirements.txt" --destination="$install_dir/app/requirements.txt"
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/app/gunicorn.conf.py"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/app/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$install_dir/app/manage.py"
ynh_config_add --template="manage.py" --destination="$install_dir/app/manage.py"
chmod +x "$install_dir/app/manage.py"
ynh_add_config --template="settings.py" --destination="$install_dir/app/settings.py"
ynh_add_config --template="setup_user.py" --destination="$install_dir/app/setup_user.py"
ynh_add_config --template="urls.py" --destination="$install_dir/app/urls.py"
ynh_add_config --template="wsgi.py" --destination="$install_dir/app/wsgi.py"
ynh_config_add --template="settings.py" --destination="$install_dir/app/settings.py"
ynh_config_add --template="setup_user.py" --destination="$install_dir/app/setup_user.py"
ynh_config_add --template="urls.py" --destination="$install_dir/app/urls.py"
ynh_config_add --template="wsgi.py" --destination="$install_dir/app/wsgi.py"
touch "$install_dir/app/local_settings.py"
chown -R "$app:www-data" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
mkdir -p "/var/log/$app"
touch "/var/log/$app/$app.log"
chown -R "$app:$app" "/var/log/$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "/var/log/$app"
#=================================================
# PYTHON VIRTUALENV
#=================================================
ynh_script_progression --message="Installing $app..." --weight=10
ynh_script_progression "Installing $app..."
_venv_install
@ -65,44 +64,44 @@ _build_app
pushd "$install_dir/app"
# Just for debugging:
ynh_exec_as "$app" "$venvpy" ./manage.py diffsettings
ynh_exec_as_app "$venvpy" ./manage.py diffsettings
ynh_exec_as "$app" "$venvpy" ./manage.py migrate --no-input
ynh_exec_as "$app" "$venvpy" ./manage.py collectstatic --no-input
ynh_exec_as_app "$venvpy" ./manage.py migrate --no-input
ynh_exec_as_app "$venvpy" ./manage.py collectstatic --no-input
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
ynh_exec_as "$app" "$venvpy" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
ynh_exec_as_app "$venvpy" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
# Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
ynh_exec_as "$app" "$venvpy" ./manage.py check --deploy || true
ynh_exec_as_app "$venvpy" ./manage.py check --deploy || true
popd
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_script_progression "Adding system configurations related to $app..."
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_nginx_config
ynh_config_add_nginx
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add "$app" --description="Django-fritzconnection server" --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate "$log_file"
ynh_config_add_logrotate "$log_file"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -10,20 +10,20 @@ source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
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_exec_warn_less yunohost service status "$app" >/dev/null; then
if ynh_hide_warnings yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
fi
ynh_remove_systemd_config
ynh_config_remove_systemd
ynh_remove_nginx_config
ynh_config_remove_nginx
ynh_remove_logrotate
ynh_config_remove_logrotate
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -10,61 +10,60 @@ source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
ynh_restore "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
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
#=================================================
# PYTHON VIRTUALENV
# Maybe the backup contains another Python version
#=================================================
ynh_script_progression --message="Updating Python virtualenv and rebuilding $app..." --weight=5
ynh_script_progression "Updating Python virtualenv and rebuilding $app..."
# Always recreate everything fresh with current python version
ynh_secure_remove "$install_dir/venv"
ynh_safe_rm "$install_dir/venv"
_venv_install
chown -R "$app:www-data" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
_build_app
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Django-fritzconnection server" --log="/var/log/$app/$app.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_restore_file --origin_path="/var/log/$app/"
ynh_restore "/var/log/$app/"
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -10,37 +10,40 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
ynh_script_progression "Ensuring downward compatibility..."
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=debug_enabled --value="0"
if [ -z "${debug_enabled:-}" ]; then
debug_enabled="0"
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=log_level --value="WARNING"
if [ -z "${log_level:-}" ]; then
log_level="WARNING"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
ynh_app_setting_set --key=log_level --value="$log_level"
fi
if [ -z "${admin_email:-}" ]; then
admin_email="${admin}@${domain}"
fi
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=default_from_email --value="${app}@${domain}"
if [ -z "${default_from_email:-}" ]; then
default_from_email="${app}@${domain}"
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
fi
if [ -d "/opt/yunohost/$app" ]; then
if [ -d "$install_dir/app" ]; then
ynh_secure_remove --file="/opt/yunohost/$app"
ynh_safe_rm "/opt/yunohost/$app"
else
mv "/opt/yunohost/$app" "$install_dir/app"
fi
@ -49,34 +52,32 @@ fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
ynh_script_progression "Upgrading source files..."
mkdir -p "$install_dir/"{app,public/media,public/static}
ynh_add_config --template="requirements.txt" --destination="$install_dir/app/requirements.txt"
ynh_config_add --template="requirements.txt" --destination="$install_dir/app/requirements.txt"
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/app/gunicorn.conf.py"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/app/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$install_dir/app/manage.py"
ynh_config_add --template="manage.py" --destination="$install_dir/app/manage.py"
chmod +x "$install_dir/app/manage.py"
ynh_add_config --template="settings.py" --destination="$install_dir/app/settings.py"
ynh_add_config --template="setup_user.py" --destination="$install_dir/app/setup_user.py"
ynh_add_config --template="urls.py" --destination="$install_dir/app/urls.py"
ynh_add_config --template="wsgi.py" --destination="$install_dir/app/wsgi.py"
chown -R "$app:www-data" "$install_dir"
chown -R "$app:www-data" "$install_dir"
ynh_config_add --template="settings.py" --destination="$install_dir/app/settings.py"
ynh_config_add --template="setup_user.py" --destination="$install_dir/app/setup_user.py"
ynh_config_add --template="urls.py" --destination="$install_dir/app/urls.py"
ynh_config_add --template="wsgi.py" --destination="$install_dir/app/wsgi.py"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
mkdir -p "/var/log/$app"
touch "/var/log/$app/$app.log"
chown -R "$app:$app" "/var/log/$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "/var/log/$app"
#=================================================
# PYTHON VIRTUALENV
#=================================================
ynh_script_progression --message="Upgrading $app..." --weight=10
ynh_script_progression "Upgrading $app..."
_venv_install
@ -84,40 +85,40 @@ _build_app
pushd "$install_dir/app"
# Just for debugging:
ynh_exec_as "$app" "$venvpy" ./manage.py diffsettings
ynh_exec_as_app "$venvpy" ./manage.py diffsettings
ynh_exec_as "$app" "$venvpy" ./manage.py migrate --no-input
ynh_exec_as "$app" "$venvpy" ./manage.py collectstatic --no-input
ynh_exec_as_app "$venvpy" ./manage.py migrate --no-input
ynh_exec_as_app "$venvpy" ./manage.py collectstatic --no-input
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
ynh_exec_as "$app" "$venvpy" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
ynh_exec_as_app "$venvpy" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
# Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
ynh_exec_as "$app" "$venvpy" ./manage.py check --deploy || true
ynh_exec_as_app "$venvpy" ./manage.py check --deploy || true
popd
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_script_progression "Upgrading system configurations related to $app..."
ynh_add_nginx_config
ynh_config_add_nginx
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add "$app" --description="Django-fritzconnection server" --log="/var/log/$app/$app.log"
ynh_use_logrotate --non-append
ynh_config_add_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"