mirror of
https://github.com/YunoHost-Apps/borgserver_ynh.git
synced 2024-09-03 20:36:20 +02:00
Try to cleanup some of the mess ..
This commit is contained in:
parent
a7003348fc
commit
8fa3f329a6
8 changed files with 35 additions and 168 deletions
|
@ -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"a=1G
|
|
@ -58,12 +58,7 @@ ram.runtime = "50M"
|
|||
example = "30G"
|
||||
|
||||
[resources]
|
||||
[resources.system_user]
|
||||
|
||||
#[resources.install_dir]
|
||||
|
||||
[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"
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
# App package root directory should be the parent folder
|
||||
PKG_DIR=$(cd ../; pwd)
|
||||
BORG_VERSION=1.2.6
|
||||
|
||||
# Install borg with pip if borg is not here
|
||||
|
@ -24,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" ]; then
|
||||
ynh_arg="PATH"
|
||||
fi
|
||||
#REMOVEME? 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" ]; then
|
||||
setting_var="path"
|
||||
fi
|
||||
ynh_app_setting_set $app $setting_var "${!var}"
|
||||
done
|
||||
}
|
||||
|
|
|
@ -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
|
||||
#REMOVEME? ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
#REMOVEME? ynh_print_info --message="Loading installation settings..."
|
||||
|
||||
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
||||
#REMOVEME? export ssh_user="$(ynh_app_setting_get $app ssh_user)"
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
#=================================================
|
||||
|
|
|
@ -9,13 +9,6 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#=================================================
|
||||
|
||||
# Retrieve arguments
|
||||
ynh_export ssh_user public_key quota alert_delay alert_mails
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
||||
#=================================================
|
||||
|
@ -26,12 +19,6 @@ if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then
|
|||
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
|
||||
#=================================================
|
||||
|
@ -39,34 +26,25 @@ ynh_script_progression --message="Installing 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
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -12,37 +12,32 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..."
|
||||
ynh_script_progression --message="Reinstalling borg env..."
|
||||
|
||||
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/$ssh_user
|
||||
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
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -30,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 :( !"
|
||||
|
@ -42,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
|
||||
|
@ -52,13 +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
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
|
@ -71,23 +64,22 @@ 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/$ssh_user
|
||||
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
|
||||
|
|
22
tests.toml
22
tests.toml
|
@ -2,20 +2,8 @@ test_format = 1.0
|
|||
|
||||
[default]
|
||||
|
||||
# ------------
|
||||
# Tests to run
|
||||
# ------------
|
||||
|
||||
exclude = ["install.root", "install.subdir", "change_url"] # The test IDs to be used in only/exclude statements are: install.root, install.subdir, install.nourl, install.multi, backup_restore, upgrade, upgrade.someCommitId change_url
|
||||
# NB: you should NOT need this except if you really have a good reason...
|
||||
|
||||
|
||||
# ------------
|
||||
# Tests to run
|
||||
# ------------
|
||||
|
||||
args.ssh_user="sam"
|
||||
args.public_key="ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
|
||||
args.alert_delay=1
|
||||
args.alert_mails="sam@domain.tld"
|
||||
args.quota="1G"
|
||||
args.ssh_user = "sam"
|
||||
args.public_key = "ssh-ed25519 AAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
|
||||
args.alert_delay = 1
|
||||
args.alert_mails = "sam@domain.tld"
|
||||
args.quota = "1G"
|
||||
|
|
Loading…
Reference in a new issue