@@ -9,7 +9,7 @@ function help() {
9
9
Use this script as pinentry to store master password for rbw into your keyring
10
10
11
11
Usage
12
- - run "rbw-pinentry-keyring setup" once to save master password to keyring
12
+ - run "rbw-pinentry-keyring clear" to clear the master password from your keyring
13
13
- add "rbw-pinentry-keyring" as "pinentry" in rbw config (${XDG_CONFIG_HOME} /rbw/config.json)
14
14
- use rbw as normal
15
15
Notes
@@ -21,32 +21,62 @@ Notes
21
21
EOHELP
22
22
}
23
23
24
- function setup() {
25
- cmd=" SETTITLE rbw\n"
26
- cmd+=" SETPROMPT Master Password\n"
27
- cmd+=" SETDESC Please enter the master password for '$rbw_profile '\n"
28
- cmd+=" GETPIN\n"
29
- password=" $( printf " $cmd " | pinentry | grep -E " ^D " | cut -d' ' -f2) "
30
- if [ -n " $password " ]; then
31
- echo -n " $password " | secret-tool store --label=" $rbw_profile master password" application rbw profile " $rbw_profile " type master_password
32
- fi
24
+ function clear() {
25
+ secret-tool clear application rbw profile " $rbw_profile " type master_password
33
26
}
34
27
35
28
function getpin() {
36
29
echo ' OK'
37
30
31
+ title=" "
32
+ prompt=" "
33
+ desc=" "
34
+
38
35
while IFS=' ' read -r command args ; do
39
36
case " $command " in
40
- SETPROMPT|SETTITLE| SETDESC)
37
+ SETTITLE)
38
+ title=" $args "
39
+ echo ' OK'
40
+ ;;
41
+ SETDESC)
42
+ desc=" $args "
43
+ echo ' OK'
44
+ ;;
45
+ SETPROMPT)
46
+ prompt=" $args "
41
47
echo ' OK'
42
48
;;
43
49
GETPIN)
44
- secret_value=" $( secret-tool lookup application rbw profile " $rbw_profile " type master_password) "
45
- if [ -z " $secret_value " ]; then
46
- exit 1
50
+ if [[ " $prompt " == " Master Password" ]]; then
51
+ set +e
52
+ secret_value=" $( secret-tool lookup application rbw profile " $rbw_profile " type master_password) "
53
+ err=$?
54
+ set -e
55
+
56
+ if [[ $err == 1 ]]; then
57
+ cmd=" SETTITLE rbw\n"
58
+ cmd+=" SETPROMPT Master Password\n"
59
+ cmd+=" SETDESC Please enter the master password for '$rbw_profile '\n"
60
+ cmd+=" GETPIN\n"
61
+ secret_value=" $( printf " $cmd " | pinentry | grep -E " ^D " | cut -c3-) "
62
+ if [ -n " $secret_value " ]; then
63
+ echo -n " $secret_value " | secret-tool store --label=" $rbw_profile master password" application rbw profile " $rbw_profile " type master_password > /dev/null 2>&1
64
+ fi
65
+ fi
66
+
67
+ printf ' D %s\n' " $secret_value "
68
+ echo ' OK'
69
+ else
70
+ cmd=" SETTITLE $title \n"
71
+ cmd+=" SETPROMPT $prompt \n"
72
+ cmd+=" SETDESC $desc \n"
73
+ cmd+=" GETPIN\n"
74
+
75
+ secret_value=" $( printf " $cmd " | pinentry | grep -E " ^D " | cut -c3-) "
76
+
77
+ printf ' D %s\n' " $secret_value "
78
+ echo ' OK'
47
79
fi
48
- printf ' D %s\n' " $secret_value "
49
- echo ' OK'
50
80
;;
51
81
BYE)
52
82
exit
@@ -63,8 +93,8 @@ case "$command" in
63
93
-h|--help|help)
64
94
help
65
95
;;
66
- -s |--setup|setup )
67
- setup
96
+ -c |--clear|clear )
97
+ clear
68
98
;;
69
99
* )
70
100
getpin
0 commit comments