mirror of
https://github.com/YunoHost-Apps/borgserver_ynh.git
synced 2024-09-03 20:36:20 +02:00
[enh] Setup storage for friend (untested)
This commit is contained in:
parent
0eefe37645
commit
e59dabbb81
9 changed files with 322 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# borgserver_ynh
|
||||||
|
Offer backup storage to a friend
|
||||||
|
|
21
conf/17-data_home
Normal file
21
conf/17-data_home
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit hook on subcommand error or unset variable
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# Source YNH helpers
|
||||||
|
source /usr/share/yunohost/helpers.d/filesystem
|
||||||
|
|
||||||
|
# Backup destination
|
||||||
|
backup_dir="\${1}/data/home"
|
||||||
|
|
||||||
|
# Backup user home
|
||||||
|
for f in \$(find /home/* -type d -prune | awk -F/ '{print \$NF}'); do
|
||||||
|
if [[ ! "\$f" =~ ^yunohost|lost\+found ]]; then
|
||||||
|
if [ ! -e "/home/\$f/.nobackup" ]; then
|
||||||
|
ynh_backup "/home/\$f" "${backup_dir}/\$f" 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
EOF
|
||||||
|
|
41
manifest.json
Normal file
41
manifest.json
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"name": "Borg Server",
|
||||||
|
"id": "borgserver",
|
||||||
|
"packaging_format": 1,
|
||||||
|
"description": {
|
||||||
|
"en": "Offer backup storage to a friend.",
|
||||||
|
"fr": "Offrez un espace de stockage à un⋅e ami⋅e."
|
||||||
|
},
|
||||||
|
"version": "1.0",
|
||||||
|
"url": "https://borgbackup.readthedocs.io",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"maintainer": {
|
||||||
|
"name": "ljf",
|
||||||
|
"email": "ljf+borg_ynh@reflexlibre.net",
|
||||||
|
"url": "https://reflexlibre.net"
|
||||||
|
},
|
||||||
|
"requirements": {
|
||||||
|
"yunohost": ">= 2.7.2"
|
||||||
|
},
|
||||||
|
"multi_instance": true,
|
||||||
|
"services": [],
|
||||||
|
"arguments": {
|
||||||
|
"install" : [
|
||||||
|
{
|
||||||
|
"name": "ssh_user",
|
||||||
|
"ask": {
|
||||||
|
"en": "Indicate the ssh user to create",
|
||||||
|
"fr": "Indiquez l'utilisateur ssh à créer"
|
||||||
|
},
|
||||||
|
"example": "john"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "public_key",
|
||||||
|
"ask": {
|
||||||
|
"en": "Indicate the public key given by borg_ynh app",
|
||||||
|
"fr": "Indiquez la clé publique donnée par l'app borg_ynh"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
60
scripts/_common.sh
Normal file
60
scripts/_common.sh
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# COMMON VARIABLES
|
||||||
|
#=================================================
|
||||||
|
# App package root directory should be the parent folder
|
||||||
|
PKG_DIR=$(cd ../; pwd)
|
||||||
|
|
||||||
|
pkg_dependencies="python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
# Render templates with Jinja2
|
||||||
|
#
|
||||||
|
# Attention : Variables should be exported before calling this helper to be
|
||||||
|
# accessible inside templates.
|
||||||
|
#
|
||||||
|
# usage: ynh_render_template some_template output_path
|
||||||
|
# | arg: some_template - Template file to be rendered
|
||||||
|
# | arg: output_path - The path where the output will be redirected to
|
||||||
|
ynh_render_template() {
|
||||||
|
local template_path=$1
|
||||||
|
local output_path=$2
|
||||||
|
# Taken from https://stackoverflow.com/a/35009576
|
||||||
|
python2.7 -c 'import os, sys, jinja2; sys.stdout.write(
|
||||||
|
jinja2.Template(sys.stdin.read()
|
||||||
|
).render(os.environ));' < $template_path > $output_path
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_configure () {
|
||||||
|
ynh_backup_if_checksum_is_different $2
|
||||||
|
ynh_configure "${PKG_DIR}/conf/$1.j2" $2
|
||||||
|
ynh_store_file_checksum $2
|
||||||
|
}
|
24
scripts/backup
Executable file
24
scripts/backup
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
|
58
scripts/install
Executable file
58
scripts/install
Executable file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
ynh_save_args ssh_user public_key
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
pip3 install setuptools --upgrade
|
||||||
|
pip3 install borgbackup
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE SSH USER USED BY BORG
|
||||||
|
#=================================================
|
||||||
|
adduser $ssh_user -s /bin/bash --disabled-password
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# AUTORIZE SSH FOR THIS USER
|
||||||
|
#=================================================
|
||||||
|
home=/home/$ssh_user
|
||||||
|
mkdir -p /home/$ssh_user/.ssh
|
||||||
|
touch /home/$ssh_user/.ssh/authorized_keys
|
||||||
|
echo "command=\"borg serve --restrict-to-path /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
|
||||||
|
#=================================================
|
||||||
|
touch $home/.nobackup
|
||||||
|
mkdir -p /etc/yunohost/hooks.d/backup
|
||||||
|
cp -f ../conf/17-data_home /etc/yunohost/hooks.d/backup/17-data_home
|
||||||
|
|
26
scripts/remove
Executable file
26
scripts/remove
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
ssh_user=$(ynh_app_setting_get $app ssh_user)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE FILES
|
||||||
|
#=================================================
|
||||||
|
userdel $ssh_user
|
59
scripts/restore
Executable file
59
scripts/restore
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ ! -e _common.sh ]; then
|
||||||
|
# Get the _common.sh file if it's not in the current directory
|
||||||
|
cp ../settings/scripts/_common.sh ./_common.sh
|
||||||
|
chmod a+rx _common.sh
|
||||||
|
fi
|
||||||
|
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
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
pip3 install setuptools --upgrade
|
||||||
|
pip3 install borgbackup
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE SSH USER USED BY BORG
|
||||||
|
#=================================================
|
||||||
|
adduser $ssh_user -s /bin/bash --disabled-password
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# AUTORIZE SSH FOR THIS USER
|
||||||
|
#=================================================
|
||||||
|
home=/home/$ssh_user
|
||||||
|
mkdir -p /home/$ssh_user/.ssh
|
||||||
|
touch /home/$ssh_user/.ssh/authorized_keys
|
||||||
|
echo "command=\"borg serve --restrict-to-path /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
|
||||||
|
#=================================================
|
||||||
|
touch $home/.nobackup
|
||||||
|
mkdir -p /etc/yunohost/hooks.d/backup
|
||||||
|
cp -f ../conf/17-data_home /etc/yunohost/hooks.d/backup/17-data_home
|
||||||
|
|
30
scripts/upgrade
Executable file
30
scripts/upgrade
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Backup the current version of the app
|
||||||
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue