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

90 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
# passwords aren't saved by default
ynh_app_setting_set --app=$app --key=passphrase --value="$passphrase"
#=================================================
# INSTALL RESTIC
#=================================================
ynh_script_progression --message="Installing Restic..." --weight=7
install_restic
_gen_and_save_public_key
_set_ssh_config
#=================================================
# SETUP THE BACKUP METHOD
#=================================================
ynh_script_progression --message="Setting up backup method..." --weight=1
mkdir -p /etc/yunohost/hooks.d/backup
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
## Backup method
_ynh_add_config_j2 --template="backup_method" --destination="/etc/yunohost/hooks.d/backup_method/05-${app}_app"
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
_ynh_add_config_j2 --template="backup-with-restic" --destination="$install_dir/backup-with-${app}"
chmod u+x "$install_dir/backup-with-restic"
## Check method
_ynh_add_config_j2 --template="check_method" --destination="$install_dir/check_method_${app}"
_ynh_add_config_j2 --template="check-restic" --destination="$install_dir/check-${app}"
chmod u+x "$install_dir/check-$app"
## Backup log script
_ynh_add_config_j2 --template="restic_log" --destination="${install_dir}/restic_log_${app}"
chmod u+x "$install_dir/restic_log_${app}"
# Check log script
_ynh_add_config_j2 --template="restic_check_log" --destination="${install_dir}/restic_check_log_${app}"
chmod u+x "$install_dir/restic_check_log_${app}"
chown -R "$app:$app" "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Systemd services and timers
for suffix in "${systemd_services_suffixes[@]}"; do
ynh_add_systemd_config --service="$app$suffix" --template="systemd$suffix.service"
_ynh_add_config_j2 --template="systemd$suffix.timer" --destination="/etc/systemd/system/$app$suffix.timer"
systemctl disable --quiet "${app}$suffix.service"
systemctl enable --quiet "${app}$suffix.time"
systemctl start --quiet "${app}$suffix.time"
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
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
chown root:root "/etc/sudoers.d/$app"
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"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last