#!/bin/sh -e
# passman -- simple password manager
-# Copyright (C) 2013-2015 Sergey Matveev (stargrave@stargrave.org)
+# Copyright (C) 2013-2023 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; either version 3 of the License, or
-# (at your option) any later version.
+# 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
DB=~/.passmandb
-generator()
-{
- dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64 | tr '+/' '-_' | tr -d =
+generator() {
+ gpg --armor --gen-random 1 16 | tr '+/' '-_' | tr -d =
}
-cliper()
-{
+cliper() {
xclip -in -selection $1
}
+ENTITY=""
+
+finder() {
+ cd $DB
+ result=$(find . -type d -path "*$1*" | while read ent; do
+ [ -e "$ent/passwd" ] || continue
+ echo "$ent" | sed 's#^\./##'
+ done)
+ if [ $(echo "$result" | wc -l) -ne 1 ]; then
+ echo "$result"
+ exit 1
+ fi
+ [ -n "$result" ] || exit 1
+ ENTITY=$result
+ echo "$result"
+}
+
case "$1" in
+has)
+ finder "$2"
+ ;;
gen)
generator
;;
[ -n "$passwd" ] || passwd=$(generator)
echo Adding password for $dst
mkdir -p $DB/$dst
+ umask 077
echo "$passwd" > $DB/$dst/passwd
;;
*)
- cd $DB
- result=$(find . -type d -path "*$1*" | while read ent; do
- [ -e "$ent/passwd" ] || continue
- echo "$ent" | sed 's#^\./##'
- done)
- if [ $(echo "$result" | wc -l) -ne 1 ]; then
- echo "$result"
- exit
- fi
- echo $result
- if [ -e "$result"/data ]; then
+ finder "$1"
+ if [ -e "$ENTITY"/data ]; then
echo -n "Associated data: "
- cat "$result"/data
+ cat "$ENTITY"/data
fi
- perl -ne 'chop and print' "$result"/passwd | cliper clipboard
- echo $(basename "$result") | perl -ne 'chop and print' | cliper primary
+ perl -ne 'chop and print' "$ENTITY"/passwd | cliper clipboard
+ echo $(basename "$ENTITY") | perl -ne 'chop and print' | cliper primary
sleep 10
echo -n | cliper clipboard
;;