Skip to content

Commit 05a9d4c

Browse files
author
Vincent Demeester
authored
Merge pull request #89 from tych0/better-initialization-check
pass: better initialization check
2 parents f00de1b + c2eec53 commit 05a9d4c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pass/pass_linux.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,25 @@ var (
2424
)
2525

2626
func init() {
27-
PassInitialized = exec.Command("pass").Run() == nil
27+
// In principle, we could just run `pass init`. However, pass has a bug
28+
// where if gpg fails, it doesn't always exit 1. Additionally, pass
29+
// uses gpg2, but gpg is the default, which may be confusing. So let's
30+
// just explictily check that pass actually can store and retreive a
31+
// password.
32+
password := "pass is initialized"
33+
name := path.Join(PASS_FOLDER, "docker-pass-initialized-check")
34+
35+
_, err := runPass(password, "insert", "-f", "-m", name)
36+
if err != nil {
37+
return
38+
}
39+
40+
stored, err := runPass("", "show", name)
41+
PassInitialized = err == nil && stored == password
42+
43+
if PassInitialized {
44+
runPass("", "rm", "-rf", name)
45+
}
2846
}
2947

3048
func runPass(stdinContent string, args ...string) (string, error) {

0 commit comments

Comments
 (0)