diff --git a/conf/backup-with-borg.j2 b/conf/backup-with-borg similarity index 58% rename from conf/backup-with-borg.j2 rename to conf/backup-with-borg index 68df3b1..2f09a3b 100644 --- a/conf/backup-with-borg.j2 +++ b/conf/backup-with-borg @@ -1,5 +1,7 @@ #!/bin/bash +app=$1 + # Adapt this script to different API 2.x vs 3.x if yunohost -v | grep "version: 2." > /dev/null; then ignore_apps="--ignore-apps" @@ -14,34 +16,34 @@ filter_hooks() { } # Backup system part conf -conf=$(yunohost app setting {{ app }} conf) +conf=$(yunohost app setting $app conf) if [ $conf -eq 1 ] then - yunohost backup create $ignore_apps -n auto_conf --method {{ app }}_app --system $(filter_hooks conf) + yunohost backup create $ignore_apps -n auto_conf --method $app_app --system $(filter_hooks conf) fi # Backup system data -data=$(yunohost app setting {{ app }} data) +data=$(yunohost app setting $app data) if [ $data -eq 1 ] then - yunohost backup create $ignore_apps -n auto_data --method {{ app }}_app --system $(filter_hooks data) + yunohost backup create $ignore_apps -n auto_data --method $app_app --system $(filter_hooks data) fi # Backup all apps independently -apps=$(yunohost app setting {{ app }} apps) -for app in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do +apps=$(yunohost app setting $app apps) +for application in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do backup_app=false if [[ "$apps" = "all" ]]; then backup_app=true else for selected_app in $(echo $apps | tr "," " ");do - if [[ "$selected_app" == "$app" ]]; then + if [[ "$selected_app" == "$application" ]]; then backup_app=true break fi done fi if [ "$backup_app" == "true" ];then - yunohost backup create $ignore_system -n auto_$app --method {{ app }}_app --apps $app + yunohost backup create $ignore_system -n auto_$application --method $app_app --apps $app fi done diff --git a/conf/backup_method.j2 b/conf/backup_method similarity index 87% rename from conf/backup_method.j2 rename to conf/backup_method index 790b5fe..4cf3c30 100644 --- a/conf/backup_method.j2 +++ b/conf/backup_method @@ -2,13 +2,13 @@ set -e -BORG_PASSPHRASE="{{ passphrase }}" -if ssh-keygen -F "{{ server }}" >/dev/null ; then - BORG_RSH="ssh -i /root/.ssh/id_{{ app }}_ed25519 -oStrictHostKeyChecking=yes " +BORG_PASSPHRASE='__PASSPHRASE__' +repo="__REPOSITORY__" #$4 +if ssh-keygen -F "__SERVER__" >/dev/null ; then + BORG_RSH="ssh -i /root/.ssh/id___APP___ed25519 -oStrictHostKeyChecking=yes " else - BORG_RSH="ssh -i /root/.ssh/id_{{ app }}_ed25519 -oStrictHostKeyChecking=no " + BORG_RSH="ssh -i /root/.ssh/id___APP___ed25519 -oStrictHostKeyChecking=no " fi -repo="{{ repository }}" #$4 do_need_mount() { true diff --git a/conf/systemd.service b/conf/systemd.service index e0d648d..4c8271b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -4,7 +4,7 @@ After=network.target [Service] Type=oneshot -ExecStart=/usr/local/bin/backup-with-__APP__ +ExecStart=/usr/local/bin/backup-with-__APP__ __APP__ User=root Group=root diff --git a/conf/systemd.timer b/conf/systemd.timer new file mode 100644 index 0000000..6434e4e --- /dev/null +++ b/conf/systemd.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run backup __APP__ regularly + +[Timer] +OnCalendar=__ON_CALENDAR__ + +[Install] +WantedBy=timers.target diff --git a/conf/systemd.timer.j2 b/conf/systemd.timer.j2 deleted file mode 100644 index f21a951..0000000 --- a/conf/systemd.timer.j2 +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Run backup {{ app }} regularly - -[Timer] -OnCalendar={{ on_calendar }} - -[Install] -WantedBy=timers.target diff --git a/scripts/_common.sh b/scripts/_common.sh index efcfe2c..ed15366 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -51,20 +51,12 @@ ynh_save_args () { if [ "$var" == "path_url" ]; then setting_var="path" fi - ynh_app_setting_set $app $setting_var ${!var} + ynh_app_setting_set $app $setting_var "${!var}" done } -ynh_configure () { - ynh_backup_if_checksum_is_different $2 - ynh_render_template "${PKG_DIR}/conf/$1.j2" "$2" - ynh_store_file_checksum $2 -} - - - # Send an email to inform the administrator # # usage: ynh_send_readme_to_admin app_message [recipients] diff --git a/scripts/install b/scripts/install index f215e1c..c1552fd 100755 --- a/scripts/install +++ b/scripts/install @@ -44,6 +44,7 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies install_borg_with_pip + #================================================= # SPECIFIC SETUP #================================================= @@ -56,11 +57,11 @@ mkdir -p /usr/share/yunohost/backup_method #================================================= # SETUP THE BACKUP METHOD #================================================= -ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" +ynh_add_config --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_configure backup-with-borg "/usr/local/bin/backup-with-$app" +ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app" chmod u+x "/usr/local/bin/backup-with-$app" if [ ! -z "$server" ]; then @@ -109,7 +110,7 @@ ynh_add_systemd_config #================================================= # CONFIGURE SYSTEMD TIMER #================================================= -ynh_configure systemd.timer "/etc/systemd/system/$app.timer" +ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer" systemctl enable $app.timer --quiet systemctl start $app.timer diff --git a/scripts/restore b/scripts/restore index 6310e7f..31a35cf 100755 --- a/scripts/restore +++ b/scripts/restore @@ -50,16 +50,19 @@ ynh_restore yunohost service add $app systemctl enable $app.timer --quiet systemctl start $app.timer -#yunohost service add $app.timer -#yunohost service enable $app.timer -#yunohost service start $app.timer #================================================= # RESTORE SYSTEMD #================================================= - systemctl enable $app.service --quiet +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="Deduplicating backup program" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2720b24..01a026c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -96,10 +96,11 @@ install_borg_with_pip # SETUP THE BACKUP METHOD #================================================= ynh_script_progression --message="Setting up backup method..." --weight=1 -ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" +ynh_add_config --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_configure backup-with-borg "/usr/local/bin/backup-with-$app" + +ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app" chmod u+x "/usr/local/bin/backup-with-$app" #================================================= @@ -113,7 +114,7 @@ ynh_add_systemd_config #================================================= # CONFIGURE SYSTEMD TIMER #================================================= -ynh_configure systemd.timer "/etc/systemd/system/$app.timer" +ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer" systemctl enable $app.timer --quiet systemctl start $app.timer