#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
reg_token=itsm.getParameter('token') #generate the token and add it here 
reg_site=itsm.getParameter('sitelink') #Registered site link

import os
if os.path.exists("C:\Program Files (x86)"):
    URL=r"https://onedrive.live.com/download?cid=CFC812D5E983F253&resid=CFC812D5E983F253%21107&authkey=ACH6sueesNrM2lQ" #provide a URL of 64 bit package
else:
    URL=r"https://onedrive.live.com/download?cid=CFC812D5E983F253&resid=CFC812D5E983F253%21108&authkey=ADu9khsxaJxWzPM" #provide a URL of 32 bit package
import ctypes
import re
import time
import socket
import _winreg
import platform
import shutil
import ssl
import urllib2
import getpass
import zipfile
import shutil
def Download(src_path, URL,fp):
    import urllib2
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    try:
        gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        parsed = urllib2.urlopen(request,context=gcontext)
    except:
        parsed = urllib2.urlopen(request)
    if not os.path.exists(src_path):
        os.makedirs(src_path)
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    return fp
Folder=os.environ['programdata']+r"\Acronis_install"
if not os.path.exists(Folder):
    os.mkdir(Folder)
fileName=r"Acronis_install.zip"
src_path=Folder
fp = os.path.join(src_path, fileName)    
Excutable_path=Download(Folder, URL,fp)
print "Downloaded succesfully to "+Excutable_path+""
dest_path=os.environ['programdata']+r"\Acronis_install"
def filezip(Excutable_path,dest_path):
    with zipfile.ZipFile(Excutable_path,"r") as zip_ref:
        zip_ref.extractall(dest_path)
        print 'file unzipped to ' +dest_path 
filezip(Excutable_path,dest_path)
def install():
    k=os.listdir(src_path)
    for i in k:
        if not '.zip' in i:
            des_path=dest_path+"\\"+"%s"%i
            des_fname="BackupClient.msi"
            des_pname="BackupClient.msi.mst"
            des_tname="BackupClient64.msi"
            des_sname="BackupClient64.msi.mst"
            path= des_path+'\\'+des_fname
            path1= des_path+'\\'+des_pname    
            path_x64=des_path+'\\'+des_tname
            x64_path=des_path+'\\'+des_sname
            if os.path.exists("C:\Program Files (x86)"):
				command1='msiexec.exe /i '+path_x64+' /l*v my_log3.txt /qn ADDLOCAL=MmsMspComponents,BackupAndRecoveryAgent,CommandLineTool,TrayMonitor TARGETDIR="C:\Program Files\BackupClient" REBOOT=ReallySuppress MMS_CREATE_NEW_ACCOUNT=1  REGISTRATION_ADDRESS='+reg_site+' REGISTRATION_TOKEN='+reg_token
                #command1='msiexec /i  "'+path_x64+'" /qn  TRANSFORMS="'+x64_path+'" '
                
            else:
                command1='msiexec.exe /i '+path+' /l*v my_log3.txt /qn ADDLOCAL=MmsMspComponents,BackupAndRecoveryAgent,CommandLineTool,TrayMonitor TARGETDIR="C:\Program Files\BackupClient" REBOOT=ReallySuppress MMS_CREATE_NEW_ACCOUNT=1  REGISTRATION_ADDRESS='+reg_site+' REGISTRATION_TOKEN='+reg_token
                
            command=os.popen(command1).read()
            print "Acronics backup successfully installed :-)"
install()
try:
    os.chmod(dest_path,0664)
    shutil.rmtree(dest_path)
except:
    pass
