From 5079a58c5b348aa26af06951d0b31cc25de9f843 Mon Sep 17 00:00:00 2001 From: Nova li Gensokyo Date: Sun, 5 Dec 2021 14:46:17 +0000 Subject: # * NOTE: Comments in this file WILL DEGRADE PERFORMANCE. * --- ayu | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 ayu (limited to 'ayu') diff --git a/ayu b/ayu new file mode 100755 index 0000000..4848531 --- /dev/null +++ b/ayu @@ -0,0 +1,72 @@ +#!/bin/sh + +# Path to the program's directory +ayu_dir="$HOME/.config/ayu" + +# Path to the age(1) keys +ayu_key="$ayu_dir/age.key" +ayu_pub="$ayu_dir/age.pub" + +# Path to the password store +ayu_store="$HOME/.ayu" + +test -d $ayu_dir || mkdir -p $ayu_dir +test -d $ayu_store || mkdir -p $ayu_store + + +if ! [ -f $ayu_key ];then + printf "First generate your own age(1) key with age-keygen(1) and place it as $ayu_key. \n" + exit 1 +fi + +cd $ayu_store + +list() { + tree $ayu_store +} + +edit() { + test -d "$1" && usage && exit + + tmpfile="$(mktemp)" + + # if the password already exists, decrypt and edit it instead + test -f "${1%%.age}".age && age --decrypt --identity=$age_pub "${1%%.age}".age > $tmpfile + + vi "$tmpfile" + + mkdir -p "$(dirname "$1")" + age --encrypt -R $ayu_pub -o $tmpfile.age $tmpfile + + mv $tmpfile.age "${1%%.age}".age + rm $tmpfile +} + +usage() { + printf "$0 [ edit | list | new | view ] \n" +} + +view() { + if [ -f "${1%%.age}".age ];then + age --decrypt --identity=$ayu_key .age + elif [ -d "${1:-.}" ];then + tree "${1:-.}" + else + usage + exit + fi +} +case $1 in + list) + list + ;; + edit | new) + edit $2 + ;; + view) + view $2 + ;; + *) + list + ;; +esac -- cgit 1.4.1-2-gfad0