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

Testing enabling all kind of repositories

This commit is contained in:
Philippe Bernery 2021-05-11 15:38:58 +02:00
parent 77b90852d1
commit fb77ce0f94
6 changed files with 103 additions and 139 deletions

View file

@ -1,11 +1,8 @@
;; Test complet ;; Test complet
; Manifest ; Manifest
server="dst.domain.tld" repository="sftp://sam@dst.domain.tld:2222/src.domain.tld/"
ssh_user="sam"
passphrase="APassphrase" passphrase="APassphrase"
conf=1 conf=1
port=2222
backup_path=src.domain.tld
data=1 data=1
app="all" app="all"
allow_extra_space_use=1 allow_extra_space_use=1

View file

@ -5,13 +5,8 @@ set -e
### ###
# Fetch information from YNH settings # Fetch information from YNH settings
### ###
RESTIC_SERVER=$(yunohost app setting {{ app }} server) RESTIC_REPOSITORY_BASE=$(yunohost app setting {{ app }} repository)
RESTIC_SERVER_PORT=$(yunohost app setting {{ app }} port)
RESTIC_SERVER_USER=$(yunohost app setting {{ app }} ssh_user)
RESTIC_PATH=$(yunohost app setting {{ app }} backup_path)
RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)" RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)"
RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/
RESTIC_COMMAND=/usr/local/bin/{{ app }} RESTIC_COMMAND=/usr/local/bin/{{ app }}
LOGFILE=/var/log/restic_backup_{{ app }}.log LOGFILE=/var/log/restic_backup_{{ app }}.log

View file

@ -2,13 +2,8 @@
set -e set -e
RESTIC_SERVER=$(yunohost app setting {{ app }} server) RESTIC_REPOSITORY_BASE=$(yunohost app setting {{ app }} repository)
RESTIC_SERVER_PORT=$(yunohost app setting {{ app }} port)
RESTIC_SERVER_USER=$(yunohost app setting {{ app }} ssh_user)
RESTIC_PATH=$(yunohost app setting {{ app }} backup_path)
RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)" RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)"
RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/
RESTIC_COMMAND=/usr/local/bin/{{ app }} RESTIC_COMMAND=/usr/local/bin/{{ app }}

View file

@ -1,12 +1,12 @@
{ {
"name": "Restic", "name": "Restic for all",
"id": "restic", "id": "restic-pbe",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Backup your server with restic.", "en": "Backup your server with restic.",
"fr": "Sauvegardez votre serveur avec restic." "fr": "Sauvegardez votre serveur avec restic."
}, },
"version": "0.12.0~ynh9", "version": "0.13.0~pbe1",
"url": "https://restic.net/", "url": "https://restic.net/",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"maintainer": { "maintainer": {
@ -22,54 +22,17 @@
"arguments": { "arguments": {
"install" : [ "install" : [
{ {
"name": "server", "name": "repository",
"type": "string", "type": "string",
"ask": { "ask": {
"en": "Indicate the server where you want put your backups", "en": "Indicate the Restic repository where you want to put your backups",
"fr": "Indiquez le serveur où vous voulez faire vos sauvegardes" "fr": "Indiquez le repository Restic où vous voulez faire vos sauvegardes"
}, },
"help":{ "help":{
"en": "IP address or resolvable hostname of your destination server", "en": "Un repository Restic peut être un serveur SFTP, une cible rclone, etc",
"fr": "Adresse IP ou nom résolvable de votre serveur de destination" "fr": "Un repository Restic peut être un serveur SFTP, une cible rclone, etc"
}, },
"example": "example.com" "example": "sftp://user@example.com:1234/path/"
},
{
"name": "port",
"type": "string",
"ask": {
"en": "sftp port of your server",
"fr": "Le port sftp de votre serveur"
},
"help":{
"en": "Listening port of your sftp or ssh server. The default value is 22",
"fr": "Le port d'écoute de votre serveur sftp ou ssh. La valeur par défaut est 22"
},
"example": "22",
"default": "22"
},
{
"name": "backup_path",
"type": "string",
"ask": {
"en": "The directory where you want your backup repositories to be created in",
"fr": "Le répertoire dans lequel les dépôts restic seront créés"
},
"help":{
"en": "A complete or relative path to an existing directory on the remote server writable by the remote backup user. Defaults to the login directory",
"fr": "Un chemin complet ou relatif vers un répertoire existant sur le serveur distant et accessible en écriture au compte utilisé pour la sauvegarde. Répertoire d'accueil par défaut"
},
"example": "./backups",
"default": "."
},
{
"name": "ssh_user",
"type": "string",
"ask": {
"en": "Indicate the ssh user to use to connect on this server",
"fr": "Indiquez l'utilisateur ssh à utiliser pour se connecter au serveur"
},
"example": "john"
}, },
{ {
"name": "passphrase", "name": "passphrase",
@ -79,6 +42,15 @@
"fr": "Indiquez une phrase de passe forte que vous garderez précieusement si vous voulez être en mesure d'utiliser vos sauvegardes" "fr": "Indiquez une phrase de passe forte que vous garderez précieusement si vous voulez être en mesure d'utiliser vos sauvegardes"
} }
}, },
{
"name": "generate_ssh_key",
"type": "boolean",
"ask": {
"en": "Would you like to generate a SSH key? This is useful if you want to save on a SFTP repository.",
"fr": "Souhaitez-vous générer une clé SSH ? C'est utile si vous désirez utiliser SFTP comme méthode de sauvegarde."
},
"default": true
},
{ {
"name": "conf", "name": "conf",
"type": "boolean", "type": "boolean",

View file

@ -23,12 +23,12 @@ export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}" export final_path="/opt/yunohost/${app}"
# Retrieve arguments # Retrieve arguments
ynh_export server port ssh_user backup_path passphrase on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use ynh_export repository passphrase generate_ssh_key on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_save_args server port ssh_user backup_path passphrase on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use ynh_save_args repository passphrase generate_ssh_key on_calendar check_on_calendar check_read_data_on_calendar conf data apps allow_extra_space_use
#================================================= #=================================================
# INSTALL RESTIC # INSTALL RESTIC
@ -115,61 +115,64 @@ ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err
#================================================= if [ "${generate_ssh_key}" == "true" ]; then
# GENERATE SSH KEY
#=================================================
ynh_script_progression --message="Generating private key"
ssh_dir="/root/.ssh"
if [ ! -d "${ssh_dir}" ];then
mkdir -p "${ssh_dir}"
fi
private_key="${ssh_dir}/id_${app}_ed25519"
test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key
#================================================= #=================================================
# GENERATE SSH CONFIG # GENERATE SSH KEY
#================================================= #=================================================
ynh_script_progression --message="Generating ssh config for ${app} server ${server}" ynh_script_progression --message="Generating private key"
grep -q "${app}" ${ssh_dir}/config 2>/dev/null || cat << EOCONF >> ${ssh_dir}/config ssh_dir="/root/.ssh"
# begin $app ssh config if [ ! -d "${ssh_dir}" ];then
Host ${server} mkdir -p "${ssh_dir}"
Hostname ${server} fi
Port ${port} private_key="${ssh_dir}/id_${app}_ed25519"
User ${ssh_user} test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key
IdentityFile ${private_key}
StrictHostKeyChecking no #=================================================
UserKnownHostsFile /dev/null # GENERATE SSH CONFIG
# end $app ssh config #=================================================
ynh_script_progression --message="Generating ssh config for ${app} server ${server}"
grep -q "${app}" ${ssh_dir}/config 2>/dev/null || cat << EOCONF >> ${ssh_dir}/config
# begin $app ssh config
Host ${server}
Hostname ${server}
Port ${port}
User ${ssh_user}
IdentityFile ${private_key}
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
# end $app ssh config
EOCONF EOCONF
#================================================= #=================================================
# Display key # Display key
#================================================= #=================================================
ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}: ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
$(cat ${private_key}.pub)" $(cat ${private_key}.pub)"
#================================================= #=================================================
# SEND A README FOR THE ADMIN # SEND A README FOR THE ADMIN
#================================================= #=================================================
ynh_script_progression --message="Sending post-installation instructions to admin" --last ynh_script_progression --message="Sending post-installation instructions to admin" --last
ynh_print_OFF ynh_print_OFF
message="You should now allow the following public key for user ${ssh_user} on server ${server}: message="You should now allow the following public key for user ${ssh_user} on server ${server}:
$(cat ${private_key}.pub) $(cat ${private_key}.pub)
Do so by running those commands on ${server} with user ${ssh_user}: Do so by running those commands on ${server} with user ${ssh_user}:
mkdir ~/.ssh 2>/dev/null mkdir ~/.ssh 2>/dev/null
touch ~/.ssh/authorized_keys touch ~/.ssh/authorized_keys
chmod u=rw,go= ~/.ssh/authorized_keys chmod u=rw,go= ~/.ssh/authorized_keys
cat << EOPKEY >> ~/.ssh/authorized_keys cat << EOPKEY >> ~/.ssh/authorized_keys
$(cat ${private_key}.pub) $(cat ${private_key}.pub)
EOPKEY EOPKEY
$(if [ "$backup_path" != "./" ];then echo "Also make sure ${backup_path} exists and is writable by ${ssh_user}";fi) $(if [ "$backup_path" != "./" ];then echo "Also make sure ${backup_path} exists and is writable by ${ssh_user}";fi)
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/restic_ynh" If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/restic_ynh"
ynh_send_readme_to_admin "$message" "root" ynh_send_readme_to_admin "$message" "root"
ynh_print_ON ynh_print_ON
fi

View file

@ -15,11 +15,9 @@ source /usr/share/yunohost/helpers
export app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}" export final_path="/opt/yunohost/${app}"
export server=$(ynh_app_setting_get $app server) export repository=$(ynh_app_setting_get $app repository)
export port=$(ynh_app_setting_get $app port)
export ssh_user=$(ynh_app_setting_get $app ssh_user)
export backup_path=$(ynh_app_setting_get $app backup_path)
export passphrase=$(ynh_app_setting_get $app passphrase) export passphrase=$(ynh_app_setting_get $app passphrase)
export generate_ssh_key=$(ynh_app_setting_get $app generate_ssh_key)
export on_calendar=$(ynh_app_setting_get $app on_calendar) export on_calendar=$(ynh_app_setting_get $app on_calendar)
export check_on_calendar=$(ynh_app_setting_get $app check_on_calendar) export check_on_calendar=$(ynh_app_setting_get $app check_on_calendar)
export check_read_data_on_calendar=$(ynh_app_setting_get $app check_read_data_on_calendar) export check_read_data_on_calendar=$(ynh_app_setting_get $app check_read_data_on_calendar)
@ -158,31 +156,35 @@ ynh_use_logrotate --logfile=/var/log/restic_backup_${app}.err
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log ynh_use_logrotate --logfile=/var/log/restic_check_${app}.log
ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err ynh_use_logrotate --logfile=/var/log/restic_check_${app}.err
#================================================= if [ "${generate_ssh_key}" == "true" ]; then
# UPGRADE SSH CONFIG
#=================================================
# old versions did not have delimiters in ~/.ssh/config #=================================================
# making removal in multi-instance cases break the remaining # UPGRADE SSH CONFIG
# instances. #=================================================
# So we need to add the delimiters if they are missing
set +o errexit # old versions did not have delimiters in ~/.ssh/config
set +o nounset # making removal in multi-instance cases break the remaining
grep -q "begin ${app}" ${ssh_dir}/config # instances.
missing_delimiters="$?" # So we need to add the delimiters if they are missing
if [ "$missing_delimiters" -eq 1 ];then set +o errexit
# did not find delimiters so removing old configuration set +o nounset
sed -e "/Host ${server}/,+6d" ${ssh_dir}/config -i || true grep -q "begin ${app}" ${ssh_dir}/config
cat << EOCONF >> ${ssh_dir}/config missing_delimiters="$?"
# begin $app ssh config if [ "$missing_delimiters" -eq 1 ];then
Host ${server} # did not find delimiters so removing old configuration
Hostname ${server} sed -e "/Host ${server}/,+6d" ${ssh_dir}/config -i || true
Port ${port} cat << EOCONF >> ${ssh_dir}/config
User ${ssh_user} # begin $app ssh config
IdentityFile ${private_key} Host ${server}
StrictHostKeyChecking no Hostname ${server}
UserKnownHostsFile /dev/null Port ${port}
# end $app ssh config User ${ssh_user}
IdentityFile ${private_key}
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
# end $app ssh config
EOCONF EOCONF
fi
ynh_script_progression --message="End of upgrade process" --last
fi fi
ynh_script_progression --message="End of upgrade process" --last