#!/bin/sh -e
# passman -- simple password manager
# Copyright (C) 2013-2024 Sergey Matveev (stargrave@stargrave.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
DB=${PASSMANDB:-$HOME/.passmandb}
dec() {
if [ -s $DB ] ; then
age -d $DB | zstd -d
else
cat <$tmp
[ $(recsel -c $tmp) -eq 1 ] || {
recsel -C -P Name $tmp
exit 1
}
}
commit() {
enc <$tmp >${DB}.tmp
fsync ${DB}.tmp
mv ${DB}.tmp $DB
}
case "$1" in
has)
finder "$2"
;;
gen)
generator
;;
add)
dst="$2"
passwd="$3"
[ -n "$dst" ]
[ -n "$passwd" ] || passwd=$(generator)
echo ${dst}...
dec | recins -t Credential -f Name -v "$dst" -f Passwd -v "$passwd" >$tmp
commit
;;
mod)
dec >$tmp
$EDITOR $tmp
commit
;;
*)
finder "$1"
name=$(recsel -P Name $tmp)
echo $name >&2
data=$(recsel -P Data $tmp)
[ -z "$data" ] || echo "Associated data: $data"
echo -n $(recsel -P Passwd $tmp) | cliper clipboard
echo -n ${name##*/} | cliper primary
sleep 10
echo -n | cliper clipboard
;;
esac