mirror of
https://github.com/YunoHost-Apps/borgserver_ynh.git
synced 2024-09-03 20:36:20 +02:00
Merge 6d35fd35e2
into 5db0a7ae07
This commit is contained in:
commit
731b6f0f56
7 changed files with 49 additions and 93 deletions
|
@ -18,7 +18,8 @@ admindoc = "https://borgbackup.readthedocs.io/en/stable/"
|
||||||
code = "https://github.com/borgbackup/borg"
|
code = "https://github.com/borgbackup/borg"
|
||||||
|
|
||||||
[integration]
|
[integration]
|
||||||
yunohost = ">= 11.2"
|
yunohost = ">= 11.2.18"
|
||||||
|
helpers_version = "2.1"
|
||||||
architectures = "all"
|
architectures = "all"
|
||||||
multi_instance = true
|
multi_instance = true
|
||||||
ldap = "not_relevant"
|
ldap = "not_relevant"
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# COMMON VARIABLES
|
# COMMON VARIABLES AND CUSTOM HELPERS
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# PERSONAL HELPERS
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
install_borg_with_pip() {
|
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"
|
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)
|
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"
|
||||||
|
|
||||||
# Make venv accessible for every user
|
# Make venv accessible for every user
|
||||||
chmod a+rX "$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 a+rX "$install_dir"
|
||||||
chmod a+rX -R "$install_dir/venv"
|
#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 | chmod a+rX -R "$install_dir/venv"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_ssh_config() {
|
create_ssh_config() {
|
||||||
|
@ -39,11 +35,3 @@ create_ssh_config() {
|
||||||
chown -R "$ssh_user:$ssh_user" "$ssh_dir"
|
chown -R "$ssh_user:$ssh_user" "$ssh_dir"
|
||||||
chmod -R u=rwX,go=--- "$ssh_dir"
|
chmod -R u=rwX,go=--- "$ssh_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# EXPERIMENTAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FUTURE OFFICIAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
|
@ -1,41 +1,32 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
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 DATA DIR
|
# BACKUP THE DATA DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/home/$ssh_user/.ssh"
|
ynh_backup "/home/$ssh_user/.ssh"
|
||||||
ynh_backup --src_path="/home/$ssh_user/.nobackup"
|
ynh_backup "/home/$ssh_user/.nobackup"
|
||||||
|
|
||||||
ynh_print_info --message="Borg backup repo in /home/$ssh_user/ won't be backup to avoid backup of backup loop issue."
|
ynh_print_info "Borg backup repo in /home/$ssh_user/ won't be backup to avoid backup of backup loop issue."
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP VARIOUS FILES
|
# BACKUP VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/cron.d/$app"
|
ynh_backup "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# 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)."
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -14,23 +8,23 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# Here is a small hack to avoid multi install CI test to fail due
|
# Here is a small hack to avoid multi install CI test to fail due
|
||||||
# to same ssh_user provided
|
# to same ssh_user provided
|
||||||
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] && [[ "$YNH_APP_INSTANCE_NUMBER" != "1" ]] ; then
|
if ynh_in_ci_tests ; then
|
||||||
ssh_user+="$YNH_APP_INSTANCE_NUMBER"
|
ssh_user+="$YNH_APP_INSTANCE_NUMBER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_system_user_exists --username="$ssh_user" && ynh_die --message="This user already exists"
|
ynh_system_user_exists --username="$ssh_user" && ynh_die "This user already exists"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL BORG
|
# INSTALL BORG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Borg..."
|
ynh_script_progression "Installing Borg..."
|
||||||
|
|
||||||
install_borg_with_pip
|
install_borg_with_pip
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# AUTORIZE SSH FOR THIS USER
|
# AUTORIZE SSH FOR THIS USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring user and SSH public key for remote connexion..."
|
ynh_script_progression "Configuring user and SSH public key for remote connexion..."
|
||||||
|
|
||||||
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
||||||
mkdir -p "/home/$ssh_user"
|
mkdir -p "/home/$ssh_user"
|
||||||
|
@ -45,14 +39,14 @@ create_ssh_config "/home/$ssh_user/.ssh" "/home/$ssh_user/backup"
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring cron to monitor backup..."
|
ynh_script_progression "Configuring cron to monitor backup..."
|
||||||
|
|
||||||
ynh_add_config --template="monitor-backup.cron" --destination="/etc/cron.d/$app"
|
ynh_config_add --template="monitor-backup.cron" --destination="/etc/cron.d/$app"
|
||||||
ynh_add_config --template="monitor-backup.sh" --destination="$install_dir/monitor-backup.sh"
|
ynh_config_add --template="monitor-backup.sh" --destination="$install_dir/monitor-backup.sh"
|
||||||
chmod +x "$install_dir/monitor-backup.sh"
|
chmod +x "$install_dir/monitor-backup.sh"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Installation of $app completed" --last
|
ynh_script_progression "Installation of $app completed"
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -21,10 +15,10 @@ ynh_system_user_delete --username="$ssh_user"
|
||||||
# REMOVE CRON FILES
|
# REMOVE CRON FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_secure_remove "/etc/cron.d/$app"
|
ynh_safe_rm "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Removal of $app completed" --last
|
ynh_script_progression "Removal of $app completed"
|
||||||
|
|
|
@ -1,43 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
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=1
|
ynh_script_progression "Restoring the app main directory..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="$install_dir"
|
ynh_restore "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE DATA DIRECTORY
|
# RESTORE THE DATA DIRECTORY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the user and SSH configuration..." --weight=1
|
ynh_script_progression "Restoring the user and SSH configuration..."
|
||||||
|
|
||||||
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
||||||
mkdir -p "/home/$ssh_user"
|
mkdir -p "/home/$ssh_user"
|
||||||
chmod 700 "/home/$ssh_user"
|
chmod 700 "/home/$ssh_user"
|
||||||
chown "$ssh_user" "/home/$ssh_user"
|
chown "$ssh_user" "/home/$ssh_user"
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/home/$ssh_user/.ssh"
|
ynh_restore "/home/$ssh_user/.ssh"
|
||||||
ynh_restore_file --origin_path="/home/$ssh_user/.nobackup"
|
ynh_restore "/home/$ssh_user/.nobackup"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE SYSTEM CONFIGURATIONS
|
# 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/cron.d/$app"
|
ynh_restore "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Restoration completed for $app" --last
|
ynh_script_progression "Restoration completed for $app"
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
#!/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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Ensuring downward compatibility..."
|
ynh_script_progression "Ensuring downward compatibility..."
|
||||||
|
|
||||||
# Remove legacy stuff
|
# Remove legacy stuff
|
||||||
if [ -f "/etc/apt/sources.list.d/$app-stretch-backports.list" ]; then
|
if [ -f "/etc/apt/sources.list.d/$app-stretch-backports.list" ]; then
|
||||||
ynh_secure_remove "/etc/apt/sources.list.d/$app-stretch-backports.list"
|
ynh_safe_rm "/etc/apt/sources.list.d/$app-stretch-backports.list"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then
|
if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then
|
||||||
ynh_secure_remove "/etc/yunohost/hooks.d/backup/17-data_home"
|
ynh_safe_rm "/etc/yunohost/hooks.d/backup/17-data_home"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clear legacy stuff
|
# Clear legacy stuff
|
||||||
if [ -d /opt/borg-env ]; then
|
if [ -d /opt/borg-env ]; then
|
||||||
ynh_secure_remove --file="/opt/borg-env"
|
ynh_safe_rm "/opt/borg-env"
|
||||||
ynh_secure_remove --file="/usr/local/bin/borg"
|
ynh_safe_rm "/usr/local/bin/borg"
|
||||||
ynh_secure_remove --file="/usr/local/bin/backup-with-borg"
|
ynh_safe_rm "/usr/local/bin/backup-with-borg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fix broken value ssh_user that mistakenly got replaced by the public key in previous versions...
|
# Fix broken value ssh_user that mistakenly got replaced by the public key in previous versions...
|
||||||
|
@ -35,30 +29,30 @@ fi
|
||||||
if echo "$ssh_user" | grep -q ' '; then
|
if echo "$ssh_user" | grep -q ' '; then
|
||||||
ssh_user=$(grep "$ssh_user" /home/*/.ssh/authorized_keys | grep borg | cut -d/ -f3)
|
ssh_user=$(grep "$ssh_user" /home/*/.ssh/authorized_keys | grep borg | cut -d/ -f3)
|
||||||
[ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !"
|
[ -n "$ssh_user" ] || ynh_die "Unable to retrieve ssh_user please fix /etc/yunohost/apps/$app/settings.yml manually :( !"
|
||||||
ynh_app_setting_set --app="$app" --key=ssh_user --value="$ssh_user"
|
ynh_app_setting_set --key=ssh_user --value="$ssh_user"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$public_key" | grep -q -v ' '; then
|
if echo "$public_key" | grep -q -v ' '; then
|
||||||
ynh_app_setting_set --app="$app" --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' "/home/$ssh_user/.ssh/authorized_keys")"
|
ynh_app_setting_set --key=public_key --value="$(grep -Po 'no-user-rc \K.*$' "/home/$ssh_user/.ssh/authorized_keys")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Alert delay and alert mail missing
|
# Alert delay and alert mail missing
|
||||||
if [ -z "${alert_delay:-}" ]; then
|
if [ -z "${alert_delay:-}" ]; then
|
||||||
ynh_app_setting_set --app="$app" --key=alert_delay --value="1"
|
ynh_app_setting_set --key=alert_delay --value="1"
|
||||||
ynh_app_setting_set --app="$app" --key=alert_mails --value="root"
|
ynh_app_setting_set --key=alert_mails --value="root"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPGRADE BORG
|
# UPGRADE BORG
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading Borg..." --weight=1
|
ynh_script_progression "Upgrading Borg..."
|
||||||
|
|
||||||
install_borg_with_pip
|
install_borg_with_pip
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# AUTORIZE SSH FOR THIS USER
|
# AUTORIZE SSH FOR THIS USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Making sure SSH user exists with appropriate permissions..."
|
ynh_script_progression "Making sure SSH user exists with appropriate permissions..."
|
||||||
|
|
||||||
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
ynh_system_user_create --username="$ssh_user" --home_dir="/home/$ssh_user" --use_shell --groups ssh.app
|
||||||
mkdir -p "/home/$ssh_user"
|
mkdir -p "/home/$ssh_user"
|
||||||
|
@ -73,14 +67,14 @@ create_ssh_config "/home/$ssh_user/.ssh" "/home/$ssh_user/backup"
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring cron to monitor backup..."
|
ynh_script_progression "Configuring cron to monitor backup..."
|
||||||
|
|
||||||
ynh_add_config --template="monitor-backup.cron" --destination="/etc/cron.d/$app"
|
ynh_config_add --template="monitor-backup.cron" --destination="/etc/cron.d/$app"
|
||||||
ynh_add_config --template="monitor-backup.sh" --destination="$install_dir/monitor-backup.sh"
|
ynh_config_add --template="monitor-backup.sh" --destination="$install_dir/monitor-backup.sh"
|
||||||
chmod +x "$install_dir/monitor-backup.sh"
|
chmod +x "$install_dir/monitor-backup.sh"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
ynh_script_progression "Upgrade of $app completed"
|
||||||
|
|
Loading…
Add table
Reference in a new issue