1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/borg_ynh.git synced 2024-09-03 18:16:05 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-30 22:42:02 +02:00 committed by Alexandre Aubin
parent f752f415d9
commit e9a7d39212
8 changed files with 84 additions and 134 deletions

View file

@ -18,7 +18,8 @@ cpe = "cpe:2.3:a:borg_project:borg"
fund = "https://www.borgbackup.org/support/fund.html"
[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = "not_relevant"

View file

@ -1,21 +1,17 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
install_borg_with_pip () {
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 setuptools wheel
ynh_exec_as_app "$venvpy" -m pip install --upgrade setuptools wheel
BORG_VERSION=$(ynh_app_upstream_version)
ynh_exec_as "$app" "$venvpy" -m pip install borgbackup[pyfuse3]=="$BORG_VERSION"
ynh_exec_as_app "$venvpy" -m pip install borgbackup[pyfuse3]=="$BORG_VERSION"
}
_gen_and_save_public_key() {
@ -29,13 +25,5 @@ _gen_and_save_public_key() {
public_key=$(cat "$private_key.pub")
fi
ynh_app_setting_set --app="$app" --key=public_key --value="$public_key"
ynh_app_setting_set --key=public_key --value="$public_key"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,32 +1,23 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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..."
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.timer"
ynh_backup "/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.timer"
ynh_backup --src_path="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_backup "/etc/sudoers.d/$app"
ynh_backup --src_path="/root/.ssh/id_${app}_ed25519" --not_mandatory
ynh_backup --src_path="/root/.ssh/id_${app}_ed25519.pub" --not_mandatory
ynh_backup "/root/.ssh/id_${app}_ed25519" || true
ynh_backup "/root/.ssh/id_${app}_ed25519.pub" || true
ynh_backup --src_path="$install_dir/backup-with-borg"
ynh_backup --src_path="$install_dir/logging.conf"
ynh_backup "$install_dir/backup-with-borg"
ynh_backup "$install_dir/logging.conf"
#=================================================
# 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

@ -2,7 +2,7 @@
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
borg="$install_dir/venv/bin/borg"
@ -49,12 +49,12 @@ get__data_multimedia() {
get__last_backups() {
cat << EOF
ask: |-
$(BORG_PASSPHRASE="$(ynh_app_setting_get $app passphrase)" BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes " "$borg" list --short --last 50 ${old[repository]} | sed 's/^/ /g' 2> /dev/null)
$(BORG_PASSPHRASE="$(ynh_app_setting_get $app passphrase)" BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes " "$borg" list --short 50 ${old[repository]} | sed 's/^/ /g' 2> /dev/null)
EOF
}
get__conf() {
ynh_app_setting_get --app=$app --key=conf
ynh_app_setting_get --key=conf
}
#=================================================
@ -75,7 +75,7 @@ set__data_multimedia() {
mkdir -p /home/yunohost.multimedia/
touch /home/yunohost.multimedia/.nobackup
else
ynh_secure_remove /home/yunohost.multimedia/.nobackup
ynh_safe_rm /home/yunohost.multimedia/.nobackup
fi
}
@ -83,11 +83,9 @@ set__conf() {
if [ -n "${conf}" ]
then
# Update the config of the app
ynh_app_setting_set --app=$app --key=conf --value=$conf
ynh_app_setting_set --key=conf --value=$conf
fi
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -26,67 +20,67 @@ else
server=""
fi
ynh_app_setting_set --app=$app --key=ssh_user --value="$ssh_user"
ynh_app_setting_set --app=$app --key=server --value="$server"
ynh_app_setting_set --key=ssh_user --value="$ssh_user"
ynh_app_setting_set --key=server --value="$server"
state="repository uncreated"
ynh_app_setting_set --app=$app --key=state --value="$state"
ynh_app_setting_set --key=state --value="$state"
last_run="-"
ynh_app_setting_set --app=$app --key=last_run --value="$last_run"
ynh_app_setting_set --key=last_run --value="$last_run"
# passwords aren't saved by default
ynh_app_setting_set --app=$app --key=passphrase --value="$passphrase"
ynh_app_setting_set --key=passphrase --value="$passphrase"
#=================================================
# INSTALL BORG
#=================================================
ynh_script_progression --message="Installing Borg..."
ynh_script_progression "Installing Borg..."
install_borg_with_pip
_gen_and_save_public_key
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
chmod u+w "/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"
#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 u+w "/var/log/$app"
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP THE BACKUP METHOD
#=================================================
ynh_script_progression --message="Setting up backup method..." --weight=1
ynh_script_progression "Setting up backup method..."
mkdir -p /etc/yunohost/hooks.d/backup
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
ynh_add_config --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_config_add --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_add_config --template="backup-with-borg" --destination="$install_dir/backup-with-borg"
ynh_config_add --template="backup-with-borg" --destination="$install_dir/backup-with-borg"
chmod u+x "$install_dir/backup-with-borg"
chown "$app:$app" "$install_dir/backup-with-borg"
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
chown root:root "/etc/sudoers.d/$app"
ynh_config_add --template="sudoer" --destination="/etc/sudoers.d/$app"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root:root "/etc/sudoers.d/$app"
ynh_add_config --template="logging.conf" --destination="$install_dir/logging.conf"
ynh_config_add --template="logging.conf" --destination="$install_dir/logging.conf"
chown "$app:$app" "$install_dir/logging.conf"
#=================================================
# 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 systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add $app --description="Deduplicating backup program" --test_status="systemctl show $app.service -p ActiveState --value | grep -v failed" --log "/var/log/$app/borg.log"
# Disable the service, this is to prevent the service from being triggered at boot time
systemctl disable $app.service --quiet
# Configure the systemd timer
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
ynh_config_add --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet
systemctl start $app.timer
@ -94,4 +88,4 @@ systemctl start $app.timer
# 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,25 +8,25 @@ source /usr/share/yunohost/helpers
#=================================================
# 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
ynh_script_progression --message="Removing $app service integration..."
if ynh_hide_warnings yunohost service status $app >/dev/null; then
ynh_script_progression "Removing $app service integration..."
yunohost service remove $app
fi
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
ynh_script_progression "Removing system configurations related to $app..."
systemctl stop $app.timer
systemctl disable $app.timer --quiet
ynh_remove_systemd_config
ynh_config_remove_systemd
ynh_secure_remove "/etc/systemd/system/$app.timer"
ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_safe_rm "/etc/systemd/system/$app.timer"
ynh_safe_rm "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,60 +1,54 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# INSTALL BORG
#=================================================
ynh_script_progression --message="Reinstalling Borg..."
ynh_script_progression "Reinstalling Borg..."
install_borg_with_pip
_gen_and_save_public_key
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
chmod u+w "/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"
#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 u+w "/var/log/$app"
#=================================================
# ACTIVATE BACKUP METHODS
#=================================================
ynh_script_progression --message="Setting up backup method..." --weight=1
ynh_script_progression "Setting up backup method..."
mkdir -p /etc/yunohost/hooks.d/backup
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
ynh_restore_file --origin_path="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_restore "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
chown root:root "/etc/sudoers.d/$app"
ynh_restore "/etc/sudoers.d/$app"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root:root "/etc/sudoers.d/$app"
ynh_restore_file --origin_path="$install_dir/backup-with-borg"
ynh_restore "$install_dir/backup-with-borg"
chmod u+x "$install_dir/backup-with-borg"
chown "$app:$app" "$install_dir/backup-with-borg"
ynh_restore_file --origin_path="$install_dir/logging.conf"
ynh_restore "$install_dir/logging.conf"
chown "$app:$app" "$install_dir/logging.conf"
#=================================================
# 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/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
yunohost service add $app --description="Deduplicating backup program" --test_status="systemctl show $app.service -p ActiveState --value | grep -v failed" --log "/var/log/$app/borg.log"
# Disable the service, this is to prevent the service from being triggered at boot time
systemctl disable $app.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app.timer"
ynh_restore "/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet
systemctl start $app.timer
@ -62,4 +56,4 @@ systemctl start $app.timer
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,38 +1,28 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# 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" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app.timer --action="stop"
ynh_systemctl --service=$app --action="stop"
ynh_systemctl --service=$app.timer --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
ynh_script_progression "Ensuring downward compatibility..."
if [[ "${mailalert:-}" != "always" && "${mailalert:-}" != "errors_only" && "${mailalert:-}" != "never" ]]; then
ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only"
ynh_app_setting_set --key="mailalert" --value="errors_only"
export mailalert="errors_only"
fi
ynh_app_setting_set --app=$app --key="state" --value="not run since last update"
ynh_app_setting_set --app=$app --key="last_run" --value="-"
ynh_app_setting_set --key="state" --value="not run since last update"
ynh_app_setting_set --key="last_run" --value="-"
if [ -z "$repository" ]; then
repository="ssh://$ssh_user@$server/~/backup"
@ -56,58 +46,58 @@ fi
# Clear legacy stuff
if [ -d /opt/borg-env ]; then
ynh_secure_remove --file="/opt/borg-env"
ynh_secure_remove --file="/usr/local/bin/borg"
ynh_secure_remove --file="/usr/local/bin/backup-with-borg"
ynh_safe_rm "/opt/borg-env"
ynh_safe_rm "/usr/local/bin/borg"
ynh_safe_rm "/usr/local/bin/backup-with-borg"
fi
#=================================================
# UPGRADE BORG
#=================================================
ynh_script_progression --message="Upgrading Borg..." --weight=1
ynh_script_progression "Upgrading Borg..."
install_borg_with_pip
_gen_and_save_public_key
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
chmod u+w "/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"
#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 u+w "/var/log/$app"
#=================================================
# SETUP THE BACKUP METHOD
#=================================================
ynh_script_progression --message="Setting up backup method..." --weight=1
ynh_script_progression "Setting up backup method..."
mkdir -p /etc/yunohost/hooks.d/backup
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
ynh_add_config --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_config_add --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
ynh_add_config --template="backup-with-borg" --destination="$install_dir/backup-with-borg"
ynh_config_add --template="backup-with-borg" --destination="$install_dir/backup-with-borg"
chmod u+x "$install_dir/backup-with-borg"
chown "$app:$app" "$install_dir/backup-with-borg"
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
chown root:root "/etc/sudoers.d/$app"
ynh_config_add --template="sudoer" --destination="/etc/sudoers.d/$app"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root:root "/etc/sudoers.d/$app"
ynh_add_config --template="logging.conf" --destination="$install_dir/logging.conf"
ynh_config_add --template="logging.conf" --destination="$install_dir/logging.conf"
chown "$app:$app" "$install_dir/logging.conf"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_script_progression "Upgrading system configurations related to $app..."
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add $app --description="Deduplicating backup program" --test_status="systemctl show $app.service -p ActiveState --value | grep -v failed" --log "/var/log/$app/borg.log"
# Disable the service, this is to prevent the service from being triggered at boot time
systemctl disable $app.service --quiet
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
ynh_config_add --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
systemctl enable $app.timer --quiet
systemctl start $app.timer
@ -115,4 +105,4 @@ systemctl start $app.timer
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"