#!/bin/sh # ayu(1) - an actually boring password manager, which uses age(1) as backend. # Path to the program's directory ayu_dir="$HOME/.config/ayu" # Path to the password store ayu_store="$HOME/.ayu" # Path to the age(1) keys ayu_key="$ayu_dir/age.key" ayu_pub="$ayu_store/.age-id" EDITOR=${EDITOR:-vi} 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" printf "e.g: age-keygen -o $ayu_key and public key should be on $ayu_pub \n" exit 1 fi cd $ayu_store || exit 1 edit() { age --decrypt --identity=$ayu_key --output=${1%%.age} ${1%%.age}.age ${EDITOR} ${1%%.age} age --encrypt -R $ayu_pub --output=${1%%.age}.age ${1%%.age} rm ${1%%.age} } list() { tree $ayu_store } new() { test -d "$1" && usage && exit tmpfile="$(mktemp)" ${EDITOR} "$tmpfile" mkdir -p "$(dirname "$1")" age --encrypt -R $ayu_pub -o $tmpfile.age $tmpfile mv $tmpfile.age "${1%%.age}".age rm $tmpfile } remove() { test -d "$1" && usage && exit rm -r "$(dirname "$1")" } usage() { printf "$0 [ edit | list | new | rm | usage | view ] \n" } view() { if [ -f "${1%%.age}".age ];then age --decrypt --identity=$ayu_key "${1%%.age}".age elif [ -d "${1:-.}" ];then tree "${1:-.}" else usage exit fi } case $1 in edit | ed) edit $2 ;; list | ls) list ;; new) new $2 ;; remove | rm) remove $2 ;; usage) usage ;; view) view $2 ;; *) list ;; esac