1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/scovie_ynh.git synced 2024-09-03 20:16:29 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 02:58:37 +02:00 committed by Alexandre Aubin
parent 4a49fc9654
commit d4de61dee2
9 changed files with 117 additions and 162 deletions

3
.gitignore vendored
View file

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

View file

@ -18,6 +18,7 @@ demo = "https://scovie.eclipse-technology.eu"
[integration]
yunohost = ">=11.2.12"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = true
@ -47,6 +48,7 @@ ram.runtime = "300M"
[resources.system_user]
[resources.install_dir]
group = "www-data:r-x"
[resources.permissions]
main.url = "/"

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
ynh_current_host=$(cat /etc/yunohost/current_host)
@ -20,32 +20,18 @@ admin_email="${admin}@${domain}"
# 'default_from_email' -> '__DEFAULT_FROM_EMAIL__' -> settings.DEFAULT_FROM_EMAIL
default_from_email="${app}@${domain}"
#REMOVEME? install_dir=/opt/yunohost/$app
log_path=/var/log/$app
log_file="${log_path}/${app}.log"
#=================================================
# PERSONAL HELPERS
#=================================================
_install_scovie_venv() {
ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv"
ynh_exec_as_app python3 -m venv --upgrade "$install_dir/venv"
venvpython="$install_dir/venv/bin/python3"
ynh_add_config --template="requirements.txt" --destination="$install_dir/requirements.txt"
ynh_config_add --template="requirements.txt" --destination="$install_dir/requirements.txt"
ynh_exec_as "$app" "$venvpython" -m ensurepip
ynh_exec_as "$app" "$venvpython" -m pip install --upgrade wheel pip setuptools
ynh_exec_as "$app" "$venvpython" -m pip install --no-deps -r "$install_dir/requirements.txt"
ynh_exec_as_app "$venvpython" -m ensurepip
ynh_exec_as_app "$venvpython" -m pip install --upgrade wheel pip setuptools
ynh_exec_as_app "$venvpython" -m pip install --no-deps -r "$install_dir/requirements.txt"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,46 +1,37 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/var/log/$app/"
ynh_backup "/var/log/$app/"
#=================================================
# 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
#=================================================
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,55 +1,43 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
#REMOVEME? YNH_APP_ARG_DOMAIN=$YNH_APP_NEW_DOMAIN
#REMOVEME? YNH_APP_ARG_PATH=$YNH_APP_NEW_PATH
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# 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"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config
ynh_config_change_url_nginx
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# MODIFY SETTINGS
#=================================================
ynh_script_progression --message="Modify $app config file..."
ynh_script_progression "Modify $app config file..."
ynh_add_config --template="settings.py" --destination="$install_dir/settings.py"
ynh_config_add --template="settings.py" --destination="$install_dir/settings.py"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
ynh_script_progression "Starting systemd service '$app'..."
ynh_systemd_action --service_name="$app" --action="start"
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,28 +12,27 @@ source /usr/share/yunohost/helpers
#=================================================
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:
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
ynh_app_setting_set --key=debug_enabled --value="$debug_enabled"
ynh_app_setting_set --key=log_level --value="$log_level"
ynh_app_setting_set --key=admin_email --value="$admin_email"
ynh_app_setting_set --key=default_from_email --value="$default_from_email"
#=================================================
# INSTALLATION
#=================================================
ynh_script_progression --message="Installing project via pip..." --weight=45
ynh_script_progression "Installing project via pip..."
_install_scovie_venv
mkdir -p "$install_dir/public/media" "$install_dir/public/static"
chmod o-rwx "$install_dir"
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 | chmod 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"
mkdir -p "$log_path"
touch "$log_file"
@ -43,64 +42,65 @@ chown -R "$app:$app" "$log_path"
#=================================================
# COPY CONFIG FILES
# ================================================
ynh_script_progression --message="Create $app configuration files..."
ynh_script_progression "Create $app configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$install_dir/manage.py"
ynh_config_add --template="manage.py" --destination="$install_dir/manage.py"
chmod +x "$install_dir/manage.py"
ynh_add_config --template="settings.py" --destination="$install_dir/settings.py"
ynh_add_config --template="setup_user.py" --destination="$install_dir/setup_user.py"
ynh_add_config --template="urls.py" --destination="$install_dir/urls.py"
ynh_add_config --template="wsgi.py" --destination="$install_dir/wsgi.py"
ynh_config_add --template="settings.py" --destination="$install_dir/settings.py"
ynh_config_add --template="setup_user.py" --destination="$install_dir/setup_user.py"
ynh_config_add --template="urls.py" --destination="$install_dir/urls.py"
ynh_config_add --template="wsgi.py" --destination="$install_dir/wsgi.py"
touch "$install_dir/local_settings.py"
#=================================================
# MIGRATE / COLLECTSTATIC / CREATEADMIN
#=================================================
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
ynh_script_progression "migrate/collectstatic/createadmin..."
pushd "$install_dir"
# Just for debugging:
ynh_exec_as "$app" "$venvpython" ./manage.py diffsettings
ynh_exec_as_app "$venvpython" ./manage.py diffsettings
ynh_exec_as "$app" "$venvpython" ./manage.py migrate --no-input
ynh_exec_as "$app" "$venvpython" ./manage.py collectstatic --no-input
ynh_exec_as_app "$venvpython" ./manage.py migrate --no-input
ynh_exec_as_app "$venvpython" ./manage.py collectstatic --no-input
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
ynh_exec_as "$app" "$venvpython" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
ynh_exec_as_app "$venvpython" ./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" "$venvpython" ./manage.py check --deploy || true
ynh_exec_as_app "$venvpython" ./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
ynh_add_nginx_config
ynh_config_add_nginx
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_systemd_config --service="$app" --template="systemd.service"
ynh_config_add_systemd
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate "/var/log/$app/$app.log"
ynh_config_add_logrotate "/var/log/$app/$app.log"
#=================================================
# Start the app server via systemd
#=================================================
ynh_script_progression --message="Starting systemd service $app..." --weight=5
ynh_script_progression "Starting systemd service $app..."
ynh_systemd_action --service_name="$app" --action="start"
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

@ -1,33 +1,27 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
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 a service from the admin panel, added by `yunohost service add`
if yunohost service status "$app" >/dev/null 2>&1; then
yunohost service remove "$app"
fi
ynh_remove_logrotate
ynh_config_remove_logrotate
ynh_remove_systemd_config --service="$app"
ynh_config_remove_systemd
ynh_remove_nginx_config
ynh_config_remove_nginx
ynh_redis_remove_db "$redis_db"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,67 +1,58 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
chmod 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 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 POSTGRES 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
#=================================================
ynh_script_progression --message="Update Python virtualenv..." --weight=5
ynh_script_progression "Update Python virtualenv..."
python3 -m venv --upgrade --without-pip "$install_dir/venv"
#=================================================
# 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="Digital signage system for high schools" --log="/var/log/$app/$app.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
ynh_restore_file --origin_path="/var/log/$app/"
chmod o-rwx "/var/log/$app"
chown -R "$app:" "/var/log/$app"
ynh_restore "/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 | chmod o-rwx "/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:" "/var/log/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# 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

@ -7,113 +7,113 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# 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
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=admin_email --value="${admin}@${domain}"
if [ -z "${admin_email:-}" ]; then
admin_email="${admin}@${domain}"
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
ynh_app_setting_set --key=admin_email --value="$admin_email"
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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5
ynh_script_progression "Stopping systemd service '$app'..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="stop"
#=================================================
# PIP INSTALLATION
#=================================================
ynh_script_progression --message="Installing project via pip..." --weight=45
ynh_script_progression "Installing project via pip..."
# Always recreate everything fresh with current python version
ynh_secure_remove "$install_dir/venv"
ynh_safe_rm "$install_dir/venv"
_install_scovie_venv
chmod o-rwx "$install_dir"
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 | chmod 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"
#=================================================
# copy config files
# ================================================
ynh_script_progression --message="Create project configuration files..."
ynh_script_progression "Create project configuration files..."
ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_add_config --template="manage.py" --destination="$install_dir/manage.py"
ynh_config_add --template="manage.py" --destination="$install_dir/manage.py"
chmod +x "$install_dir/manage.py"
ynh_add_config --template="settings.py" --destination="$install_dir/settings.py"
ynh_add_config --template="setup_user.py" --destination="$install_dir/setup_user.py"
ynh_add_config --template="urls.py" --destination="$install_dir/urls.py"
ynh_add_config --template="wsgi.py" --destination="$install_dir/wsgi.py"
ynh_config_add --template="settings.py" --destination="$install_dir/settings.py"
ynh_config_add --template="setup_user.py" --destination="$install_dir/setup_user.py"
ynh_config_add --template="urls.py" --destination="$install_dir/urls.py"
ynh_config_add --template="wsgi.py" --destination="$install_dir/wsgi.py"
#=================================================
# MIGRATE PYINVENTORY
#=================================================
ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10
ynh_script_progression "migrate/collectstatic/createadmin..."
pushd "$install_dir"
# Just for debugging:
ynh_exec_as "$app" "$venvpython" ./manage.py diffsettings
ynh_exec_as_app "$venvpython" ./manage.py diffsettings
ynh_exec_as "$app" "$venvpython" ./manage.py migrate --no-input
ynh_exec_as "$app" "$venvpython" ./manage.py collectstatic --no-input
ynh_exec_as_app "$venvpython" ./manage.py migrate --no-input
ynh_exec_as_app "$venvpython" ./manage.py collectstatic --no-input
# Create/update Django superuser (set unusable password, because auth done via SSOwat):
ynh_exec_as "$app" "$venvpython" ./manage.py create_superuser --username="$admin" --email="$(ynh_user_get_info "$admin" mail)"
ynh_exec_as_app "$venvpython" ./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" "$venvpython" ./manage.py check --deploy || true
ynh_exec_as_app "$venvpython" ./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_config_add_systemd
ynh_add_systemd_config --service="$app" --template="systemd.service"
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
ynh_use_logrotate --non-append
ynh_config_add_logrotate
chmod o-rwx "$log_path"
chown -R "$app:" "$log_path"
#=================================================
# Start the app server via systemd
#=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
ynh_script_progression "Starting systemd service '$app'..."
ynh_systemd_action --service_name="$app" --action="start"
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"