2019-09-11 04:11:40 +02:00
|
|
|
#!/bin/sh
|
2019-12-08 19:14:46 +01:00
|
|
|
# credentials
|
2020-05-03 16:47:27 +02:00
|
|
|
# Written in 2019-2020 by Lucas
|
2019-09-11 04:11:40 +02:00
|
|
|
# CC0 1.0 Universal/Public domain - No rights reserved
|
|
|
|
#
|
|
|
|
# To the extent possible under law, the author(s) have dedicated all
|
|
|
|
# copyright and related and neighboring rights to this software to the
|
|
|
|
# public domain worldwide. This software is distributed without any
|
|
|
|
# warranty. You should have received a copy of the CC0 Public Domain
|
|
|
|
# Dedication along with this software. If not, see
|
|
|
|
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
usage()
|
|
|
|
{
|
2019-12-28 01:12:31 +01:00
|
|
|
cat - <<. >&2
|
|
|
|
Usage:
|
2020-05-25 17:47:09 +02:00
|
|
|
${0##*/} [-mpu] account
|
2019-12-28 01:12:31 +01:00
|
|
|
.
|
2019-09-11 04:11:40 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
err()
|
|
|
|
{
|
|
|
|
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2019-09-11 04:11:40 +02:00
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
clip()
|
|
|
|
{
|
|
|
|
xclip -q -r -l 1 -sel clip 2>/dev/null
|
2019-09-11 04:11:40 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
get_user()
|
|
|
|
{
|
|
|
|
printf user
|
2020-05-25 17:42:34 +02:00
|
|
|
sekrit cp "$1/user" && printf "\n"
|
2019-09-11 04:11:40 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
get_pass()
|
|
|
|
{
|
|
|
|
printf pass
|
2020-05-25 17:42:34 +02:00
|
|
|
sekrit cp "$1/pass" && printf "\n"
|
2019-12-05 11:58:10 +01:00
|
|
|
}
|
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
get_mfa()
|
2019-12-05 11:58:10 +01:00
|
|
|
{
|
2020-05-25 17:47:09 +02:00
|
|
|
printf mfa
|
2020-07-16 19:07:54 +02:00
|
|
|
sekrit get "$1/mfa" | otpcli | clip && printf "\n"
|
2019-09-11 04:11:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
get_account()
|
2019-12-05 11:58:10 +01:00
|
|
|
{
|
2020-05-25 17:47:09 +02:00
|
|
|
account=$1
|
2019-12-05 11:58:10 +01:00
|
|
|
user=$2
|
|
|
|
pass=$3
|
2020-05-25 17:47:09 +02:00
|
|
|
mfa=$4
|
2019-09-11 04:11:40 +02:00
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
if [ $user = no ] && [ $pass = no ] && [ $mfa = no ]; then
|
|
|
|
sekrit has "$account/pass" || err "unknown account $account"
|
2019-12-28 00:20:28 +01:00
|
|
|
pass=yes
|
2020-05-25 17:47:09 +02:00
|
|
|
sekrit has "$account/user" && user=yes
|
|
|
|
sekrit has "$account/mfa" && mfa=yes
|
2019-12-28 00:20:28 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $user = check ]; then
|
2020-05-25 17:47:09 +02:00
|
|
|
sekrit has "$account/user" || err "account $account has no user"
|
2019-12-28 00:20:28 +01:00
|
|
|
user=yes
|
2019-12-16 14:50:59 +01:00
|
|
|
fi
|
2019-12-28 00:20:28 +01:00
|
|
|
if [ $pass = check ]; then
|
2020-05-25 17:47:09 +02:00
|
|
|
sekrit has "$account/pass" || err "account $account has no pass"
|
2019-12-28 00:20:28 +01:00
|
|
|
pass=yes
|
2019-12-16 14:50:59 +01:00
|
|
|
fi
|
2020-05-25 17:47:09 +02:00
|
|
|
if [ $mfa = check ]; then
|
|
|
|
sekrit has "$account/mfa" || err "account $account has no MFA"
|
|
|
|
mfa=yes
|
2019-12-16 14:50:59 +01:00
|
|
|
fi
|
2019-09-11 04:11:40 +02:00
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
[ $user = yes ] && get_user "$account"
|
|
|
|
[ $pass = yes ] && get_pass "$account"
|
|
|
|
[ $mfa = yes ] && get_mfa "$account"
|
2019-09-11 04:11:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
mfa=no
|
2019-09-11 04:11:40 +02:00
|
|
|
pass=no
|
|
|
|
user=no
|
2020-05-25 17:47:09 +02:00
|
|
|
while getopts mpu flag; do
|
2019-09-11 04:11:40 +02:00
|
|
|
case $flag in
|
2020-08-22 02:01:38 +02:00
|
|
|
m) mfa=check ;;
|
|
|
|
p) pass=check ;;
|
|
|
|
u) user=check ;;
|
|
|
|
*) usage ;;
|
2019-09-11 04:11:40 +02:00
|
|
|
esac
|
|
|
|
done
|
2020-05-03 16:47:27 +02:00
|
|
|
shift $((OPTIND - 1))
|
2019-09-11 04:11:40 +02:00
|
|
|
|
2019-12-05 11:58:10 +01:00
|
|
|
[ $# -eq 1 ] && [ -n "$1" ] || usage
|
2019-12-28 00:20:28 +01:00
|
|
|
key=$1
|
2019-09-11 04:11:40 +02:00
|
|
|
|
2020-05-25 17:47:09 +02:00
|
|
|
: ${SEKRIT_DIR:=~/keep/sekrit/accounts}
|
2020-05-25 17:42:34 +02:00
|
|
|
export SEKRIT_DIR
|
|
|
|
get_account "$key" $user $pass $mfa
|