diff options
Diffstat (limited to 'dpw-gpg')
| -rwxr-xr-x | dpw-gpg | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -59,7 +59,7 @@ while true ; do if [ -e "$id_file" ] ; then keys="" while read -r key ; do - keys=" -r $key" + keys="$keys -r $key" done < "$id_file" export PASSWORD_STORE_KEY="$keys" @@ -88,7 +88,7 @@ exec gpg $__gpg_opts -d < "${PASSWORD_STORE_DIR}/${pth}.gpg" insert() { pth="$1"; shift _set_gpg_id "$pth" -mkdir -p "$(dirname "$pth")" +mkdir -p "$PASSWORD_STORE_DIR/$(dirname "$pth")" #shellcheck disable=SC2086 gpg $__gpg_opts -e ${PASSWORD_STORE_KEY} \ > "${PASSWORD_STORE_DIR}/${pth}.gpg" @@ -133,11 +133,59 @@ rm $recursive $force $files _git_commit "Remove: $*" } +_init_help() { +cat <<EOF +usage: $0 [--no-git] <GPG IDs>... +EOF +exit 1 +} + +_init() { +USE_GIT=1 +if [ -d "${PASSWORD_STORE_DIR}" ] ; then + echo "Cannot init new password store, one exists" + exit 1 +fi +while [ $# -gt 0 ] ; do case $1 in + --no-git) USE_GIT=0 ; shift ;; + -h|--help) _init_help ;; + *) break ;; +esac ; done + +if [ $# -eq 0 ] ; then + echo "No GPG id supplied, bailing" + exit 1 +fi + +mkdir -p "${PASSWORD_STORE_DIR}" +cd "${PASSWORD_STORE_DIR}" + +if [ $USE_GIT -eq 1 ] ; then + git init + cat >> .git/config <<EOF +[diff "gpg"] + binary = true + textconv = gpg --no-tty --decrypt +EOF + + echo "*.gpg diff=gpg" >> .gitattributes +fi + +for id in "$@" ; do + echo "$id" >> .gpg-id +done + +_git_commit + +echo "Password store initialized" +} + act="$1"; shift case $act in show) show "$@" ;; list) list "$@" ;; insert) insert "$@" ;; rm) remove "$@" ;; + init) _init "$@" ;; *) echo "Bad command $act"; exit 1; ;; esac |
