#!/usr/bin/env python3 import glob import hashlib import os import urllib.request def update_keys(local_user, github_user): with urllib.request.urlopen('https://github.com/%s.keys' % github_user) as f: keys = f.read().decode('utf-8').strip().splitlines() current_keys = glob.glob('keydir/%s@github-*.pub' % local_user) for path in current_keys: os.remove(path) for key in keys: m = hashlib.md5() m.update(key.encode('utf-8')) path = 'keydir/%s@github-%s.pub' % (local_user, m.hexdigest()) with open(path, 'w+') as f: f.write(key) update_keys('admin', 'GITHUB_USER')