summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-28 11:38:40 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-28 11:38:40 +0100
commit423ce84b1877b8efca404221b1fdb0488e6cb6db (patch)
tree4f47243e47f54cc571758af0ab66db6936af8585 /scripts
downloadresources-423ce84b1877b8efca404221b1fdb0488e6cb6db.tar.bz2
RES: Initial crud
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/add-mailcreds46
-rwxr-xr-xscripts/print-mailcreds67
-rwxr-xr-xscripts/tree-relink65
3 files changed, 178 insertions, 0 deletions
diff --git a/scripts/add-mailcreds b/scripts/add-mailcreds
new file mode 100755
index 0000000..93b1a77
--- /dev/null
+++ b/scripts/add-mailcreds
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import gtk
+import gnomekeyring as gkey
+import getpass
+
+class Keyring(object):
+ def __init__(self, name, server, protocol):
+ self._name = name
+ self._server = server
+ self._protocol = protocol
+ self._keyring = gkey.get_default_keyring_sync()
+
+ def has_credentials(self):
+ try:
+ attrs = {"server": self._server, "protocol": self._protocol}
+ items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
+ return len(items) > 0
+ except gkey.DeniedError:
+ return False
+
+ def get_credentials(self):
+ attrs = {"server": self._server, "protocol": self._protocol}
+ items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
+ return (items[0].attributes["user"], items[0].secret)
+
+ def set_credentials(self, (user, pw)):
+ attrs = {
+ "user": user,
+ "server": self._server,
+ "protocol": self._protocol,
+ }
+ gkey.item_create_sync(gkey.get_default_keyring_sync(),
+ gkey.ITEM_NETWORK_PASSWORD, self._name, attrs, pw, True)
+
+service = raw_input("Service (offlineimap, mutt, etc): ")
+protocol = raw_input("Protocol (imap, smtp, etc): ")
+server = raw_input("Server (mail.foo.bar.com): ")
+username = raw_input("Username: ")
+password = getpass.getpass(prompt="Password: ")
+print
+
+keyring = Keyring(service, server, protocol)
+
+keyring.set_credentials((username, password))
+
diff --git a/scripts/print-mailcreds b/scripts/print-mailcreds
new file mode 100755
index 0000000..0151c2c
--- /dev/null
+++ b/scripts/print-mailcreds
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+import sys
+import gtk
+import gnomekeyring as gkey
+
+class Keyring(object):
+ def __init__(self, name, server, protocol):
+ self._name = name
+ self._server = server
+ self._protocol = protocol
+ self._keyring = gkey.get_default_keyring_sync()
+
+ def has_credentials(self):
+ try:
+ attrs = {"server": self._server, "protocol": self._protocol}
+ items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
+ return len(items) > 0
+ except gkey.DeniedError:
+ return False
+
+ def get_credentials(self):
+ attrs = {"server": self._server, "protocol": self._protocol}
+ items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
+ return (items[0].attributes["user"], items[0].secret)
+
+ def set_credentials(self, (user, pw)):
+ attrs = {
+ "user": user,
+ "server": self._server,
+ "protocol": self._protocol,
+ }
+ gkey.item_create_sync(gkey.get_default_keyring_sync(),
+ gkey.ITEM_NETWORK_PASSWORD, self._name, attrs, pw, True)
+
+want_url = False
+
+if len(sys.argv) > 1:
+ if sys.argv[1] == "--url":
+ want_url = True
+ sys.argv.remove("--url")
+
+if len(sys.argv) < 4:
+ print "Usage: print-mailcreds [--url] <service> <server> <protocol>"
+ print "e.g. print-mailcreds offlineimap mail.banana.com imap"
+ print "e.g. print-mailcreds --url mutt mail.banana.com smtp"
+ sys.exit(1)
+
+service = sys.argv[1]
+server = sys.argv[2]
+protocol = sys.argv[3]
+#print "Connect"
+keyring = Keyring(service, server, protocol)
+#print "Check"
+if not keyring.has_credentials():
+ print "Failure!"
+ sys.exit(2)
+#print "Retrieve"
+(username, password) = keyring.get_credentials()
+#print "Done"
+if want_url:
+ if 'smtps' in protocol:
+ print "%s://%s:%s@%s/" % (protocol, username, password, server)
+ else:
+ print "%s://%s:%s@%s:587/" % (protocol, username, password, server)
+else:
+ print "%s : %s" % (username, password)
diff --git a/scripts/tree-relink b/scripts/tree-relink
new file mode 100755
index 0000000..521df7d
--- /dev/null
+++ b/scripts/tree-relink
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+if ($#ARGV == -1) {
+ print STDERR "usage: $0 <rootdir> [<rootdir>...]\n";
+ exit 1;
+}
+
+
+my %nodes;
+
+
+my $rootdir;
+
+while ($rootdir = shift @ARGV) {
+ print "Scanning $rootdir\n";
+
+ foreach my $filename (`find $rootdir -type f`) {
+ chomp $filename;
+ my @sinfo = stat $filename;
+ my $ino = $sinfo[1];
+ my $size = $sinfo[7];
+ unless (exists $nodes{$ino}) {
+ my $md5 = `md5sum $filename | cut -d' ' -f1`;
+ chomp $md5;
+ $nodes{$ino} = { "files" => [], "sig" => "$size.$md5" };
+ }
+ push @{$nodes{$ino}->{"files"}}, $filename;
+ }
+}
+
+print "Walking, looking for possible crosslinks\n";
+
+my $didsomething;
+
+my @nodes = keys %nodes;
+while ($#nodes != -1) {
+ my $node = shift @nodes;
+ my $sig = $nodes{$node}->{"sig"};
+ my $onefile = $nodes{$node}->{"files"}->[0];
+ delete $nodes{$node};
+ print "Considering inode $node\n";
+ foreach my $othernode (@nodes) {
+ if ($nodes{$othernode}->{"sig"} eq $sig) {
+ print "Node $othernode can be merged in...\n";
+ foreach my $filename (@{$nodes{$othernode}->{"files"}}) {
+ safe_relink($filename, $onefile);
+ }
+ delete $nodes{$othernode};
+ }
+ }
+ @nodes = keys %nodes;
+}
+
+
+exit 0;
+
+sub safe_relink {
+ my $to_replace = shift;
+ my $replace_with = shift;
+ rename("$to_replace", "${to_replace}.bak");
+ link("$replace_with", "$to_replace");
+ unlink("${to_replace}.bak");
+}