2020-02-23 12:02:10 +01:00
|
|
|
#!/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 server port ssh_user backup_path passphrase 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 conf data apps allow_extra_space_use
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Installing dependencies"
|
2020-02-23 12:02:10 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Installing restic binary"
|
2020-02-23 12:02:10 +01:00
|
|
|
install_restic
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ACTIVATE BACKUP METHODS
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Activating backup methods"
|
2020-02-23 12:02:10 +01:00
|
|
|
mkdir -p /etc/yunohost/hooks.d/backup_method
|
|
|
|
mkdir -p /usr/share/yunohost/backup_method
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP THE BACKUP METHOD
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Setting up backup methods"
|
2020-02-23 12:02:10 +01:00
|
|
|
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE CRON
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Configuring cron"
|
2020-02-23 12:02:10 +01:00
|
|
|
ynh_configure backup-with-restic "/usr/local/bin/backup-with-$app"
|
|
|
|
ynh_configure backup-with-restic-answerbot "/usr/local/bin/backup-with-$app-answerbot"
|
|
|
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
|
|
|
chmod u+x "/usr/local/bin/backup-with-$app-answerbot"
|
|
|
|
ynh_add_systemd_config
|
|
|
|
ynh_configure systemd.timer "/etc/systemd/system/$app.timer"
|
|
|
|
systemctl enable $app.timer
|
|
|
|
systemctl start $app.timer
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERATE SSH KEY
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Generating private key"
|
2020-02-23 12:02:10 +01:00
|
|
|
private_key="/root/.ssh/id_${app}_ed25519"
|
|
|
|
test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERATE SSH CONFIG
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Generating ssh config for ${server}"
|
2020-02-23 12:02:10 +01:00
|
|
|
grep -q "${server}" /root/.ssh/config 2>/dev/null || cat << EOCONF >> ~/.ssh/config
|
|
|
|
Host ${server}
|
|
|
|
Hostname ${server}
|
|
|
|
Port ${port}
|
|
|
|
User ${ssh_user}
|
|
|
|
IdentityFile ${private_key}
|
|
|
|
StrictHostKeyChecking no
|
|
|
|
UserKnownHostsFile /dev/null
|
|
|
|
EOCONF
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Display key
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="You should now allow the following public key for user ${ssh_user} on server ${server}:
|
2020-02-23 12:02:10 +01:00
|
|
|
$(cat ${private_key}.pub)"
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
2020-02-23 21:06:25 +01:00
|
|
|
ynh_print_info --message="Sending post-installation instructions to admin"
|
2020-02-23 12:02:10 +01:00
|
|
|
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 this command 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)
|
|
|
|
EOPKEY
|
|
|
|
|
|
|
|
$(if [ "$backup_path" != "./" ];then echo "Also make sure ${backup_path} exists and is writable by ${ssh_user}";fi)
|
|
|
|
|
|
|
|
If you 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
|