summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShokara Kou <kou@13f0.net>2022-09-07 18:42:36 -0400
committerShokara Kou <kou@13f0.net>2022-09-07 18:42:36 -0400
commit32341a174c86712cabb9243caf9e88f4d7feec50 (patch)
tree6fa60f2b070406b95b30a39569588ac56ff83f81
parent46924111a8fb9e7a51bb3cb50f306b2334f46f24 (diff)
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.
-rw-r--r--README23
-rwxr-xr-xangou16
-rwxr-xr-xangou-age66
3 files changed, 26 insertions, 79 deletions
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.
5Dependencies 5Dependencies
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
16Configuration
17-------------
18In your ~/.profile or wherever you set environment variables, add something
19like this if you use age:
20export AGE_KEY=/nas/ssh/id_ed25519
21export AGE_PUB=${AGE_KEY}.pub
22export ANGOU_DIR=/nas/angou-age
23export ANGOU_ENCRYPT="age -R $AGE_PUB"
24export ANGOU_DECRYPT="age -d -i $AGE_KEY -o -"
25
26If you use GnuPG, then add:
27export GPG_ID="user@email.tld" # or your key id
28export ANGOU_DECRYPT="gpg -qd"
29export ANGOU_ENCRYPT="gpg -er $GPG_ID -o -"
30
31For some other file encryptor, you'd need to be able to output the encrypted
32file to stdout or change the last line of edit() that runs $ANGOU_ENCRYPT.
33
15Why should I use this over password-store? 34Why should I use this over password-store?
16------------------------------------------ 35------------------------------------------
17Don't. For a serious answer, it's because this doesn't depend on bash. 36Don'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.
23Auto-complete 42Auto-complete
24------------- 43-------------
25If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your 44If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your
26kshrc. 45kshrc. \ 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"}
10mkdir -p "$ANGOU_DIR" 10mkdir -p "$ANGOU_DIR"
11cd "$ANGOU_DIR" || exit 11cd "$ANGOU_DIR" || exit
12 12
13[ ! -f ".gpg-id" ] && echo "please put your gpg key id into \$ANGOU_DIR/.gpg-id"
14GPG_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
17view() { 14view() {
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
29copy() { 26copy() {
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
4ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"}
5# sets the command to copy into your clipboard (must accept stdin)
6ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"}
7# sets command to use when listing directory structure
8ANGOU_LIST=${ANGOU_LIST:-"tree"}
9
10mkdir -p "$ANGOU_DIR"
11cd "$ANGOU_DIR" || exit
12
13# decrypt and print a password from ANGOU_DIR or print the directory structure
14view() {
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
26copy() {
27 [ ! -f $1 ] && usage && exit
28
29 view "$1" | sed 1q | $ANGOU_CLIPBOARD
30}
31
32# create new or existing password in ANGOU_DIR
33edit() {
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
48usage() {
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
59option="$1"
60case "$option" in
61 help) usage ;;
62 copy) copy "$2" ;;
63 edit) edit "$2" ;;
64 view) view "$2" ;;
65 *) view "$1" ;;
66esac