summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-16 19:30:57 -0400
committerJesse Luehrs <doy@tozt.net>2013-08-16 19:31:44 -0400
commit2df92d971035c75685b9bda24ca42f93ae4894da (patch)
tree0c90e4b5403934b025158d68d5d1ec423ee8b0da /bin
parent071a5fcd2f2c3d250898218109a1a8db96ba851c (diff)
downloadconf-2df92d971035c75685b9bda24ca42f93ae4894da.tar.gz
conf-2df92d971035c75685b9bda24ca42f93ae4894da.zip
script for exporting pwsafe databases to pass
for reference, http://nsd.dyndns.org/pwsafe/ and http://zx2c4.com/projects/password-store/
Diffstat (limited to 'bin')
-rwxr-xr-xbin/pwsafe2pass32
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/pwsafe2pass b/bin/pwsafe2pass
new file mode 100755
index 0000000..cc21af5
--- /dev/null
+++ b/bin/pwsafe2pass
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+# run as pwsafe --exportdb | pwsafe2pass
+# requires an already initialized pass database
+
+# headers
+readline;
+readline;
+
+while (my $line = <>) {
+ my ($uuid, $group, $name, $login, $passwd, $notes) = map {
+ s/^"(.*)"$/$1/; $_
+ } split /\t/, $line;
+
+ # XXX pass doesn't handle filenames with spaces properly
+ s/\s/-/g for $group, $name;
+ die "pass can't handle files with spaces" if $login =~ /\s/;
+
+ my $entry = join '/', $group, $name, length($login) ? ($login) : ();
+
+ open my $fh, '|-', 'pass', 'insert', ($notes ? ('-m') : ()), $entry
+ or die "Couldn't insert!";
+ $fh->print("$passwd\n");
+ $fh->print("$notes\n") if $notes;
+ $fh->close;
+
+ # XXX pass doesn't propagate git failure exit codes to the overall process,
+ # so failures in 'git add' or whatever will fail silently
+ die "Failed to insert $entry: $?" if $?;
+}