sekrit style fixes

This commit is contained in:
Lucas 2019-12-05 10:58:10 +00:00
parent 404fa47fd9
commit 2934979ce4
3 changed files with 52 additions and 53 deletions

View File

@ -10,7 +10,8 @@
# Dedication along with this software. If not, see # Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>. # <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() { usage()
{
cat - <<. >&2 cat - <<. >&2
Usage: Usage:
${0##*/} [-2pu] service ${0##*/} [-2pu] service
@ -18,66 +19,68 @@ Usage:
exit 1 exit 1
} }
clip() { xclip -q -r -l 1 -sel clip 2>/dev/null; } err()
{
get_user() { printf "%s: %s\n" "${0##*/}" "$*" >&2
echo user exit 1
sekrit get services/"$1"/user | clip
} }
get_pass() { clip()
echo pass {
sekrit get services/"$1"/pass | clip xclip -q -r -l 1 -sel clip 2>/dev/null
} }
get_2fa() { get_user()
echo 2fa {
printf user
sekrit get "services/$1/user" | clip && printf "\n"
}
get_pass()
{
printf pass
sekrit get "services/$1/pass" | clip && printf "\n"
}
get_2fa()
{
printf 2fa
otpcli_opts= otpcli_opts=
case $1 in case $1 in
isnic) otpcli_opts="-H sha512 -d 8" isnic) otpcli_opts="-H sha512 -d 8"
;; ;;
esac esac
sekrit get services/"$1"/2fa | otpcli $otpcli_opts | clip sekrit get "services/$1/2fa" | otpcli $otpcli_opts | clip && printf "\n"
} }
get_from_flags() { get_from_flags()
user=$1 {
pass=$2 service=$1
sfa=$3 user=$2
s=$4 pass=$3
sfa=$4
if [ $user = yes ] && ! sekrit has services/"$s"/user; then [ $user = yes ] && sekrit has services/"$service"/user ||
printf "%s: service \"%s\" has no user.\n" \ err "Service \"$service\" has no user."
"${0##*/}" "$s" >&2 [ $pass = yes ] && sekrit has services/"$service"/pass ||
exit 1 err "Service \"$service\" has no pass."
fi [ $sfa = yes ] && sekrit has services/"$service"/2fa ||
if [ $pass = yes ] && ! sekrit has services/"$s"/pass; then err "Service \"$service\" has no 2fa."
printf "%s: service \"%s\" has no pass.\n" \
"${0##*/}" "$s" >&2
exit 1
fi
if [ $sfa = yes ] && ! sekrit has services/"$s"/2fa; then
printf "%s: service \"%s\" has no 2fa.\n" \
"${0##*/}" "$s" >&2
exit 1
fi
[ $user = yes ] && get_user "$s" [ $user = yes ] && get_user "$service"
[ $pass = yes ] && get_pass "$s" [ $pass = yes ] && get_pass "$service"
[ $sfa = yes ] && get_2fa "$s" [ $sfa = yes ] && get_2fa "$service"
} }
get_all() { get_all()
s=$1 {
if ! sekrit has services/"$s"/pass; then service=$1
printf "%s: Unknown service \"%s\".\n" \ sekrit has "services/$service/pass" ||
"${0##*/}" "$s" >&2 err "Unknown service \"$service\"."
exit 1
fi
sekrit has services/"$s"/user && get_user "$s" sekrit has "services/$service/user" && get_user "$service"
get_pass "$s" get_pass "$service"
sekrit has services/"$s"/2fa && get_2fa "$s" sekrit has "services/$service/2fa" && get_2fa "$service"
} }
sfa=no sfa=no
@ -97,13 +100,11 @@ while getopts 2pu flag; do
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ $# -ne 1 ] || [ -z "$1" ]; then [ $# -eq 1 ] && [ -n "$1" ] || usage
usage
fi
service=$1 service=$1
if [ $sfa = yes ] || [ $pass = yes ] || [ $user = yes ]; then if [ $sfa = yes ] || [ $pass = yes ] || [ $user = yes ]; then
get_from_flags $user $pass $sfa "$service" get_from_flags "$service" $user $pass $sfa
else else
get_all "$service" get_all "$service"
fi fi

View File

@ -68,7 +68,7 @@ sekrit_add()
[ -f "$f" ] && err "Key \"$key\" already exists." [ -f "$f" ] && err "Key \"$key\" already exists."
if [ $# -ne 0 ]; then if [ $# -gt 0 ]; then
printf "%s\n" "$*" printf "%s\n" "$*"
else else
cat - cat -

View File

@ -10,8 +10,6 @@
# Dedication along with this software. If not, see # Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>. # <http://creativecommons.org/publicdomain/zero/1.0/>.
clip() { xclip -q -l 1 -sel clip 2>/dev/null; }
if [ $# -ne 1 ] || [ -z "$1" ]; then if [ $# -ne 1 ] || [ -z "$1" ]; then
printf "Usage: %s key\n" "${0##*/}" >&2 printf "Usage: %s key\n" "${0##*/}" >&2
exit 1 exit 1
@ -20,4 +18,4 @@ if ! sekrit has "$1"; then
printf "%s: Unknown key \"%s\".\n" "${0##*/}" "$1" >&2 printf "%s: Unknown key \"%s\".\n" "${0##*/}" "$1" >&2
exit 1 exit 1
fi fi
sekrit get "$1" | clip sekrit get "$1" | xclip -q -r -l 1 -sel clip 2>/dev/null