about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAoi Koizumi <novaburst@kalli.st>2022-03-14 19:33:41 -0300
committerAoi Koizumi <novaburst@kalli.st>2022-03-14 19:33:41 -0300
commit35c0bd2601d222629a66919a0d859bad956f5c6c (patch)
treec0a7c27482ee2d37d3e183aa234c904f5d252158
parent9e095399195f5296af89322d8eb9529b9f1fc558 (diff)
downloadayu-35c0bd2601d222629a66919a0d859bad956f5c6c.tar.gz
ayu was rewritten
Signed-off-by: Aoi Koizumi <novaburst@kalli.st>
-rw-r--r--README2
-rw-r--r--[-rwxr-xr-x]ayu110
2 files changed, 46 insertions, 66 deletions
diff --git a/README b/README
index 35db5bd..ecf0e4d 100644
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
 ayu (あゆ)
 ===
 
-Not-so standard unix password manager, written in (mostly) posix shell (~90 LoC, 73 ULoC)
+Not-so standard unix password manager, written in (mostly) posix shell (69 SLoC,  63 ULoC)
 Uses <https://age-encryption.org> as back-end, and tree(1) to list contents of the password store
 
 Caveats
diff --git a/ayu b/ayu
index d12afb9..6516ad8 100755..100644
--- a/ayu
+++ b/ayu
@@ -1,99 +1,79 @@
 #!/bin/sh
 
-# ayu(1) - an actually boring password manager, which uses age(1) as backend.
+ayu_dir=${ayu_dir:-$HOME/.ayu}
+ayu_settings=${ayu_settings:-$XDG_CONFIG_HOME/ayu}
+ayu_store=${ayu_store:-$HOME/.ayu-store}
+
+for dir in $ayu_dir $ayu_settings $ayu_store; do
+	test -d $dir || mkdir -p $dir
+done
+
+if ! test -f $ayu_settings/config; then
+	{
+		printf "#ayu_clipboard=\"wl-copy --primary\"\n"
+		printf "ayu_clipboard=\"xsel -ib\"\n"
+		printf "ayu_private_key=\"${ayu_dir}/private_key\" \n"
+		printf "ayu_public_key=\"${ayu_dir}/public_key\" \n"
+		printf "EDITOR=${EDITOR:-vi}\n"
+	} > $ayu_settings/config
+
+	. $ayu_settings/config
+else
+	. $ayu_settings/config
+fi
 
-# Path to the program's directory
-ayu_dir="${ayu_dir:-$HOME/.ayu}"
-
-# Path to the password store
-ayu_store="${ayu_store:-$HOME/.ayu-store}"
-
-# Command to copy an entry's text into the clipboard (must accept standard input)
-ayu_clipboard="xsel -ib"
-
-# Path to the age(1) keys
-private_key="${private_key:-${ayu_dir}/private_key}"
-public_key="${public_key:-${ayu_dir}/public_key}"
-
-# Default editor to be used
-EDITOR=${EDITOR:-vi}
-
-# Run some tests
-test -d "$ayu_dir" || mkdir -p "$ayu_dir"
-test -d "$ayu_store" || mkdir -p "$ayu_store"
-
-test -f "$private_key" || printf "Generate your own age(1) key with age-keygen(1) and place it as %s \n" "$private_key" >&2
-test -f "$public_key" || printf "Public key needs to be placed on %s \n" "$public_key" >&2
-
-# Switch directory to the password store, otherwise bail out.
 cd "$ayu_store" || exit 1
 
-# Copy an entry to the clipboard
-copy() {
+fn_copy() {
 	view "$2" | sed 1q | "$ayu_clipboard"
 }
-
-# Edit an entry if it exists
-edit() {
-	age --decrypt --identity="$private_key" --output="${1%%.age}" "${1%%.age}.age"
-	${EDITOR} "${1%%.age}"
-	age --encrypt -R "$public_key" --output="${1%%.age}.age" "${1%%.age}"
+fn_edit() {
+	age --decrypt --identity="${ayu_private_key}" --output="${1%%.age}" "${1%%.age}.age"
+	$EDITOR "${1%%.age}"
+	age --encrypt --recipients-file "${ayu_public_key}" --output="${1%%.age}.age" "${1%%.age}"
 	rm "${1%%.age}"
 }
-
-# List contents of the store
-list() {
+fn_list() {
 	tree "$ayu_store"
 }
-
-# Create a new entry
-new() {
+fn_new() {
 	test -d "$1" && usage && exit
 
 	tmpfile="$(mktemp)"
 	${EDITOR} "$tmpfile"
 
 	mkdir -p "$(dirname "$1")"
-	age --encrypt -R "$public_key" -o "$tmpfile.age" "$tmpfile"
+	age --encrypt --recipients-file "${ayu_public_key}" --output="$tmpfile.age" "$tmpfile"
 
 	mv "$tmpfile.age" "${1%%.age}".age
 	rm "$tmpfile"
 }
-
-# Remove
-remove() {
-	rm -f "${1}${2}.age"
-}
-
-# Remove recursively
-remove_recursive() {
+fn_remove_recursive() {
 	rm -rf "$@"
 }
-# Print usage
-usage() {
+fn_remove_single() {
+	rm -f "${1}${2}.age"
+}
+fn_usage() {
 	printf "Usage: [ -c | -e | -l | -n | -r | -R | -v ] <entry> \n"
 }
-
-# View an entry, otherwise list the contents of the directory specified.
-view() {
+fn_view() {
 	if [ -f "${1%%.age}".age ];then
-		age --decrypt --identity="$private_key" "${1%%.age}".age
+		age --decrypt --identity="${ayu_private_key}" "${1%%.age}.age"
 	elif [ -d "${1:-.}" ];then
 		tree "${1:-.}"
 	else
-		usage
+		fn_usage
 		exit
 	fi
 }
-
 case $1 in
-	-c) copy "$2" ;;
-	-e) edit "$2" ;;
-	-l) list ;;
-	-n) new "$2" ;;
-	-r) remove "$2" "$3" ;;
-	-R) remove_recursive "$2" ;;
-	-h) usage ;;
-	-v) view "$2" ;;
-	*) usage ;;
+	-c ) fn_copy "$2" ;;
+	-e ) fn_edit "$2" ;;
+	-l ) fn_list ;;
+	-n ) fn_new "$2" ;;
+	-r ) fn_remove_single "$2" ;;
+	-R ) fn_remove_recursive "$2" ;;
+	-v ) fn_view "$2" ;;
+	* ) fn_usage ;;
 esac