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:
parent
77b90852d1
commit
fb77ce0f94
6 changed files with 103 additions and 139 deletions
|
@ -1,11 +1,8 @@
|
|||
;; Test complet
|
||||
; Manifest
|
||||
server="dst.domain.tld"
|
||||
ssh_user="sam"
|
||||
repository="sftp://sam@dst.domain.tld:2222/src.domain.tld/"
|
||||
passphrase="APassphrase"
|
||||
conf=1
|
||||
port=2222
|
||||
backup_path=src.domain.tld
|
||||
data=1
|
||||
app="all"
|
||||
allow_extra_space_use=1
|
||||
|
|
|
@ -5,13 +5,8 @@ set -e
|
|||
###
|
||||
# Fetch information from YNH settings
|
||||
###
|
||||
RESTIC_SERVER=$(yunohost app setting {{ app }} server)
|
||||
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_REPOSITORY_BASE=$(yunohost app setting {{ app }} repository)
|
||||
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 }}
|
||||
LOGFILE=/var/log/restic_backup_{{ app }}.log
|
||||
|
|
|
@ -2,13 +2,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
RESTIC_SERVER=$(yunohost app setting {{ app }} server)
|
||||
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_REPOSITORY_BASE=$(yunohost app setting {{ app }} repository)
|
||||
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 }}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "Restic",
|
||||
"id": "restic",
|
||||
"name": "Restic for all",
|
||||
"id": "restic-pbe",
|
||||
"packaging_format": 1,
|
||||
"description": {
|
||||
"en": "Backup your server with restic.",
|
||||
"fr": "Sauvegardez votre serveur avec restic."
|
||||
},
|
||||
"version": "0.12.0~ynh9",
|
||||
"version": "0.13.0~pbe1",
|
||||
"url": "https://restic.net/",
|
||||
"license": "BSD-2-Clause",
|
||||
"maintainer": {
|
||||
|
@ -22,54 +22,17 @@
|
|||
"arguments": {
|
||||
"install" : [
|
||||
{
|
||||
"name": "server",
|
||||
"name": "repository",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "Indicate the server where you want put your backups",
|
||||
"fr": "Indiquez le serveur où vous voulez faire vos sauvegardes"
|
||||
"en": "Indicate the Restic repository where you want to put your backups",
|
||||
"fr": "Indiquez le repository Restic où vous voulez faire vos sauvegardes"
|
||||
},
|
||||
"help":{
|
||||
"en": "IP address or resolvable hostname of your destination server",
|
||||
"fr": "Adresse IP ou nom résolvable de votre serveur de destination"
|
||||
"en": "Un repository Restic peut être un serveur SFTP, une cible rclone, etc",
|
||||
"fr": "Un repository Restic peut être un serveur SFTP, une cible rclone, etc"
|
||||
},
|
||||
"example": "example.com"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
"example": "sftp://user@example.com:1234/path/"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"type": "boolean",
|
||||
|
|
|
@ -23,12 +23,12 @@ export app=$YNH_APP_INSTANCE_NAME
|
|||
export final_path="/opt/yunohost/${app}"
|
||||
|
||||
# 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
|
||||
#=================================================
|
||||
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
|
||||
|
@ -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}.err
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
if [ "${generate_ssh_key}" == "true" ]; then
|
||||
|
||||
#=================================================
|
||||
# GENERATE 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
|
||||
#=================================================
|
||||
# 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
|
||||
#=================================================
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# Display key
|
||||
#=================================================
|
||||
#=================================================
|
||||
# Display key
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
||||
$(cat ${private_key}.pub)"
|
||||
ynh_script_progression --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
||||
$(cat ${private_key}.pub)"
|
||||
|
||||
|
||||
#=================================================
|
||||
# SEND A README FOR THE ADMIN
|
||||
#=================================================
|
||||
ynh_script_progression --message="Sending post-installation instructions to admin" --last
|
||||
ynh_print_OFF
|
||||
message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
||||
$(cat ${private_key}.pub)
|
||||
#=================================================
|
||||
# SEND A README FOR THE ADMIN
|
||||
#=================================================
|
||||
ynh_script_progression --message="Sending post-installation instructions to admin" --last
|
||||
ynh_print_OFF
|
||||
message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
||||
$(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
|
||||
touch ~/.ssh/authorized_keys
|
||||
chmod u=rw,go= ~/.ssh/authorized_keys
|
||||
cat << EOPKEY >> ~/.ssh/authorized_keys
|
||||
$(cat ${private_key}.pub)
|
||||
mkdir ~/.ssh 2>/dev/null
|
||||
touch ~/.ssh/authorized_keys
|
||||
chmod u=rw,go= ~/.ssh/authorized_keys
|
||||
cat << EOPKEY >> ~/.ssh/authorized_keys
|
||||
$(cat ${private_key}.pub)
|
||||
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_print_ON
|
||||
ynh_send_readme_to_admin "$message" "root"
|
||||
ynh_print_ON
|
||||
fi
|
||||
|
|
|
@ -15,11 +15,9 @@ source /usr/share/yunohost/helpers
|
|||
|
||||
export app=$YNH_APP_INSTANCE_NAME
|
||||
export final_path="/opt/yunohost/${app}"
|
||||
export server=$(ynh_app_setting_get $app server)
|
||||
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 repository=$(ynh_app_setting_get $app repository)
|
||||
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 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)
|
||||
|
@ -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}.err
|
||||
|
||||
#=================================================
|
||||
# UPGRADE SSH CONFIG
|
||||
#=================================================
|
||||
if [ "${generate_ssh_key}" == "true" ]; then
|
||||
|
||||
# old versions did not have delimiters in ~/.ssh/config
|
||||
# making removal in multi-instance cases break the remaining
|
||||
# instances.
|
||||
# So we need to add the delimiters if they are missing
|
||||
set +o errexit
|
||||
set +o nounset
|
||||
grep -q "begin ${app}" ${ssh_dir}/config
|
||||
missing_delimiters="$?"
|
||||
if [ "$missing_delimiters" -eq 1 ];then
|
||||
# did not find delimiters so removing old configuration
|
||||
sed -e "/Host ${server}/,+6d" ${ssh_dir}/config -i || true
|
||||
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
|
||||
#=================================================
|
||||
# UPGRADE SSH CONFIG
|
||||
#=================================================
|
||||
|
||||
# old versions did not have delimiters in ~/.ssh/config
|
||||
# making removal in multi-instance cases break the remaining
|
||||
# instances.
|
||||
# So we need to add the delimiters if they are missing
|
||||
set +o errexit
|
||||
set +o nounset
|
||||
grep -q "begin ${app}" ${ssh_dir}/config
|
||||
missing_delimiters="$?"
|
||||
if [ "$missing_delimiters" -eq 1 ];then
|
||||
# did not find delimiters so removing old configuration
|
||||
sed -e "/Host ${server}/,+6d" ${ssh_dir}/config -i || true
|
||||
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
|
||||
fi
|
||||
ynh_script_progression --message="End of upgrade process" --last
|
||||
|
||||
fi
|
||||
ynh_script_progression --message="End of upgrade process" --last
|
||||
|
|
Loading…
Add table
Reference in a new issue