diff --git a/roles/restic/files/restic-job.sh b/roles/restic/files/restic-job.sh index 014fbb5..ada90fa 100755 --- a/roles/restic/files/restic-job.sh +++ b/roles/restic/files/restic-job.sh @@ -8,7 +8,9 @@ error_exit() { } RESTIC_ETC_PATH=${RESTIC_ETC_PATH:-/etc/restic} -RESTIC_PATH=${RESTIC_PATH:-/usr/local/bin/restic} + +# shellcheck source=/dev/null +source "${RESTIC_ETC_PATH}/env.sh" MAX_ATTEMPTS=60 NICE="ionice -c2 nice -n19" diff --git a/roles/restic/files/restic-repo.sh b/roles/restic/files/restic-repo.sh index 369d5ba..7a02bf1 100644 --- a/roles/restic/files/restic-repo.sh +++ b/roles/restic/files/restic-repo.sh @@ -8,7 +8,9 @@ error_exit() { } RESTIC_ETC_PATH=${RESTIC_ETC_PATH:-/etc/restic} -RESTIC_PATH=${RESTIC_PATH:-/usr/local/bin/restic} + +# shellcheck source=/dev/null +source "${RESTIC_ETC_PATH}/env.sh" if [ $# -lt 2 ]; then error_exit "missing arguments" diff --git a/roles/restic/files/restic-tidy.sh b/roles/restic/files/restic-tidy.sh index 505f301..ab7054a 100755 --- a/roles/restic/files/restic-tidy.sh +++ b/roles/restic/files/restic-tidy.sh @@ -8,7 +8,9 @@ error_exit() { } RESTIC_ETC_PATH=${RESTIC_ETC_PATH:-/etc/restic} -RESTIC_PATH=${RESTIC_PATH:-/usr/local/bin/restic} + +# shellcheck source=/dev/null +source "${RESTIC_ETC_PATH}/env.sh" if [ "$RESTIC_SELF_UPDATE" -eq 1 ]; then printf "running restic self-update\n" diff --git a/roles/restic/tasks/main.yaml b/roles/restic/tasks/main.yaml index 7225242..84c1ba8 100644 --- a/roles/restic/tasks/main.yaml +++ b/roles/restic/tasks/main.yaml @@ -65,6 +65,14 @@ - "{{ restic_etc_path }}/repos" - "{{ restic_etc_path }}/jobs" +- name: create environment helper + template: + src: env.sh.j2 + dest: "{{ restic_etc_path }}/env.sh" + owner: root + group: root + mode: 0400 + - name: copy restic helper scripts copy: src: "{{ item }}" diff --git a/roles/restic/templates/env.sh.j2 b/roles/restic/templates/env.sh.j2 new file mode 100644 index 0000000..b6fa8b7 --- /dev/null +++ b/roles/restic/templates/env.sh.j2 @@ -0,0 +1,7 @@ +#!/bin/bash + +# {{ ansible_managed }} + +RESTIC_ETC_PATH="{{ restic_etc_path | default('/etc/restic') }}" +RESTIC_PATH="{{ restic_path | default('/usr/local/bin/restic') }}" +RESTIC_SELF_UPDATE={{ restic_self_update | ternary(1, 0) }}