2020-02-23 12:02:10 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2022-03-13 17:45:45 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
# passwords aren't saved by default
|
|
|
|
ynh_app_setting_set --app=$app --key=passphrase --value="$passphrase"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-12 17:13:11 +02:00
|
|
|
# INSTALL RESTIC
|
2020-02-23 12:02:10 +01:00
|
|
|
#=================================================
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_script_progression --message="Installing Restic..." --weight=7
|
2022-03-13 17:45:45 +01:00
|
|
|
|
2020-02-23 12:02:10 +01:00
|
|
|
install_restic
|
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
_gen_and_save_public_key
|
2022-03-13 17:45:45 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
_set_ssh_config
|
2021-03-07 16:09:16 +01:00
|
|
|
|
2020-02-23 12:02:10 +01:00
|
|
|
#=================================================
|
2024-05-25 09:34:34 +02:00
|
|
|
# SETUP THE BACKUP METHOD
|
2020-02-23 12:02:10 +01:00
|
|
|
#=================================================
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_script_progression --message="Setting up backup method..." --weight=1
|
2022-03-13 17:45:45 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
mkdir -p /etc/yunohost/hooks.d/backup
|
2020-02-23 12:02:10 +01:00
|
|
|
mkdir -p /etc/yunohost/hooks.d/backup_method
|
|
|
|
mkdir -p /usr/share/yunohost/backup_method
|
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
## Backup method
|
2024-05-25 10:50:29 +02:00
|
|
|
_ynh_add_config_j2 --template="backup_method.j2" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
2024-05-25 09:34:34 +02:00
|
|
|
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
2021-03-07 16:09:16 +01:00
|
|
|
|
2024-05-25 12:54:59 +02:00
|
|
|
_ynh_add_config_j2 --template="backup-with-restic.j2" --destination="$install_dir/backup-with-restic"
|
2024-05-25 09:34:34 +02:00
|
|
|
chmod u+x "$install_dir/backup-with-restic"
|
2021-03-21 19:57:50 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
## Check method
|
2024-05-25 12:54:59 +02:00
|
|
|
_ynh_add_config_j2 --template="check_method.j2" --destination="$install_dir/check_method_restic"
|
2023-01-16 19:29:00 +01:00
|
|
|
|
2024-05-25 12:54:59 +02:00
|
|
|
_ynh_add_config_j2 --template="check-restic.j2" --destination="$install_dir/check-restic"
|
|
|
|
chmod u+x "$install_dir/check-restic"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
## Backup log script
|
2024-05-25 12:54:59 +02:00
|
|
|
_ynh_add_config_j2 --template="restic_log.j2" --destination="$install_dir/restic_log"
|
|
|
|
chmod u+x "$install_dir/restic_log"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
# Check log script
|
2024-05-25 12:54:59 +02:00
|
|
|
_ynh_add_config_j2 --template="restic_check_log.j2" --destination="$install_dir/restic_check_log"
|
|
|
|
chmod u+x "$install_dir/restic_check_log"
|
2022-03-13 17:45:45 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
chown -R "$app:$app" "$install_dir"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-05-25 09:34:34 +02:00
|
|
|
# SYSTEM CONFIGURATION
|
2020-02-23 12:02:10 +01:00
|
|
|
#=================================================
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
# Systemd services and timers
|
|
|
|
for suffix in "${systemd_services_suffixes[@]}"; do
|
|
|
|
ynh_add_systemd_config --service="$app$suffix" --template="systemd$suffix.service"
|
2024-05-25 10:50:29 +02:00
|
|
|
_ynh_add_config_j2 --template="systemd$suffix.timer.j2" --destination="/etc/systemd/system/$app$suffix.timer"
|
2024-05-25 09:34:34 +02:00
|
|
|
systemctl disable --quiet "${app}$suffix.service"
|
2024-05-25 12:30:33 +02:00
|
|
|
systemctl enable --quiet "${app}$suffix.timer"
|
|
|
|
systemctl start --quiet "${app}$suffix.timer"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
yunohost service add "$app$suffix" --description="Restic backup program ($app$suffix)" \
|
|
|
|
--test_status="systemctl show $app$suffix.service -p ActiveState --value | grep -v failed"
|
|
|
|
done
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
|
|
|
chown root:root "/etc/sudoers.d/$app"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/restic_backup_${app}.log"
|
|
|
|
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"
|
2020-02-23 12:02:10 +01:00
|
|
|
|
2022-03-13 17:45:45 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2024-05-25 09:34:34 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|