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

Merge pull request #58 from YunoHost-Apps/version-2

Version 2
This commit is contained in:
Alexandre Aubin 2023-12-04 23:05:02 +01:00 committed by GitHub
commit 2e90ff40c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 116 additions and 224 deletions

View file

@ -5,7 +5,8 @@ It shall NOT be edited by hand.
# Borg Server for YunoHost
[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Working status](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Integration level](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Working status](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Install Borg Server with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver)
*[Lire ce readme en français.](./README_fr.md)*
@ -26,7 +27,7 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
* Official app website: <https://www.borgbackup.org/>
* Official admin documentation: <https://borgbackup.readthedocs.io/en/stable/>
* Upstream app code repository: <https://github.com/borgbackup/borg>
* YunoHost documentation for this app: <https://yunohost.org/app_borgserver>
* YunoHost Store: <https://apps.yunohost.org/app/borgserver>
* Report a bug: <https://github.com/YunoHost-Apps/borgserver_ynh/issues>
## Developer info

View file

@ -5,7 +5,8 @@ It shall NOT be edited by hand.
# Borg Server pour YunoHost
[![Niveau dintégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Niveau dintégration](https://dash.yunohost.org/integration/borgserver.svg)](https://dash.yunohost.org/appci/app/borgserver) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/borgserver.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/borgserver.maintain.svg)
[![Installer Borg Server avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=borgserver)
*[Read this readme in english.](./README.md)*
@ -26,7 +27,7 @@ The main goal of Borg is to provide an efficient and secure way to backup data.
* Site officiel de lapp : <https://www.borgbackup.org/>
* Documentation officielle de ladmin : <https://borgbackup.readthedocs.io/en/stable/>
* Dépôt de code officiel de lapp : <https://github.com/borgbackup/borg>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_borgserver>
* YunoHost Store: <https://apps.yunohost.org/app/borgserver>
* Signaler un bug : <https://github.com/YunoHost-Apps/borgserver_ynh/issues>
## Informations pour les développeurs

View file

@ -1,27 +0,0 @@
;; Test complet
; Manifest
ssh_user="sam"
public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
alert_delay=1
alert_mails="sam@domain.tld"
quota="1G"
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=0
setup_nourl=1
setup_private=0
setup_public=0
upgrade=1
upgrade=1 from_commit=c6ff77fc299c008b83cfe5f849b5d115989d5c49
backup_restore=1
multi_instance=1
port_already_use=0
change_url=0
;;; Options
Email=ljf+borg_ynh@reflexlibre.net
Notificatio
;;; Upgrade options
; commit=c6ff77fc299c008b83cfe5f849b5d115989d5c49
name=Merge pull request #26 from YunoHost-Apps/testing
manifest_arg=ssh_user=sam&public_key=ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC&quota=1G

64
manifest.toml Normal file
View file

@ -0,0 +1,64 @@
packaging_format = 2
id = "borgserver"
name = "Borg Server"
description.en = "Offer backup storage to a friend"
description.fr = "Offrez un espace de stockage à un⋅e ami⋅e"
version = "1.2.6~ynh1"
maintainers = ["ljf"]
[upstream]
license = "BSD-3-Clause"
website = "https://www.borgbackup.org/"
admindoc = "https://borgbackup.readthedocs.io/en/stable/"
code = "https://github.com/borgbackup/borg"
[integration]
yunohost = ">= 11.2"
architectures = "all"
multi_instance = true
ldap = "not_relevant"
sso = "not_relevant"
disk = "50M"
ram.build = "50M"
ram.runtime = "50M"
[install]
[install.ssh_user]
ask.en = "Indicate the SSH user to create"
ask.fr = "Indiquez l'utilisateur SSH à créer"
type = "string"
example = "john"
[install.public_key]
ask.en = "Indicate the public key given by borg_ynh app"
ask.fr = "Indiquez la clé publique donnée par l'app borg_ynh"
type = "string"
[install.alert_delay]
ask.en = "After which delay in days should we alert if there are no changes on repo ?"
ask.fr = "Après quel délais en jours devons-nous lancer une alerte si il n'y a pas de changement dans le repo ?"
type = "string"
default = "1"
[install.alert_mails]
ask.en = "Emails to whom send alerts ?"
ask.fr = "Emails des personnes à qui envoyer les alertes ?"
type = "string"
default = "root"
example = "camille@example.com,eden@example.com"
[install.quota]
ask.en = "Indicate the storage quota"
ask.fr = "Indiquez le quota de stockage"
type = "string"
optionnal = true
example = "30G"
[resources]
[resources.permissions]
[resources.apt]
packages = "python3-pip, python3-dev, libacl1-dev, libssl-dev, liblz4-dev, python3-jinja2, python3-setuptools, python3-venv, virtualenv, libfuse-dev, pkg-config"

View file

@ -1,13 +1,6 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# App package root directory should be the parent folder
PKG_DIR=$(cd ../; pwd)
BORG_VERSION=1.1.16
pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev python3-jinja2 python3-setuptools python3-venv virtualenv libfuse-dev pkg-config"
BORG_VERSION=1.2.6
# Install borg with pip if borg is not here
install_borg_with_pip () {
@ -26,31 +19,3 @@ install_borg_with_pip () {
# We need this to be executable by other borg apps
chmod a+x /usr/local/bin/borg
}
#=================================================
# COMMON HELPERS
#=================================================
ynh_export () {
local ynh_arg=""
for var in $@;
do
ynh_arg=$(echo "$var" | awk '{print toupper($0)}')
if [ "$var" == "path_url" ]; then
ynh_arg="PATH"
fi
ynh_arg="YNH_APP_ARG_$ynh_arg"
export $var="${!ynh_arg}"
done
}
# Save listed var in YunoHost app settings
# usage: ynh_save_args VARNAME1 [VARNAME2 [...]]
ynh_save_args () {
for var in $@;
do
local setting_var="$var"
if [ "$var" == "path_url" ]; then
setting_var="path"
fi
ynh_app_setting_set $app $setting_var "${!var}"
done
}

View file

@ -1,28 +1,7 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
export ssh_user="$(ynh_app_setting_get $app ssh_user)"
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================

View file

@ -9,80 +9,50 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
export app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
ynh_export ssh_user public_key quota alert_delay alert_mails
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
# Here is a small hack to avoid multi install CI test to fail due
# to same ssh_user provided
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] && [[ "$YNH_APP_INSTANCE_NUMBER" != "1" ]] ; then
ssh_user+="$YNH_APP_INSTANCE_NUMBER"
fi
ynh_system_user_exists --username=$ssh_user && ynh_die --message="This user already exists"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_save_args ssh_user public_key quota alert_delay alert_mails
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
install_borg_with_pip
#=================================================
# CREATE SSH USER USED BY BORG
#=================================================
ynh_script_progression --message="Creating SSH user used by Borg..."
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
#=================================================
# AUTORIZE SSH FOR THIS USER
#=================================================
ynh_script_progression --message="Configuring SSH public key for remote connexion..."
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
home=/home/$ssh_user
mkdir -p /home/$ssh_user/.ssh
chmod o=--- /home/$ssh_user
chown -R $ssh_user:$ssh_user /home/$ssh_user
touch /home/$ssh_user/.ssh/authorized_keys
mkdir -p $home/.ssh
chmod o=--- $home
chown -R $ssh_user:$ssh_user $home
touch $home/.ssh/authorized_keys
extra="--storage-quota $quota"
if [ "$quota" = "" ]; then
extra=""
fi
echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys
#=================================================
# AVOID BACKUP OF BACKUP
#=================================================
ynh_script_progression --message="Avoiding to backup the backup itself..."
echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys
# Tweak to prevent the backup of the backup itself
touch $home/.nobackup
#=================================================
# SETUP CRON
#=================================================
ynh_script_progression --message="Configuring cron to monitor backup..."
ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app"
#=================================================

View file

@ -9,20 +9,11 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get $app ssh_user)
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies
# Remove borg if we are removing the last borg app on the system
if [ "$(yunohost app list | grep "id: borg" | wc -l)" == "1" ] ; then
ynh_secure_remove "/opt/borg-env"
@ -34,11 +25,13 @@ fi
#=================================================
# We keep files cause we don't know what the user want to do about
# backups stored in the home directory
ynh_system_user_delete --username=$ssh_user
#=================================================
# REMOVE CRON FILES
#=================================================
ynh_secure_remove "/etc/cron.d/$app"
#=================================================

View file

@ -9,58 +9,35 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
export ssh_user=$(ynh_app_setting_get $app ssh_user)
export public_key=$(ynh_app_setting_get $app public_key)
export quota=$(ynh_app_setting_get $app quota)
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
ynh_script_progression --message="Reinstalling borg env..."
ynh_install_app_dependencies $pkg_dependencies
install_borg_with_pip
#=================================================
# CREATE SSH USER USED BY BORG
#=================================================
ynh_script_progression --message="Creating SSH user used by Borg..."
ynh_script_progression --message="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
#=================================================
# AUTORIZE SSH FOR THIS USER
#=================================================
home=/home/$ssh_user
mkdir -p /home/$ssh_user/.ssh
chmod o=--- /home/$ssh_user
chown -R $ssh_user:$ssh_user /home/$ssh_user
touch /home/$ssh_user/.ssh/authorized_keys
mkdir -p $home/.ssh
chmod o=--- $home
extra="--storage-quota $quota"
if [ "$quota" = "" ]; then
extra=""
fi
echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys
#=================================================
# AVOID BACKUP OF BACKUP
#=================================================
echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys
chown -R $ssh_user:$ssh_user $home
# Tweak to prevent the backup of the backup itself
touch $home/.nobackup
# Actual restore of ...?
ynh_restore
#=================================================

View file

@ -9,38 +9,12 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
ssh_user=$(ynh_app_setting_get --app=$app --key=ssh_user)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
alert_delay=$(ynh_app_setting_get --app=$app --key=alert_delay)
alert_mails=$(ynh_app_setting_get --app=$app --key=alert_mails)
quota=$(ynh_app_setting_get --app=$app --key=quota)
#=================================================
# CHECK IF AN UPGRADE IS NEEDED
#=================================================
ynh_check_app_version_changed
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# We don't backup before upgrade cause we don't want accidental
# remove of repo if upgrade failed
#ynh_backup_before_upgrade
#ynh_clean_setup () {
# # restore it if the upgrade fails
# ynh_restore_upgradebackup
#}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -56,7 +30,7 @@ if [ -f "/etc/yunohost/hooks.d/backup/17-data_home" ]; then
fi
# Fix broken value ssh_user that mistakenly got replaced by the public key in previous versions...
[ -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 :( !"
if echo "$ssh_user" | grep -q ' '; then
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 :( !"
@ -68,7 +42,7 @@ if echo "$public_key" | grep -q -v ' '; then
fi
# 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 --app=$app --key=alert_mails --value="root"
fi
@ -78,20 +52,6 @@ if [ ! -f "/opt/borg-env/$(ynh_get_debian_release)" ] ; then
ynh_secure_remove /opt/borg-env
fi
#=================================================
# CREATE SSH USER USED BY BORG
#=================================================
ynh_script_progression --message="Creating SSH user used by Borg..."
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
@ -104,28 +64,28 @@ install_borg_with_pip
#=================================================
# AUTORIZE SSH FOR THIS USER
#=================================================
ynh_script_progression --message="Seting good permissions..."
ynh_script_progression --message="Making sure SSH user exists with appropriate permissions..."
mkdir -p /home/$ssh_user/.ssh
chmod o=--- /home/$ssh_user
ynh_system_user_create --username=$ssh_user --home_dir=/home/$ssh_user --use_shell --groups ssh.app
home=/home/$ssh_user
mkdir -p $home/.ssh
chmod o=--- $home
extra="--storage-quota $quota"
if [ "$quota" = "" ]; then
extra=""
fi
echo "command=\"borg serve $extra --restrict-to-repository /home/$ssh_user/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> /home/$ssh_user/.ssh/authorized_keys
chown -R $ssh_user:$ssh_user /home/$ssh_user
echo "command=\"borg serve $extra --restrict-to-repository $home/backup\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc $public_key" >> $home/.ssh/authorized_keys
chown -R $ssh_user:$ssh_user $home
#=================================================
# AVOID BACKUP OF BACKUP
#=================================================
ynh_script_progression --message="Avoiding to backup the backup itself..."
touch /home/$ssh_user/.nobackup
# Tweak to prevent the backup of the backup itself
touch $home/.nobackup
#=================================================
# SETUP CRON
#=================================================
ynh_script_progression --message="Configuring cron to monitor backup..."
ynh_add_config --template="monitor-backup" --destination="/etc/cron.d/$app"
#=================================================

9
tests.toml Normal file
View file

@ -0,0 +1,9 @@
test_format = 1.0
[default]
args.ssh_user = "sam"
args.public_key = "ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
args.alert_delay = 1
args.alert_mails = "sam@domain.tld"
args.quota = "1G"