Skip to content

Instantly share code, notes, and snippets.

@aresnick
Created May 8, 2014 20:50
Show Gist options
  • Save aresnick/032dc2b62fbcadcb4d29 to your computer and use it in GitHub Desktop.
Save aresnick/032dc2b62fbcadcb4d29 to your computer and use it in GitHub Desktop.
BeagleBone Black sshfs mirror
#!/usr/bin/env python
import subprocess
# This installs pip; if you already have it, comment out the next three lines
subprocess.call(['curl', '-O', 'https://bootstrap.pypa.io/get-pip.py'])
subprocess.call(['chmod', '755', 'get-pip.py'])
subprocess.call(['python get-pip.py'], shell=True)
# This installs envoy
subprocess.call(['pip', 'install', 'envoy'], shell=True)
import os
import envoy
def file_exists(path):
print "Checking if " + path + " exists locally. . ."
r = envoy.run(' '.join(['ls', path])).status_code == 0
if r:
print path + " exists."
else:
print path + " does not exist."
return r
def process_running(search_string):
print "Checking if " + search_string + " is running already locally. . ."
r = int(envoy.run('ps aux | grep ' + search_string + ' | grep -v grep | wc -l').std_out) > 0
if r:
print search_string + " appears in a running process."
else:
print "No running process found containing " + search_string
return r
def sshfs(user, host, remote_path, local_path):
full_local_path = os.path.join(envoy.run('pwd').std_out.strip(), local_path)
print "Setting up sshfs to mirror " + remote_path + " on " + user+"@"+host + " to " + full_local_path
r = envoy.run(' '.join([
'sshfs -o defer_permissions',
user + '@' + 'host' + ':' + remote_path,
full_local_path]))
if r.status_code == 0:
print "sshfs mirror of " + remote_path + " on " + user+"@"+host + " to " + local_path + " setup."
else:
print "Error encountered setting up sshfs mirror of " + remote_path + " on " + user+"@"+host + " to " + local_path + ":\n"
print r.std_err
DEFAULT_PATH = 'beagle'
BB_IP = '192.168.7.2'
BB_DEFAULT_PATH = '/var/lib/cloud9/beagle'
DEFAULT_BB_USER = 'root'
if not file_exists(DEFAULT_PATH + '/'):
envoy.run('mkdir ' + DEFAULT_PATH)
if not process_running('sshfs') and not process_running(BB_IP):
sshfs(DEFAULT_BB_USER, BB_IP, BB_DEFAULT_PATH, DEFAULT_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment