#!/usr/bin/python import sys,os user = os.getuid() groups = os.getgroups() DEBUG = False try: d=sys.argv[1] if d.lower() == 'debug': DEBUG=True except: pass try: import xmlrpclib as x import hashlib import base64 import os.path import StringIO import tarfile import subprocess import shutil import tempfile c=x.ServerProxy("https://server:9779") try: md5,pack=c.get_profile_pack('','PlankSync',{'u':user,'g':groups}) except: import traceback print '{}'.format(traceback.format_exc()) print '{}'.format(c.get_profile_pack('','PlankSync',{'u':user,'g':groups})) sys.exit(1) decoded=base64.b64decode(pack) if md5 == hashlib.md5(decoded).hexdigest(): dir=tempfile.mkdtemp('','syncer-client') if not os.path.exists(dir): os.mkdir(dir,0o777) else: shutil.rmtree(dir) os.mkdir(dir,0o777) with tarfile.open(fileobj=StringIO.StringIO(decoded)) as f: f.extractall(dir) if DEBUG: print dir out='' for root,dirnames,filenames in os.walk(dir): program='/usr/bin/syncer' for filename in filenames: if DEBUG: sequence = ['-d','-i','-r '+dir+'/'+filename,'-s','-p'] else: sequence = ['-d','-i','-r '+dir+'/'+filename,'-p'] for cmd in sequence: call=[program,'-w '+dir+' ',cmd] try: out+=subprocess.check_output(call,stderr=subprocess.STDOUT) except Exception as e: print(e) if not DEBUG: shutil.rmtree(dir) print(out.replace('\n','').strip()) except Exception as e: print(e) sys.exit(0)