Skip to content

Instantly share code, notes, and snippets.

@mhl
Created June 11, 2010 07:54
Show Gist options
  • Save mhl/434221 to your computer and use it in GitHub Desktop.
Save mhl/434221 to your computer and use it in GitHub Desktop.
Grab ~/.pwsafe.dat over ssh and merge it with your local version
#!/usr/bin/python3.1
import sys
import re
import tempfile
from subprocess import call, check_call
import os
def print_usage():
print("Usage: {} user@host".format(sys.argv[0]))
if len(sys.argv) != 2:
print_usage()
sys.exit(1)
user_and_host = sys.argv[1]
m = re.match("(.+)@(.+)",user_and_host)
if not m:
print_usage()
sys.exit(2)
user = m.group(1)
host = m.group(2)
if 0 != call(["pwsafe","-V"]):
print("pwsafe doesn't seem to be on your PATH")
sys.exit(3)
if 0 != call(["shred","--version"]):
print("shred doesn't seem to be on your PATH")
sys.exit(4)
f,filename = tempfile.mkstemp()
os.close(f)
try:
print("Fetching pwsafe database from user '{}' on host '{}' to temporary file: {}".format(user,host,filename))
check_call(["scp","{}@{}:.pwsafe.dat".format(user,host),filename])
merge_result = call(["pwsafe","--mergedb={}".format(filename)])
print("Merge "+("succeeded" if (merge_result == 0) else "failed"))
finally:
print("Shredding the temporary file: "+filename)
if 0 != call(["shred","--remove",filename]):
print("shredding failed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment