diff options
| -rw-r--r-- | README | 23 | ||||
| -rwxr-xr-x | angou | 16 | ||||
| -rwxr-xr-x | angou-age | 66 |
3 files changed, 26 insertions, 79 deletions
| @@ -5,13 +5,32 @@ A simple password manager written in POSIX shell. | |||
| 5 | Dependencies | 5 | Dependencies |
| 6 | ------------ | 6 | ------------ |
| 7 | - POSIX-compliant environment | 7 | - POSIX-compliant environment |
| 8 | - gnupg | 8 | - age, gnupg, or any other utility to {en,de}crypt files |
| 9 | - tree (for listing all your passwords and their directories) | 9 | - tree (for listing all your passwords and their directories) |
| 10 | - a simple version is available in https://github.com/pyr/tree | 10 | - a simple version is available in https://github.com/pyr/tree |
| 11 | and in OpenBSD's ports | 11 | and in OpenBSD's ports |
| 12 | - can possibly be replaced with ls if you add ANGOU_LIST in your ~/.profile | ||
| 12 | - xsel (for copying password to clipboard, but can be changed to a different | 13 | - xsel (for copying password to clipboard, but can be changed to a different |
| 13 | command with the ANGOU_CLIPBOARD command that accepts stdin) | 14 | command with the ANGOU_CLIPBOARD command that accepts stdin) |
| 14 | 15 | ||
| 16 | Configuration | ||
| 17 | ------------- | ||
| 18 | In your ~/.profile or wherever you set environment variables, add something | ||
| 19 | like this if you use age: | ||
| 20 | export AGE_KEY=/nas/ssh/id_ed25519 | ||
| 21 | export AGE_PUB=${AGE_KEY}.pub | ||
| 22 | export ANGOU_DIR=/nas/angou-age | ||
| 23 | export ANGOU_ENCRYPT="age -R $AGE_PUB" | ||
| 24 | export ANGOU_DECRYPT="age -d -i $AGE_KEY -o -" | ||
| 25 | |||
| 26 | If you use GnuPG, then add: | ||
| 27 | export GPG_ID="user@email.tld" # or your key id | ||
| 28 | export ANGOU_DECRYPT="gpg -qd" | ||
| 29 | export ANGOU_ENCRYPT="gpg -er $GPG_ID -o -" | ||
| 30 | |||
| 31 | For some other file encryptor, you'd need to be able to output the encrypted | ||
| 32 | file to stdout or change the last line of edit() that runs $ANGOU_ENCRYPT. | ||
| 33 | |||
| 15 | Why should I use this over password-store? | 34 | Why should I use this over password-store? |
| 16 | ------------------------------------------ | 35 | ------------------------------------------ |
| 17 | Don't. For a serious answer, it's because this doesn't depend on bash. | 36 | 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. | |||
| 23 | Auto-complete | 42 | Auto-complete |
| 24 | ------------- | 43 | ------------- |
| 25 | If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your | 44 | If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your |
| 26 | kshrc. | 45 | kshrc. \ No newline at end of file |
| @@ -10,13 +10,10 @@ ANGOU_LIST=${ANGOU_LIST:-"tree"} | |||
| 10 | mkdir -p "$ANGOU_DIR" | 10 | mkdir -p "$ANGOU_DIR" |
| 11 | cd "$ANGOU_DIR" || exit | 11 | cd "$ANGOU_DIR" || exit |
| 12 | 12 | ||
| 13 | [ ! -f ".gpg-id" ] && echo "please put your gpg key id into \$ANGOU_DIR/.gpg-id" | ||
| 14 | GPG_ID="$(cat .gpg-id)" | ||
| 15 | |||
| 16 | # decrypt and print a password from ANGOU_DIR or print the directory structure | 13 | # decrypt and print a password from ANGOU_DIR or print the directory structure |
| 17 | view() { | 14 | view() { |
| 18 | if [ -f "${1%%.gpg}".gpg ]; then | 15 | if [ -f "$1" ]; then |
| 19 | gpg -qd "${1%%.gpg}".gpg | 16 | $ANGOU_DECRYPT "$1" |
| 20 | elif [ -d "${1:-.}" ]; then | 17 | elif [ -d "${1:-.}" ]; then |
| 21 | tree "${1:-.}" | 18 | tree "${1:-.}" |
| 22 | else | 19 | else |
| @@ -27,7 +24,7 @@ view() { | |||
| 27 | 24 | ||
| 28 | # copy the first line from view to clipboard | 25 | # copy the first line from view to clipboard |
| 29 | copy() { | 26 | copy() { |
| 30 | [ ! -f "${1%%.gpg}".gpg ] && usage && exit | 27 | [ ! -f $1 ] && usage && exit |
| 31 | 28 | ||
| 32 | view "$1" | sed 1q | $ANGOU_CLIPBOARD | 29 | view "$1" | sed 1q | $ANGOU_CLIPBOARD |
| 33 | } | 30 | } |
| @@ -39,15 +36,12 @@ edit() { | |||
| 39 | tmpfile="$(mktemp)" | 36 | tmpfile="$(mktemp)" |
| 40 | 37 | ||
| 41 | # edit a copy of a password if it already exists | 38 | # edit a copy of a password if it already exists |
| 42 | [ -f "${1%%.gpg}".gpg ] && gpg -qd "${1%%.gpg}".gpg > "$tmpfile" | 39 | [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" |
| 43 | 40 | ||
| 44 | "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" | 41 | "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" |
| 45 | 42 | ||
| 46 | mkdir -p "$(dirname "$1")" | 43 | mkdir -p "$(dirname "$1")" |
| 47 | gpg -er "$GPG_ID" "$tmpfile" | 44 | $ANGOU_ENCRYPT "$tmpfile" >"$1" |
| 48 | |||
| 49 | rm "$tmpfile" | ||
| 50 | mv "$tmpfile.gpg" "${1%%.gpg}".gpg | ||
| 51 | } | 45 | } |
| 52 | 46 | ||
| 53 | # print usage | 47 | # 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 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # sets the directory with all your passwords | ||
| 4 | ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} | ||
| 5 | # sets the command to copy into your clipboard (must accept stdin) | ||
| 6 | ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"} | ||
| 7 | # sets command to use when listing directory structure | ||
| 8 | ANGOU_LIST=${ANGOU_LIST:-"tree"} | ||
| 9 | |||
| 10 | mkdir -p "$ANGOU_DIR" | ||
| 11 | cd "$ANGOU_DIR" || exit | ||
| 12 | |||
| 13 | # decrypt and print a password from ANGOU_DIR or print the directory structure | ||
| 14 | view() { | ||
| 15 | if [ -f "$1" ]; then | ||
| 16 | $ANGOU_DECRYPT "$1" | ||
| 17 | elif [ -d "${1:-.}" ]; then | ||
| 18 | tree "${1:-.}" | ||
| 19 | else | ||
| 20 | usage | ||
| 21 | exit | ||
| 22 | fi | ||
| 23 | } | ||
| 24 | |||
| 25 | # copy the first line from view to clipboard | ||
| 26 | copy() { | ||
| 27 | [ ! -f $1 ] && usage && exit | ||
| 28 | |||
| 29 | view "$1" | sed 1q | $ANGOU_CLIPBOARD | ||
| 30 | } | ||
| 31 | |||
| 32 | # create new or existing password in ANGOU_DIR | ||
| 33 | edit() { | ||
| 34 | [ -d "$1" ] && usage && exit | ||
| 35 | |||
| 36 | tmpfile="$(mktemp)" | ||
| 37 | |||
| 38 | # edit a copy of a password if it already exists | ||
| 39 | [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" | ||
| 40 | |||
| 41 | "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" | ||
| 42 | |||
| 43 | mkdir -p "$(dirname "$1")" | ||
| 44 | $ANGOU_ENCRYPT "$tmpfile" >"$1" | ||
| 45 | } | ||
| 46 | |||
| 47 | # print usage | ||
| 48 | usage() { | ||
| 49 | printf "Usage: %s [help|copy|edit|view [file or directory]]\n" "$0" | ||
| 50 | printf "\tThe edit and copy command expects a file as an argument,\n" | ||
| 51 | printf "\twhile the view command expects a directory as an argument.\n" | ||
| 52 | printf "\tThe arguments for view and edit are relative to\n" | ||
| 53 | printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" | ||
| 54 | |||
| 55 | printf "\tThe view command is the default command if only a file or\n" | ||
| 56 | printf "\tdirectory is passed as an argument\n" | ||
| 57 | } | ||
| 58 | |||
| 59 | option="$1" | ||
| 60 | case "$option" in | ||
| 61 | help) usage ;; | ||
| 62 | copy) copy "$2" ;; | ||
| 63 | edit) edit "$2" ;; | ||
| 64 | view) view "$2" ;; | ||
| 65 | *) view "$1" ;; | ||
| 66 | esac | ||
