From 32341a174c86712cabb9243caf9e88f4d7feec50 Mon Sep 17 00:00:00 2001 From: Shokara Kou Date: Wed, 7 Sep 2022 18:42:36 -0400 Subject: make angou-age the main angou to be tool-independent Angou no longer strictly depends on age or gnupg as the encrypt and decrypt commands are user changeable. --- README | 23 ++++++++++++++++++++-- angou | 16 +++++----------- angou-age | 66 --------------------------------------------------------------- 3 files changed, 26 insertions(+), 79 deletions(-) delete mode 100755 angou-age diff --git a/README b/README index 8d20e2c..08521d1 100644 --- a/README +++ b/README @@ -5,13 +5,32 @@ A simple password manager written in POSIX shell. Dependencies ------------ - POSIX-compliant environment -- gnupg +- age, gnupg, or any other utility to {en,de}crypt files - tree (for listing all your passwords and their directories) - a simple version is available in https://github.com/pyr/tree and in OpenBSD's ports + - can possibly be replaced with ls if you add ANGOU_LIST in your ~/.profile - xsel (for copying password to clipboard, but can be changed to a different command with the ANGOU_CLIPBOARD command that accepts stdin) +Configuration +------------- +In your ~/.profile or wherever you set environment variables, add something +like this if you use age: +export AGE_KEY=/nas/ssh/id_ed25519 +export AGE_PUB=${AGE_KEY}.pub +export ANGOU_DIR=/nas/angou-age +export ANGOU_ENCRYPT="age -R $AGE_PUB" +export ANGOU_DECRYPT="age -d -i $AGE_KEY -o -" + +If you use GnuPG, then add: +export GPG_ID="user@email.tld" # or your key id +export ANGOU_DECRYPT="gpg -qd" +export ANGOU_ENCRYPT="gpg -er $GPG_ID -o -" + +For some other file encryptor, you'd need to be able to output the encrypted +file to stdout or change the last line of edit() that runs $ANGOU_ENCRYPT. + Why should I use this over password-store? ------------------------------------------ Don't. For a serious answer, it's because this doesn't depend on bash. @@ -23,4 +42,4 @@ Set the ANGOU_DIR environment variable to your password store directory. Auto-complete ------------- If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your -kshrc. +kshrc. \ No newline at end of file diff --git a/angou b/angou index 5a252a3..845670b 100755 --- a/angou +++ b/angou @@ -10,13 +10,10 @@ ANGOU_LIST=${ANGOU_LIST:-"tree"} mkdir -p "$ANGOU_DIR" cd "$ANGOU_DIR" || exit -[ ! -f ".gpg-id" ] && echo "please put your gpg key id into \$ANGOU_DIR/.gpg-id" -GPG_ID="$(cat .gpg-id)" - # decrypt and print a password from ANGOU_DIR or print the directory structure view() { - if [ -f "${1%%.gpg}".gpg ]; then - gpg -qd "${1%%.gpg}".gpg + if [ -f "$1" ]; then + $ANGOU_DECRYPT "$1" elif [ -d "${1:-.}" ]; then tree "${1:-.}" else @@ -27,7 +24,7 @@ view() { # copy the first line from view to clipboard copy() { - [ ! -f "${1%%.gpg}".gpg ] && usage && exit + [ ! -f $1 ] && usage && exit view "$1" | sed 1q | $ANGOU_CLIPBOARD } @@ -39,15 +36,12 @@ edit() { tmpfile="$(mktemp)" # edit a copy of a password if it already exists - [ -f "${1%%.gpg}".gpg ] && gpg -qd "${1%%.gpg}".gpg > "$tmpfile" + [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" mkdir -p "$(dirname "$1")" - gpg -er "$GPG_ID" "$tmpfile" - - rm "$tmpfile" - mv "$tmpfile.gpg" "${1%%.gpg}".gpg + $ANGOU_ENCRYPT "$tmpfile" >"$1" } # print usage diff --git a/angou-age b/angou-age deleted file mode 100755 index 845670b..0000000 --- a/angou-age +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh - -# sets the directory with all your passwords -ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} -# sets the command to copy into your clipboard (must accept stdin) -ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"} -# sets command to use when listing directory structure -ANGOU_LIST=${ANGOU_LIST:-"tree"} - -mkdir -p "$ANGOU_DIR" -cd "$ANGOU_DIR" || exit - -# decrypt and print a password from ANGOU_DIR or print the directory structure -view() { - if [ -f "$1" ]; then - $ANGOU_DECRYPT "$1" - elif [ -d "${1:-.}" ]; then - tree "${1:-.}" - else - usage - exit - fi -} - -# copy the first line from view to clipboard -copy() { - [ ! -f $1 ] && usage && exit - - view "$1" | sed 1q | $ANGOU_CLIPBOARD -} - -# create new or existing password in ANGOU_DIR -edit() { - [ -d "$1" ] && usage && exit - - tmpfile="$(mktemp)" - - # edit a copy of a password if it already exists - [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" - - "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" - - mkdir -p "$(dirname "$1")" - $ANGOU_ENCRYPT "$tmpfile" >"$1" -} - -# print usage -usage() { - printf "Usage: %s [help|copy|edit|view [file or directory]]\n" "$0" - printf "\tThe edit and copy command expects a file as an argument,\n" - printf "\twhile the view command expects a directory as an argument.\n" - printf "\tThe arguments for view and edit are relative to\n" - printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" - - printf "\tThe view command is the default command if only a file or\n" - printf "\tdirectory is passed as an argument\n" -} - -option="$1" -case "$option" in - help) usage ;; - copy) copy "$2" ;; - edit) edit "$2" ;; - view) view "$2" ;; - *) view "$1" ;; -esac -- cgit v1.2.3