From: Sven Hoexter Date: Thu, 13 Dec 2018 16:58:56 +0000 (+0100) Subject: prototype of a thin shell wrapper around pass to access multiple repository X-Git-Url: https://git.sven.stormbind.net/?a=commitdiff_plain;h=8747c72b953e5eadf25677e1d0bb9003bfcdc211;p=sven%2Fscripts.git prototype of a thin shell wrapper around pass to access multiple repository --- diff --git a/home/mpass.sh b/home/mpass.sh new file mode 100755 index 0000000..8d88b6d --- /dev/null +++ b/home/mpass.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +set -eu + +# since we're running with nounset we've to ensure all variables exist +repo="" + +function help { + cat <&2 + help + fi + + # in case no repository is defined, assume it's "default" + if [ -z "${repo}" ]; then + repo="default" + fi + + # define pass repo location + # this variable is also used by pass to decide where to operate + export PASSWORD_STORE_DIR="${REPO_STORE_DIR[${repo}]}" + + # check if we actually have something that could be a repository configuraton + if [ -z "${PASSWORD_STORE_DIR}" ]; then + echo "ERROR: No valid repository configuration found for repo ${repo}" >&2 + help + fi + + # try to find out if we've a repository at hand, otherwise issue a warning + # this could still result in an error, but is perfectly fine on an "init" command + if ! [ -d "${PASSWORD_STORE_DIR}" ]; then + echo "WARNING: Given pass repo ${PASSWORD_STORE_DIR} does not exist" >&2 + fi +} + +while getopts ":r:" option; do + case $option in + r) + repo="${OPTARG}" + shift $((OPTIND-1)) + ;; + \?) + echo "ERROR: Invalid option: -$OPTARG" >&2 + help + ;; + :) + echo "ERROR: Option -$OPTARG requires an argument" >&2 + help + ;; + esac +done + +if [[ -z "${@}" ]]; then + echo "ERROR: no commands given" >&2 + help +fi + +# read our configuration +initialize + +case $1 in + pull) + echo "Trying to update pass repo ${PASSWORD_STORE_DIR}" + cd ${PASSWORD_STORE_DIR} + set +e + git pull + set -e + cd - + ;; + push) + echo "Trying to push pass repo ${PASSWORD_STORE_DIR}" + cd ${PASSWORD_STORE_DIR} + set +e + git push + set -e + cd - + ;; + *) + echo "Remaining pass commands: $@" + pass ${@} + ;; +esac