#!/usr/bin/env python2

import sys
import subprocess

def usage():
    print 'Usage: ssh_upload <user@host>'

def cat_key(host):
    key = '$HOME/.ssh/id_rsa.pub'
    remote_cmd = '"mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"'

    cmd = 'cat %s | ssh %s -- %s' % (key, host, remote_cmd)

    subprocess.call(cmd, shell=True)

def main(args):
    if len(args) < 2:
        usage()
        sys.exit(1)

    host = args[-1]

    if host == '-h' or host == '--help':
        usage()
        sys.exit

    cat_key(host)

main(sys.argv)