sekrit style fixes
This commit is contained in:
parent
404fa47fd9
commit
2934979ce4
@ -10,7 +10,8 @@
|
||||
# Dedication along with this software. If not, see
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
usage() {
|
||||
usage()
|
||||
{
|
||||
cat - <<. >&2
|
||||
Usage:
|
||||
${0##*/} [-2pu] service
|
||||
@ -18,66 +19,68 @@ Usage:
|
||||
exit 1
|
||||
}
|
||||
|
||||
clip() { xclip -q -r -l 1 -sel clip 2>/dev/null; }
|
||||
|
||||
get_user() {
|
||||
echo user
|
||||
sekrit get services/"$1"/user | clip
|
||||
err()
|
||||
{
|
||||
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
get_pass() {
|
||||
echo pass
|
||||
sekrit get services/"$1"/pass | clip
|
||||
clip()
|
||||
{
|
||||
xclip -q -r -l 1 -sel clip 2>/dev/null
|
||||
}
|
||||
|
||||
get_2fa() {
|
||||
echo 2fa
|
||||
get_user()
|
||||
{
|
||||
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=
|
||||
case $1 in
|
||||
isnic) otpcli_opts="-H sha512 -d 8"
|
||||
;;
|
||||
esac
|
||||
sekrit get services/"$1"/2fa | otpcli $otpcli_opts | clip
|
||||
sekrit get "services/$1/2fa" | otpcli $otpcli_opts | clip && printf "\n"
|
||||
}
|
||||
|
||||
get_from_flags() {
|
||||
user=$1
|
||||
pass=$2
|
||||
sfa=$3
|
||||
s=$4
|
||||
get_from_flags()
|
||||
{
|
||||
service=$1
|
||||
user=$2
|
||||
pass=$3
|
||||
sfa=$4
|
||||
|
||||
if [ $user = yes ] && ! sekrit has services/"$s"/user; then
|
||||
printf "%s: service \"%s\" has no user.\n" \
|
||||
"${0##*/}" "$s" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $pass = yes ] && ! sekrit has services/"$s"/pass; then
|
||||
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 ] && sekrit has services/"$service"/user ||
|
||||
err "Service \"$service\" has no user."
|
||||
[ $pass = yes ] && sekrit has services/"$service"/pass ||
|
||||
err "Service \"$service\" has no pass."
|
||||
[ $sfa = yes ] && sekrit has services/"$service"/2fa ||
|
||||
err "Service \"$service\" has no 2fa."
|
||||
|
||||
[ $user = yes ] && get_user "$s"
|
||||
[ $pass = yes ] && get_pass "$s"
|
||||
[ $sfa = yes ] && get_2fa "$s"
|
||||
[ $user = yes ] && get_user "$service"
|
||||
[ $pass = yes ] && get_pass "$service"
|
||||
[ $sfa = yes ] && get_2fa "$service"
|
||||
}
|
||||
|
||||
get_all() {
|
||||
s=$1
|
||||
if ! sekrit has services/"$s"/pass; then
|
||||
printf "%s: Unknown service \"%s\".\n" \
|
||||
"${0##*/}" "$s" >&2
|
||||
exit 1
|
||||
fi
|
||||
get_all()
|
||||
{
|
||||
service=$1
|
||||
sekrit has "services/$service/pass" ||
|
||||
err "Unknown service \"$service\"."
|
||||
|
||||
sekrit has services/"$s"/user && get_user "$s"
|
||||
get_pass "$s"
|
||||
sekrit has services/"$s"/2fa && get_2fa "$s"
|
||||
sekrit has "services/$service/user" && get_user "$service"
|
||||
get_pass "$service"
|
||||
sekrit has "services/$service/2fa" && get_2fa "$service"
|
||||
}
|
||||
|
||||
sfa=no
|
||||
@ -97,13 +100,11 @@ while getopts 2pu flag; do
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
if [ $# -ne 1 ] || [ -z "$1" ]; then
|
||||
usage
|
||||
fi
|
||||
[ $# -eq 1 ] && [ -n "$1" ] || usage
|
||||
service=$1
|
||||
|
||||
if [ $sfa = yes ] || [ $pass = yes ] || [ $user = yes ]; then
|
||||
get_from_flags $user $pass $sfa "$service"
|
||||
get_from_flags "$service" $user $pass $sfa
|
||||
else
|
||||
get_all "$service"
|
||||
fi
|
||||
|
@ -68,7 +68,7 @@ sekrit_add()
|
||||
|
||||
[ -f "$f" ] && err "Key \"$key\" already exists."
|
||||
|
||||
if [ $# -ne 0 ]; then
|
||||
if [ $# -gt 0 ]; then
|
||||
printf "%s\n" "$*"
|
||||
else
|
||||
cat -
|
||||
|
@ -10,8 +10,6 @@
|
||||
# Dedication along with this software. If not, see
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
clip() { xclip -q -l 1 -sel clip 2>/dev/null; }
|
||||
|
||||
if [ $# -ne 1 ] || [ -z "$1" ]; then
|
||||
printf "Usage: %s key\n" "${0##*/}" >&2
|
||||
exit 1
|
||||
@ -20,4 +18,4 @@ if ! sekrit has "$1"; then
|
||||
printf "%s: Unknown key \"%s\".\n" "${0##*/}" "$1" >&2
|
||||
exit 1
|
||||
fi
|
||||
sekrit get "$1" | clip
|
||||
sekrit get "$1" | xclip -q -r -l 1 -sel clip 2>/dev/null
|
||||
|
Loading…
Reference in New Issue
Block a user