Due to my employer’s server-configuration, I find myself developing on remote machines often. However, I find it a pain to setup a dev environment on every new machine. So, I usually just end up working local as much as possible via SSH-FS. For anyone else that had to do this as well, here is a handly little script that will hopefully help you out (just a little).

 1 #!/usr/bin/env python
 2 from subprocess import call
 3 import os
 4  
 5 servers = [
 6   {
 7     'host': 'some.remote.host',          # host to connect to
 8     'dir' : '/usr/local/supersecret/'    # remote dir to mount
 9   },
10   {
11     'host': 'some.other.remote.host',
12     'dir' : '/home/USER/'
13   }
14 ]
15 user = os.environ['USER']
16  
17  
18 def connect():
19   """
20   Connect SSH-FS's
21   """
22   for server in servers:
23     try:
24       print("connecting to %s" %(server['host']))
25       print("------------------------------")
26       call(["sudo", "mkdir", "-p", "/Volumes/%s" % (server['host'])])
27       call(["sudo", "chown", "-R", user, "/Volumes/%s" % (server['host'])])
28       status = call(["sshfs",
29                      "%s:%s" % (server['host'], server['dir']),
30                      "/Volumes/%s" %(server['host'])])
31  
32       if status == 0:
33         print("connected")
34         print("mounted locally at /Volumes/%s" % (server['host']))
35         print("mounted remotely at %s" % (server['dir']))
36     except:
37       print "Unexpected error:", sys.exc_info()[0]
38     finally:
39       print("\n")
40  
41  
42 def get_sudo():
43   call(["echo", "Running as root. Beware!! (mwahahahaha)"])
44   call(["sudo", "echo"])
45  
46  
47 get_sudo()
48 connect()