1
mirror of git://git.acid.vegas/random.git synced 2024-12-04 21:46:40 +00:00
random/pass

65 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# developed by acidvegas (https://acid.vegas/pass)
# todo: oathtool check for git gpg gpg2 oathtool shred xclip
GPG_ID="acidvegas"
GPG_OPTS="--quiet --yes --compress-algo=none --no-encrypt-to --batch --use-agent"
PASS_DIR=$HOME/.secrets
gc() {
git -C $PASS_DIR add -A
git -C $PASS_DIR commit -m "$@"
}
edit() {
if [ -d /dev/shm ] && [ -w /dev/shm ] && [ -x /dev/shm ]; then
tmp=$(mktemp -u /dev/shm/pw.XXXXXXXXXX)
else
tmp=$(mktemp -u pw.XXXXXXXXXX)
fi
trap "shred -f -z $tmp" EXIT
if [ -f $PASS_DIR/$1.gpg ]; then
gpg2 -d -o $tmp $GPG_OPTS $PASS_DIR/$1.gpg
nano $tmp
if [ ! "$(gpg2 -d $GPG_OPTS $PASS_DIR/$1.gpg)" = "$(cat $tmp)" ]; then
gpg2 -e -r $GPG_ID -o $PASS_DIR/$1.gpg $GPG_OPTS $tmp
gc "modified $1"
fi
else
nano $tmp
if [ -f $tmp ]; then
mkdir -p $(dirname $PASS_DIR/$1)
gpg2 -e -r $GPG_ID -o $PASS_DIR/$1.gpg $GPG_OPTS $tmp
gc "created $1"
fi
fi
}
otp() {
echo "not done"
}
show() {
if [ -f $PASS_DIR/$1.gpg ]; then
gpg2 -d $GPG_OPTS $PASS_DIR/$1.gpg
else
echo "error: $1 does not exist"
fi
}
set -f+x
export GPG_TTY=$(tty)
umask 077
mkdir -p $PASS_DIR
if [ "$#" = '2' ]; then
if [ "$1" = "edit" ]; then
edit $2
elif [ "$1" = "otp" ]; then
otp $2
fi
elif [ "$#" = '1' ]; then
show $1
else
tree -C -l --noreport $PASS_DIR | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
fi