From 48da2fa1c5fdbc3842ce87f5afce15c37101d304 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Tue, 10 Oct 2023 00:28:35 +0200 Subject: Improve restic pre-filling function This allows using vanilla restic by default, using the prefilling as restic.vin instead. Also allows specifying a username for vin. --- tw/home/files/zshrc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tw/home/files') diff --git a/tw/home/files/zshrc b/tw/home/files/zshrc index 4f71747d..ced22a16 100644 --- a/tw/home/files/zshrc +++ b/tw/home/files/zshrc @@ -112,17 +112,19 @@ alias vault='VAULT_TOKEN=$(pass cern/ci/vault-root-token | head -1) \vault' nomad-shell () { nomad alloc exec "$1" sh -c 'export TERM=xterm-256color HOME=$NOMAD_TASK_DIR PS1="\\u@\\h \\w \\\$ "; cd; exec bash -i' } -restic () { +restic.vin () { if [ $# -eq 0 ]; then - command restic - echo >&2; echo 'Pass the repo name as the first parameter.' >&2 + echo 'Pass the repo name as the first parameter.' >&2 else - local repo=$1; shift - echo "running: R_REPO=rest:.../$USERNAME/$repo restic $*" >&2 - # Set RESTIC_REPOSITORY here, since we have to run pass(1) to generate it. - # RESTIC_PASSWORD_COMMAND is set separately, since it's a static string that restic will execute. + local repo user + case $1 in + */*) user=${1%%/*} repo=${1#*/} ;; + *) user=$USERNAME repo=$1 ;; + esac + shift + echo "running: restic -r vin.wg/$user/$repo $*" >&2 RESTIC_PASSWORD_COMMAND="pass computers/vin/restic-repos/$repo" \ - RESTIC_REPOSITORY="rest:http://timo:$(pass "computers/vin/restic-server/$USERNAME" | head -1)@vin.wg:8181/$USERNAME/$repo" \ + RESTIC_REPOSITORY="rest:http://$user:$(pass "computers/vin/restic-server/$user" | head -1)@vin.wg:8181/$user/$repo" \ command restic "$@" fi } -- cgit v1.2.3