1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 23:33:11 +02:00 committed by Alexandre Aubin
parent 283dc637b4
commit 1066801e58
8 changed files with 88 additions and 161 deletions

View file

@ -19,7 +19,8 @@ code = "https://github.com/spiral-project/ihatemoney"
demo = "https://ihatemoney.org/demo/"
[integration]
yunohost = ">= 11.1.21"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = false
@ -59,6 +60,7 @@ ram.runtime = "100M"
[resources.install_dir]
group = "www-data:r-x"
group = "www-data:r-x"
[resources.permissions]
main.url = "/"

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
pip_dependencies=(
@ -10,11 +10,6 @@ pip_dependencies=(
'PyMySQL>=0.9,<1.1'
)
#=================================================
# PERSONAL HELPERS
#=================================================
wait_gunicorn_start() {
# line_match isn't enough because ihatemoney may stop if database upgrades
for _ in {1..20}; do
@ -60,11 +55,3 @@ _hash_password() {
password=$1
python3 -c "$HASH_PASSWORD_PYTHON" "$password"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,31 +1,22 @@
#!/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 /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"
#=================================================
# 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"
#=================================================
# SPECIFIC BACKUP
@ -33,23 +24,23 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP LOG
#=================================================
ynh_backup --src_path="/var/log/$app" --is_big=1
ynh_backup "/var/log/$app"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_print_info "Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
ynh_mysql_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,31 +1,23 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."
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..."
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")
ynh_change_url_nginx_config
ynh_config_change_url_nginx
#=================================================
# SPECIFIC MODIFICATIONS
@ -39,24 +31,22 @@ domain="$new_domain"
# Allows to comment some config lines if not using sub path
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
chmod 640 "$install_dir/ihatemoney.cfg"
chown "$app:$app" "$install_dir/ihatemoney.cfg"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemctl --service="$app" --action="start"
wait_gunicorn_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

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -14,7 +8,7 @@ source /usr/share/yunohost/helpers
#=================================================
# BUILD VENV
#=================================================
ynh_script_progression --message="Building venv..." --weight=6
ynh_script_progression "Building venv..."
__ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}"
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")
@ -22,64 +16,61 @@ python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression "Configuring NGINX web server..."
# Create a dedicated NGINX config
## Needs $python_venv_site_packages
ynh_add_nginx_config
ynh_config_add_nginx
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_script_progression "Adding $app's configuration..."
# Secret key for cookies encryption.
secret_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
ynh_app_setting_set --key=secret_key --value="$secret_key"
hashed_password=$(_hash_password "$password")
ynh_app_setting_set --app="$app" --key=hashed_password --value="$hashed_password"
ynh_app_setting_set --key=hashed_password --value="$hashed_password"
# Allows to comment some config lines if not using sub path
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"
ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
chown -R "$app:www-data" "$install_dir"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
#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"
# Configure log directory
mkdir -p "/var/log/$app"
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"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression "Configuring $app's systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --line_match="Listening at"
ynh_systemctl --service="$app" --action="start" --wait_until="Listening at"
wait_gunicorn_start
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -14,30 +8,30 @@ source /usr/share/yunohost/helpers
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
ynh_script_progression --message="Removing $app service integration..." --weight=1
ynh_script_progression "Removing $app service integration..."
yunohost service remove "$app"
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
ynh_script_progression "Stopping and removing the systemd service..."
ynh_remove_systemd_config
ynh_config_remove_systemd
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
ynh_script_progression "Removing NGINX web server configuration..."
ynh_remove_nginx_config
ynh_config_remove_nginx
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
ynh_script_progression "Removing various files..."
# Remove the log files
@ -45,4 +39,4 @@ ynh_script_progression --message="Removing various files..." --weight=1
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/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 /usr/share/yunohost/helpers
@ -13,68 +7,65 @@ source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
ynh_script_progression "Restoring the app main directory..."
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"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
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 MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
ynh_script_progression "Restoring the MySQL database..."
ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
ynh_mysql_db_shell < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
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
#=================================================
# RESTORE LOG
#=================================================
ynh_restore_file --origin_path="/var/log/$app"
ynh_restore "/var/log/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --line_match="Listening at"
ynh_systemctl --service="$app" --action="start" --wait_until="Listening at"
wait_gunicorn_start
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
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
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,50 +1,36 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
ynh_script_progression "Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
if ynh_compare_current_package_version --comparison le --version "4.1.5~ynh2"; then
if ynh_app_upgrading_from_version_before_or_equal_to 4.1.5~ynh2; then
upgrade_from_opt=true
else
upgrade_from_opt=false
fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
if [[ "$upgrade_from_opt" == "false" ]]; then
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop"
ynh_systemctl --service="$app" --action="stop"
fi
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
ynh_script_progression "Ensuring downward compatibility..."
# MIGRATION: Remove old code (from pre-4.1.5 versions, not using venv)
if [[ "$upgrade_from_opt" == "true" ]]; then
# Remove legacy install dir
ynh_secure_remove /opt/yunohost/ihatemoney
ynh_safe_rm /opt/yunohost/ihatemoney
# Remove legacy Supervisor config
rm -f /etc/supervisor/conf.d/ihatemoney.conf
@ -57,97 +43,92 @@ if [[ "$upgrade_from_opt" == "true" ]]; then
fi
for old_file in "/etc/ihatemoney/ihatemoney.cfg" "/etc/$app/gunicorn.conf.py"; do
ynh_backup_if_checksum_is_different --file="$old_file"
ynh_delete_file_checksum --file="$old_file"
ynh_backup_if_checksum_is_different "$old_file"
ynh_delete_file_checksum "$old_file"
done
install_dir=/var/www/$app
ynh_app_setting_set --app="$app" --key=install_dir --value="$install_dir"
ynh_app_setting_set --key=install_dir --value="$install_dir"
db_name=ihatemoney
db_user=$db_name
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
ynh_app_setting_set --key=db_name --value="$db_name"
fi
# If secret_key doesn't exist, create it
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=secret_key --value=$(ynh_string_random --length=32)
if [ -z "${secret_key:-}" ]; then
secret_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
ynh_app_setting_set --key=secret_key --value="$secret_key"
fi
# If hashed_password doesn't exist, create it
if [ -z "${hashed_password:-}" ]; then
password=$(ynh_string_random --length=16)
hashed_password=$(_hash_password "$password")
ynh_app_setting_set --app="$app" --key=hashed_password --value="$hashed_password"
ynh_app_setting_set --key=hashed_password --value="$hashed_password"
fi
if [ ! -d "/var/log/$app" ]; then
# Configure log directory
mkdir -p "/var/log/$app"
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"
fi
#=================================================
# SPECIFIC UPGRADE
#=================================================
# BUILD VENV
#=================================================
ynh_script_progression --message="Building venv..." --weight=6
ynh_script_progression "Building venv..."
ynh_secure_remove --file="$install_dir/venv"
ynh_safe_rm "$install_dir/venv"
__ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}"
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
ynh_script_progression "Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
## Needs $python_venv_site_packages
ynh_add_nginx_config
ynh_config_add_nginx
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_script_progression "Updating configuration..."
# Allows to comment some config lines if not using sub path
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"
ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
chown -R "$app:www-data" "$install_dir"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
#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"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_script_progression "Upgrading systemd configuration..."
ynh_add_systemd_config
ynh_config_add_systemd
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --line_match="Listening at"
ynh_systemctl --service="$app" --action="start" --wait_until="Listening at"
wait_gunicorn_start
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"