Added pass extensions
To tried to properly explain. Pretty easy to read. Go do that.
This commit is contained in:
parent
494ea1de35
commit
0bc487ccc9
90
pass/extensions/get.bash
Executable file
90
pass/extensions/get.bash
Executable file
|
@ -0,0 +1,90 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# pass get - Password Store Extension (https://www.passwordstore.org/)
|
||||||
|
# Copyright (C) 2020 James Patrick
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
R='\033[0;31m'
|
||||||
|
G='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
PASSWORD_STORE_DIR="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
||||||
|
|
||||||
|
cmd_get_usage() {
|
||||||
|
cat <<-_EOF
|
||||||
|
Usage:
|
||||||
|
$PROGRAM get pattern pass_name
|
||||||
|
Parses the pass data for lines pulling out the value of browserpass's
|
||||||
|
format of "key:value". The 'pattern' arg is a case insenitive, extended
|
||||||
|
regex using grep -iE.
|
||||||
|
|
||||||
|
https://github.com/browserpass/browserpass-extension
|
||||||
|
|
||||||
|
Options:
|
||||||
|
Nada.
|
||||||
|
_EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cmd_get_assert(){
|
||||||
|
test="$1"
|
||||||
|
local pattern="$2" expected="$3"
|
||||||
|
|
||||||
|
actual="$(cmd_get "$pattern")"
|
||||||
|
if [[ "$actual" == "$expected" ]] ; then
|
||||||
|
echo -e "$G ✔ '$actual' == '$expected' $NC"
|
||||||
|
else
|
||||||
|
echo -e "$R ✘ f('$test', '$pattern') → '$actual' != '$expected' $NC"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_get_test(){
|
||||||
|
cmd_get_assert "username:value" "(user|username|login)" "value"
|
||||||
|
cmd_get_assert " user: whitespace" "(user|username|login)" "whitespace"
|
||||||
|
|
||||||
|
val="multiple:lines
|
||||||
|
value:pairs"
|
||||||
|
cmd_get_assert "$val" "value" "pairs"
|
||||||
|
cmd_get_assert "Key:capitalization doesn't counts" "key" \
|
||||||
|
"capitalization doesn't counts"
|
||||||
|
cmd_get_assert "missing:empty" "i don't exist" ""
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_get(){
|
||||||
|
local pattern="$1" pass_name="$2"
|
||||||
|
|
||||||
|
# valid the regex is valid
|
||||||
|
echo | grep -qiE "$pattern"
|
||||||
|
if [[ "$?" == 2 ]] ; then
|
||||||
|
>&2 echo -e "${R}Invalid Pattern:${NC} $pattern"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${test:-$(cmd_show "$pass_name")}" \
|
||||||
|
| grep -iE "$pattern" \
|
||||||
|
| head -1 \
|
||||||
|
| cut -d ':' -f2- \
|
||||||
|
| sed -e 's/^[ \t]*//'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[[ "$1" == "test" ]] && cmd_get_test
|
||||||
|
[[ "$1" == "help" || "$1" == "--help" || "$1" == "-h" ]] && cmd_get_usage
|
||||||
|
[[ "$#" != "2" ]] && cmd_get_usage
|
||||||
|
cmd_get "$@"
|
49
pass/extensions/get_pass.bash
Executable file
49
pass/extensions/get_pass.bash
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# pass get - Password Store Extension (https://www.passwordstore.org/)
|
||||||
|
# Copyright (C) 2020 James Patrick
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
PASSWORD_STORE_DIR="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
||||||
|
|
||||||
|
cmd_get_pass_usage() {
|
||||||
|
cat <<-_EOF
|
||||||
|
TODO:
|
||||||
|
Usage:
|
||||||
|
$PROGRAM get_pass pass_name
|
||||||
|
Grabs the pass based on rules for Browserpass.
|
||||||
|
1. match "key:value" where key, either pass, password, or secret
|
||||||
|
2. if no match is present default to the first line.
|
||||||
|
|
||||||
|
https://github.com/browserpass/browserpass-extension
|
||||||
|
|
||||||
|
Options:
|
||||||
|
Nada.
|
||||||
|
_EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cmd_get_user(){
|
||||||
|
local pass_name="$1" val backup
|
||||||
|
val=$(pass get "(pass|password|secret)" "$pass_name")
|
||||||
|
backup=$(cmd_show "$pass_name" | head -1)
|
||||||
|
echo "${val:-$backup}"
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ "$1" == "help" || "$1" == "--help" || "$1" == "-h" ]] && cmd_get_user_usage
|
||||||
|
[[ "$#" != "1" ]] && cmd_get_user_usage
|
||||||
|
cmd_get_user "$@"
|
49
pass/extensions/get_user.bash
Executable file
49
pass/extensions/get_user.bash
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# pass get - Password Store Extension (https://www.passwordstore.org/)
|
||||||
|
# Copyright (C) 2020 James Patrick
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
PASSWORD_STORE_DIR="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
||||||
|
|
||||||
|
cmd_get_user_usage() {
|
||||||
|
cat <<-_EOF
|
||||||
|
TODO:
|
||||||
|
Usage:
|
||||||
|
$PROGRAM get_user pass_name
|
||||||
|
Grabs the username based on rules for Browserpass.
|
||||||
|
1. match "key:value" where key, either user, username, or login
|
||||||
|
2. if no match is present default to a trimmed filename.
|
||||||
|
|
||||||
|
https://github.com/browserpass/browserpass-extension
|
||||||
|
|
||||||
|
Options:
|
||||||
|
Nada.
|
||||||
|
_EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cmd_get_user(){
|
||||||
|
local pass_name="$1" val
|
||||||
|
val=$(pass get "(user|username|login)" "$pass_name")
|
||||||
|
backup=$(echo "$pass_name" | awk -F"/" '{print $NF}' )
|
||||||
|
echo "${val:-$backup}"
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ "$1" == "help" || "$1" == "--help" || "$1" == "-h" ]] && cmd_get_user_usage
|
||||||
|
[[ "$#" != "1" ]] && cmd_get_user_usage
|
||||||
|
cmd_get_user "$@"
|
24
pass/makefile
Normal file
24
pass/makefile
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- mode: makefile-gmake; -*-
|
||||||
|
SRC := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
include ../lib/shared.mk
|
||||||
|
TARGET := ~/.password-store
|
||||||
|
|
||||||
|
install: | init update
|
||||||
|
|
||||||
|
init:
|
||||||
|
if (( $$+commands[pass] )) ; then
|
||||||
|
$(report) header "Setting up pass"
|
||||||
|
[ -e $(TARGET) ] \
|
||||||
|
&& $(mk_link) $(SRC)/extensions $(TARGET)/.extensions \
|
||||||
|
|| $(report) warn "$(TARGET) doesn't exist. Skipping."
|
||||||
|
else
|
||||||
|
$(report) debug " pass not installed. Skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
|
update:
|
||||||
|
|
||||||
|
|
||||||
|
remove:
|
||||||
|
$(report) header "Removing pass"
|
||||||
|
$(rm_link) $(TARGET)
|
Loading…
Reference in New Issue
Block a user