def Download(self): rc = 0 if not CheckOsascript() and not CheckCocoasudo(self.install): rc = InstallCocoasudo(self.tmp, self.install, self.progress) if rc != 0: return rc if not self.__checkLibssh(): subutai.AddStatus("Downloading libssh2") subutai.download(self.LibsshFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setLibsshProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setLibsshProgress(self.progress.getLibsshSize()) self.progress.updateProgress() subutai.download(self.TrayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setTrayProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setTrayProgress(self.progress.getTraySize()) self.progress.updateProgress() return rc
def Download(self): rc = 0 subutai.AddStatus("Installing") if not self.__checkNssm(): subutai.download(self.NssmFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setNssmProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setNssmProgress(self.progress.getNssmSize()) self.progress.updateProgress() try: copyfile(self.tmp + self.NssmFile, self.install + "bin/" + self.NssmFile) except: subutai.RaiseError( "Failed to move NSSM file to it's destination") return 14 else: subutai.UnregisterService("Subutai P2P") subutai.ProcessKill("nssm.exe") subutai.ProcessKill("p2p.exe") rc = self.__installTuntap() subutai.download(self.RemoteP2PFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setP2PProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setP2PProgress(self.progress.getP2PSize()) self.progress.updateProgress() try: copyfile(self.tmp + self.RemoteP2PFile, self.install + "bin/" + self.P2PFile) except: subutai.RaiseError("Failed to move p2p binary to " + self.install + "bin/" + self.P2PFile) return 19 try: st = os.stat(self.install + "/bin/" + self.P2PFile) os.chmod(self.install + "/bin/" + self.P2PFile, st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to make p2p binary executable") return 31 return rc
def Download(self): rc = 0 subutai.AddStatus("Installing") if not CheckOsascript() and not CheckCocoasudo(self.install): rc = InstallCocoasudo(self.tmp, self.install, self.progress) if rc != 0: return rc if not self.__checkTuntap(): self.__installTuntap() subutai.download(self.RemoteP2PFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setP2PProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setP2PProgress(self.progress.getP2PSize()) self.progress.updateProgress() try: copyfile(self.tmp+self.RemoteP2PFile, self.install+"bin/"+self.P2PFile) except: subutai.RaiseError("Failed to move p2p binary to " + self.install + "bin/"+self.P2PFile) return 19 try: st = os.stat(self.install+"/bin/"+self.P2PFile) os.chmod(self.install+"/bin/"+self.P2PFile, st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to make p2p binary executable") return 31 return rc
def SetupVirtualMachine(self): subutai.AddStatus("Setting up virtual machine") subutai.SetAction("INSTVM") rc = 0 subutai.AddStatus("Installing VM") if subutai.CheckVMExists(self.name) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setCoreProgress(subutai.GetBytesDownload()) self.progress.updateProgress() subutai.AddStatus("VM Image downloaded") self.progress.setCoreProgress(self.progress.getCoreSize()) self.progress.updateProgress() rc = subutai.VBoxS("import " + subutai.GetTmpDir().replace(" ", "+++") + "core.ova --vsys 0 --vmname " + self.name) if rc != 0: subutai.RaiseError("Failed to import Virtual Machine") return rc sleep(3) cpus = subutai.GetCoreNum() mem = subutai.GetMemSize() * 1024 subutai.VBox("modifyvm " + self.name + " --cpus " + str(cpus)) subutai.VBox("modifyvm " + self.name + " --memory " + str(mem)) return rc
def subutaistart(): p2pSize = subutai.GetFileSize("p2p") totalSize = p2pSize p2pProgress = 0 subutai.AddStatus("Download p2p binary") sfile = "/etc/systemd/system/p2p.service" if os.path.exists(sfile): subutai.RemoveSystemdUnit("p2p.service") subutai.download("p2p") while subutai.isDownloadComplete() != 1: sleep(0.05) p2pProgress = subutai.GetBytesDownload() updateProgress(p2pProgress, totalSize) subutai.SetProgress(1.0) tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() subutai.AddStatus("Download finished. Installing") copyfile(tmpDir+"/p2p", installDir+"/bin/p2p") st = os.stat(installDir+"/bin/p2p") os.chmod(installDir+"/bin/p2p", st.st_mode | stat.S_IEXEC) subutai.AddStatus("Creating symlink") subutai.MakeLink(installDir+"/bin/p2p", "/usr/bin/p2p") subutai.AddStatus("Creating systemd unit") unit = ''' [Unit] Description=Service for Subutai p2p daemon Wants=network-online.target After=network-online.target [Service] ExecStart=/opt/subutai/bin/p2p daemon Restart=on-failure WorkingDirectory=/opt/subutai/ TimeoutStopSec=30 Type=simple [Install] WantedBy=multi-user.target '''.strip() f = open(tmpDir+"p2p.service", 'w') f.write(unit) f.close() subutai.AddSystemdUnit("p2p.service", tmpDir+"p2p.service") subutai.Shutdown() return 0
def subutaistart(): tmpDir = subutai.GetTmpDir() chromeFilename = "GoogleChromeStandaloneEnterprise64.msi" chromeSize = subutai.GetFileSize(chromeFilename) totalSize = chromeSize chromeProgress = 0 if subutai.IsChromeInstalled() != 0: subutai.AddStatus("Downloading Chrome") subutai.download(chromeFilename) while subutai.isDownloadComplete() != 1: sleep(0.05) chromeProgress = subutai.GetBytesDownload() updateProgress(chromeProgress, totalSize) chromeProgress = chromeSize subutai.AddStatus("Installing Chrome") try: call(['msiexec', '/qn', '/i', tmpDir + chromeFilename]) except: subutai.RaiseError("Failed to install Google Chrome") sleep(5) subutai.AddStatus("Installing Browser Plugin") subutai.RegisterPlugin() subutai.Shutdown() return 0
def __installTuntap(self): while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setTuntapProgress(subutai.GetBytesDownload()) self.progress.setTuntapProgress(self.progress.getTuntapSize()) self.progress.updateProgress() return 0
def subutaistart(): subutai.AddStatus("Download Tray application") trayFile = "SubutaiTray_libs.tar.gz" traySize = subutai.GetFileSize(trayFile) totalSize = traySize trayProgress = 0 subutai.download(trayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) trayProgress = subutai.GetBytesDownload() updateProgress(trayProgress, totalSize) trayProgress = traySize tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() subutai.AddStatus("Unpacking Tray") call(['/usr/bin/killall', '-9', 'SubutaiTray']) tar = tarfile.open(tmpDir + "/" + trayFile, "r:gz") tar.extractall(installDir + "/bin/") tar.close() subutai.AddStatus("Creating Symlink") subutai.MakeLink(installDir + "/bin/SubutaiTray", "/usr/local/bin/SubutaiTray") desktop = ''' [Desktop Entry] Version=1.0 Name=Subutai Tray Comment=Subutai Tray Keywords=Internet; Exec=SubutaiTray Terminal=false Type=Application Icon=/usr/share/icons/launcher-logo.png Categories=GNOME;Network; StartupNotify=true '''.strip() f = open(tmpDir + "SubutaiTray.desktop", 'w') f.write(desktop) f.close() subutai.DesktopFileInstall(tmpDir + "SubutaiTray.desktop") subutai.StartTray() subutai.Shutdown() return 0
def DownloadP2P(p2p, progress): subutai.download(p2p) while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setP2PProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setP2PProgress(subutai.getP2PSize()) return 0
def Download(self): rc = 0 subutai.download(self.TrayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setTrayProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setTrayProgress(self.progress.getTraySize()) self.progress.updateProgress() return rc
def Download(self): rc = 0 subutai.AddStatus("Downloading") subutai.download(self.RemoteP2PFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setP2PProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setP2PProgress(self.progress.getP2PSize()) self.progress.updateProgress() return rc
def Download(self): rc = 0 if not self.__checkGoogleChrome(): subutai.AddStatus("Downloading Google Chrome") subutai.download(self.GoogleChromeFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setChromeProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setChromeProgress(self.progress.getChromeSize()) self.progress.updateProgress() return rc
def Download(self): rc = 0 subutai.AddStatus("Downloading libssh2") subutai.download(self.LibsshFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setLibsshProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setLibsshProgress(self.progress.getLibsshSize()) self.progress.updateProgress() subutai.ProcessKill("SubutaiTray.exe") subutai.ProcessKill("ssh.exe") subutai.ProcessKill("ssh-keygen.exe") subutai.download(self.TrayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setTrayProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setTrayProgress(self.progress.getTraySize()) self.progress.updateProgress() try: zf = zipfile.ZipFile(self.tmp + self.TrayFile, 'r') zf.extractall(self.install) zf.close() zfl = zipfile.ZipFile(self.tmp + self.LibsshFile, 'r') zfl.extractall(self.install + "/bin") zfl.close() except: subutai.RaiseError("Failed to replace tray") return rc
def __installTuntap(self): subutai.SetStep("TAPINST") subutai.AddStatus("Downloading TUN/TAP driver") subutai.download(self.TapFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setTuntapProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setTuntapProgress(self.progress.getTuntapSize()) self.progress.updateProgress() subutai.Information("Running TAP installation") subutai.AddStatus("Installing TUN/TAP driver") r = call([self.tmp + self.TapFile, '/S']) if r != 0: subutai.RaiseError("Failed to install TUN/TAP Driver") return r
def InstallVirtualBox(tmp, install, progress): subutai.AddStatus("Downloading VirtualBox") subutai.download(GetVirtualBoxName()) while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setVboxProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setVboxProgress(progress.getVboxSize()) progress.updateProgress() subutai.AddStatus("Installing VirtualBox") try: call([tmp + GetVirtualBoxName(), '-silent']) except: subutai.RaiseError("Failed to install VirtualBox. Aborting") return 45 return 0
def Download(self): subutai.SetAction('DWL') rc = 0 if not CheckOsascript() and not CheckCocoasudo(self.install): rc = InstallCocoasudo(self.tmp, self.install, self.progress) if rc != 0: return rc if not self.__checkGoogleChrome(): subutai.AddStatus("Downloading Google Chrome") subutai.download(self.GoogleChromeFile) while subutai.isDownloadComplete() != 1: sleep(0.05) self.progress.setChromeProgress(subutai.GetBytesDownload()) self.progress.updateProgress() self.progress.setChromeProgress(self.progress.getChromeSize()) self.updateProgress() return rc
def installVBox(vboxFile, tmpDir, installDir, progress): if subutai.IsVBoxInstalled() != 0: subutai.AddStatus("Downloading VirtualBox") subutai.download(vboxFile) while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setVboxProgress(subutai.GetBytesDownload()) progress.updateProgress() subutai.AddStatus("Installing VirtualBox") subutai.InstallVBox(tmpDir+vboxFile) progress.setVboxProgress(progress.getVboxSize()) progress.updateProgress() if subutai.IsVBoxInstalled() != 0: subutai.AddStatus("Failed to install VirtualBox. Aborting") return 24 return 0
def InstallCocoasudo(tmp, install, progress): subutai.AddStatus("Downloading cocoasudo application") subutai.download("cocoasudo") while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setCocoasudoProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setCocoasudoProgress(progress.getCocoasudoSize()) progress.updateProgress() subutai.AddStatus("Installing cocoasudo") try: copyfile(tmp+"cocoasudo", install+"bin/cocoasudo") st = os.stat(install+"bin/cocoasudo") os.chmod(install+"bin/cocoasudo", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to install cocoasudo. Aborting") return -87 return 0
def InstallVirtualBox(tmp, install, progress): subutai.AddStatus("Downloading VirtualBox") subutai.download("VirtualBox.pkg") while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setVboxProgress(subutai.GetBytesDownload()) progress.updateProgress() subutai.AddStatus("Installing VirtualBox") try: CheckAndKillVirtualBox() if not CheckOsascript(): returnCode = call([install+"bin/cocoasudo", '--prompt="Install VirtualBox"', 'installer', '-pkg', tmp+'VirtualBox.pkg', '-target', '/']) if returnCode != 0: return 21 else: ins = 'do shell script "installer -pkg '+tmp+'VirtualBox.pkg -target /" with administrator privileges' p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) stdout, stderr = p.communicate(ins) if p.returncode != 0: return 23 except: subutai.RaiseError("Failed to install VirtualBox. Aborting") sleep(10) return 45 progress.setVboxProgress(progress.getVboxSize()) progress.updateProgress() if not os.path.exists("/Applications/VirtualBox.app"): subutai.AddStatus("Failed to install VirtualBox. Aborting") return 24 return 0
def InstallVirtualBox(tmp, install, progress): subutai.AddStatus("Downloading VirtualBox") subutai.download(GetVirtualBoxName()) while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setVboxProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setVboxProgress(progress.getVboxSize()) progress.updateProgress() try: subutai.AddStatus("Installing VirtualBox") postinst = subuco.PostInstall(tmp) postinst.append('dpkg -i ' + tmp + GetVirtualBoxName()) postinst.append('modprobe vboxdrv >> /tmp/subutai/vbox.log 2>&1') postinst.append('modprobe vboxnetflt >> /tmp/subutai/vbox.log 2>&1') postinst.append('modprobe vboxnetadp >> /tmp/subutai/vbox.log 2>&1') postinst.append('modprobe vboxpci >> /tmp/subutai/vbox.log 2>&1') postinst.append("apt-get install -f -y") postinst.append('cat /tmp/subutai/vbox.log') p = run([ '/usr/bin/gksudo', '--message', 'Install VirtualBox', postinst.get() ], stdout=PIPE, stderr=PIPE, encoding="utf-8") if p.stdout != '': subutai.Information(p.stdout) if p.stderr != '': subutai.Error(p.stderr) except: subutai.RaiseError("Failed to install VirtualBox. Aborting") return 45 if not CheckVirtualBox(): subutai.RaiseError("Failed to install VirtualBox. Aborting") return 24 return 0
def setupVm(machineName, progress): subutai.log("info", "Setting up a VM") subutai.AddStatus("Installing VM") rc = 0 if subutai.CheckVMExists(machineName) != 0: subutai.download("core.ova") while subutai.isDownloadComplete() != 1: sleep(0.05) progress.setCoreProgress(subutai.GetBytesDownload()) progress.updateProgress() progress.setCoreProgress(progress.getCoreSize()) progress.updateProgress() rc = subutai.VBoxS("import " + subutai.GetTmpDir().replace(" ", "+++") + "core.ova --vsys 0 --vmname "+machineName) if rc != 0: return rc sleep(3) cpus = subutai.GetCoreNum() mem = subutai.GetMemSize() * 1024 subutai.VBox("modifyvm " + machineName + " --cpus " + str(cpus)) subutai.VBox("modifyvm " + machineName + " --memory " + str(mem)) subutai.VBox("modifyvm " + machineName + " --nic1 nat") subutai.VBox("modifyvm " + machineName + " --cableconnected1 on") subutai.VBox("modifyvm " + machineName + " --natpf1 ssh-fwd,tcp,,4567,,22 --natpf1 https-fwd,tcp,,9999,,8443") subutai.VBox("modifyvm " + machineName + " --rtcuseutc on") adapterName = subutai.GetVBoxHostOnlyInterface() if adapterName != 'undefined': subutai.VBox("modifyvm " + machineName + " --nic3 hostonly --hostonlyadapter3 " + adapterName) sleep(1) return rc
def subutaistart(): tmpDir = subutai.GetTmpDir() subutai.AddStatus("Downloading Google Chrome") chromeFilename = "google-chrome-stable_current_amd64.deb" chromeSize = subutai.GetFileSize(chromeFilename) totalSize = chromeSize chromeProgress = 0 subutai.download(chromeFilename) while subutai.isDownloadComplete() != 1: sleep(0.05) chromeProgress = subutai.GetBytesDownload() updateProgress(chromeProgress, totalSize) chromeProgress = chromeSize try: call([ '/usr/bin/gksudo', '--message', 'Install Google Chrome Dependencies', 'apt-get install libappindicator1 -y' ]) call([ '/usr/bin/gksudo', '--message', 'Install Google Chrome', 'dpkg -i ' + tmpDir + chromeFilename ]) sleep(20) except: subutai.RaiseError("Failed to install Google Chrome") sleep(5) subutai.AddStatus("Installing Browser Plugin") #location = os.environ['HOME'] + '/.config/google-chrome/Default/External Extensions' location = '/opt/google/chrome/extensions/' if not os.path.exists(location): try: call([ '/usr/bin/gksudo', '--message', 'Create extension directory', 'mkdir -p ' + location ]) except: subutai.RaiseError("Failed to create " + location + " directory") sleep(5) return -22 ete = '{\n\t"external_update_url": "https://clients2.google.com/service/update2/crx"\n}\n' f = open(tmpDir + "kpmiofpmlciacjblommkcinncmneeoaa.json", 'w') f.write(ete) # python will convert \n to os.linesep f.close() try: call([ '/usr/bin/gksudo', '--message', 'Create extension directory', 'cp ' + tmpDir + 'kpmiofpmlciacjblommkcinncmneeoaa.json ' + location ]) except: subutai.RaiseError("Failed to move extension file") sleep(5) return -22 subutai.Shutdown() return 0
def subutaistart(): tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() trayFile = "SubutaiTray_libs_osx.tar.gz" libsshFile = "libssh2-1.6.0-0_osx.pkg" cocoasudoFile = "cocoasudo" cocoasudoSize = subutai.GetFileSize(cocoasudoFile) traySize = subutai.GetFileSize(trayFile) libsshSize = subutai.GetFileSize(libsshFile) totalSize = cocoasudoSize + traySize + libsshSize cocoasudoProgress = 0 trayProgress = 0 libsshProgress = 0 if not os.path.exists(installDir + "bin/cocoasudo"): subutai.AddStatus("Downloading cocoasudo application") subutai.download(cocoasudoFile) while subutai.isDownloadComplete() != 1: sleep(0.05) cocoasudoProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, trayProgress, libsshProgress, totalSize) try: copyfile(tmpDir + cocoasudoFile, installDir + "bin/cocoasudo") st = os.stat(installDir + "bin/cocoasudo") os.chmod(installDir + "bin/cocoasudo", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to install cocoasudo. Aborting") sleep(10) return -99 cocoasudoProgress = cocoasudoSize subutai.AddStatus("Download Tray application") subutai.download(trayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) trayProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, trayProgress, libsshProgress, totalSize) trayProgress = traySize subutai.AddStatus("Installing Tray") try: tar = tarfile.open(tmpDir + "/" + trayFile, "r:gz") tar.extractall("/Applications/Subutai") tar.close() except: subutai.RaiseError("Failed to unpack Tray archive. Aborting") sleep(10) return 86 subutai.AddStatus("Installing Tray dependencies") subutai.download(libsshFile) while subutai.isDownloadComplete() != 1: sleep(0.05) libsshProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, trayProgress, libsshProgress, totalSize) libsshProgress = libsshSize try: call([ installDir + 'bin/cocoasudo', '-prompt="Install libssh"', 'installer', '-pkg', tmpDir + '/' + libsshFile, '-target', '/' ]) except: subutai.RaiseError("Failed to install libssh. Aborting") sleep(10) return -99 try: launch = 'tell application "SubutaiTray.app" to activate' p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) stdout, stderr = p.communicate(launch) except: subutai.RaiseError("Failed to launch Subutai Tray application") subutai.Shutdown() return 0
def subutaistart(): tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() nssmSize = subutai.GetFileSize("nssm.exe") p2pSize = subutai.GetFileSize("p2p.exe") tuntapSize = subutai.GetFileSize("tap-windows-9.21.2.exe") totalSize = nssmSize + p2pSize + tuntapSize nssmProgress = 0 p2pProgress = 0 tuntapProgress = 0 subutai.AddStatus("Installing Service Manager") if os.path.exists(installDir + "nssm.exe"): subutai.UnregisterService("Subutai P2P") sleep(30) subutai.ProcessKill("nssm.exe") subutai.download("nssm.exe") while subutai.isDownloadComplete() != 1: sleep(0.05) nssmProgress = subutai.GetBytesDownload() updateProgress(nssmProgress, p2pProgress, tuntapProgress, totalSize) copyfile(tmpDir + "nssm.exe", installDir + "bin/nssm.exe") if not os.path.exists(installDir + "nssm.exe"): subutai.download("nssm.exe") while subutai.isDownloadComplete() != 1: sleep(0.05) nssmProgress = subutai.GetBytesDownload() updateProgress(nssmProgress, p2pProgress, tuntapProgress, totalSize) subutai.UnregisterService("Subutai P2P") sleep(30) subutai.ProcessKill("nssm.exe") copyfile(tmpDir + "nssm.exe", installDir + "bin/nssm.exe") nssmProgress = nssmSize subutai.AddStatus("Downloading p2p binary") subutai.download("p2p.exe") while subutai.isDownloadComplete() != 1: sleep(0.05) p2pProgress = subutai.GetBytesDownload() updateProgress(nssmProgress, p2pProgress, tuntapProgress, totalSize) p2pProgress = p2pSize subutai.AddStatus("Downloading extra tools") subutai.download("tap-windows-9.21.2.exe") while subutai.isDownloadComplete() != 1: sleep(0.05) tuntapProgress = subutai.GetBytesDownload() updateProgress(nssmProgress, p2pProgress, tuntapProgress, totalSize) tuntapProgress = tuntapSize subutai.ProcessKill("p2p.exe") subutai.AddStatus("Installing P2P") if os.path.exists(installDir + "bin/p2p.exe"): subutai.AddStatus("Removing previous installation") os.remove(installDir + "bin/p2p.exe") if os.path.exists(installDir + "bin/p2p.exe"): subutai.RaiseError("Failed to remove p2p binary") subutai.AddStatus("Copying files") copyfile(tmpDir + "p2p.exe", installDir + "bin/p2p.exe") st = os.stat(installDir + "bin/p2p.exe") os.chmod(installDir + "bin/p2p.exe", st.st_mode | stat.S_IEXEC) subutai.AddStatus("Registering P2P as a Windows service") subutai.RegisterService("Subutai P2P", installDir + "bin/p2p.exe|daemon") subutai.AddStatus("Installing TUN/TAP driver") call([tmpDir + 'tap-windows-9.21.2.exe', '/S']) sleep(5) subutai.Shutdown() return 0
def subutaistart(): tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() cocoasudoSize = subutai.GetFileSize("cocoasudo") chromeSize = subutai.GetFileSize("GoogleChrome_osx.tar.gz") totalSize = cocoasudoSize + chromeSize cocoasudoProgress = 0 chromeProgress = 0 if not os.path.exists(installDir + "bin/cocoasudo"): subutai.AddStatus("Downloading cocoasudo application") subutai.download("cocoasudo") while subutai.isDownloadComplete() != 1: sleep(0.05) cocoasudoProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, chromeProgress, totalSize) try: copyfile(tmpDir + "cocoasudo", installDir + "bin/cocoasudo") st = os.stat(installDir + "bin/cocoasudo") os.chmod(installDir + "bin/cocoasudo", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to install cocoasudo. Aborting") sleep(10) return -99 cocoasudoProgress = cocoasudoSize subutai.AddStatus("Checking Google Chrome Installation") if not os.path.exists("/Applications/Google Chrome.app"): subutai.AddStatus("Downloading Google Chrome") subutai.download("GoogleChrome_osx.tar.gz") while subutai.isDownloadComplete() != 1: sleep(0.05) chromeProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, chromeProgress, totalSize) subutai.AddStatus("Download Complete") chromeProgress = chromeSize updateProgress(cocoasudoProgress, chromeProgress, totalSize) #try: # script = 'quit Application \"Google Chrome.app\"' # p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) # stdout, stderr = p.communicate(script) #except: # subutai.RaiseError("Failed to stop Google Chrome") # sleep(10) sleep(1) subutai.AddStatus("Installing Google Chrome") try: script = 'do shell script "/usr/bin/tar -xf ' + tmpDir + 'GoogleChrome_osx.tar.gz -C /Applications" with administrator privileges' p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) stdout, stderr = p.communicate(script) except: subutai.RaiseError("Failed to install Google Chrome") sleep(5) subutai.AddStatus("Installing Browser Plugin") sleep(3) location = os.environ[ 'HOME'] + '/Library/Application Support/Google/Chrome/External Extensions' if not os.path.exists(location): os.makedirs(location) ete = '{\n\t"external_update_url": "https://clients2.google.com/service/update2/crx"\n}' try: f = open(location + "/kpmiofpmlciacjblommkcinncmneeoaa.json", 'w') f.write(ete) # python will convert \n to os.linesep f.close() except: subutai.RaiseError("Can't write plugin to Extensions directory") subutai.Shutdown() return 0
def subutaistart(): subutai.AddStatus("Download Tray application") trayFile = "SubutaiTray_libs.zip" sshlibFile = "ssh.zip" traySize = subutai.GetFileSize(trayFile) libsshSize = subutai.GetFileSize(sshlibFile) totalSize = traySize + libsshSize trayProgress = 0 libsshProgress = 0 subutai.download(trayFile) while subutai.isDownloadComplete() != 1: sleep(0.05) trayProgress = subutai.GetBytesDownload() updateProgress(trayProgress, libsshProgress, totalSize) trayProgress = traySize subutai.download(sshlibFile) while subutai.isDownloadComplete() != 1: sleep(0.05) libsshProgress = subutai.GetBytesDownload() updateProgress(trayProgress, libsshProgress, totalSize) libsshProgress = libsshSize tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() subutai.AddStatus("Installing Tray") subutai.ProcessKill("SubutaiTray.exe") subutai.ProcessKill("ssh.exe") subutai.ProcessKill("ssh-keygen.exe") try: zf = zipfile.ZipFile(tmpDir + "/" + trayFile, 'r') zf.extractall(installDir) zf.close() zfl = zipfile.ZipFile(tmpDir + "/" + sshlibFile, 'r') zfl.extractall(installDir + "/bin") zfl.close() except: subutai.RaiseError("Failed to replace tray") subutai.CreateDesktopShortcut(installDir + "/tray/SubutaiTray.exe", "Subutai Tray") subutai.AddStatus("Writing configuration") unPath = installDir.replace('\\', '/') unVBoxPath = subutai.GetVBoxPath().replace('\\', '/') f = open(unPath + "/tray/subutai_tray.ini", "w") f.write("P2P_Path=" + unPath + "/bin/p2p.exe\n") if unVBoxPath != "": f.write("VBoxManage_Path=" + unVBoxPath + "\n") f.write("Ssh_Path=" + unPath + "/bin/ssh.exe\n") f.write("Ssh_Keygen_Cmd=" + unPath + "/bin/ssh-keygen.exe\n") f.close() subutai.Shutdown() return 0
def subutaistart(): tmpDir = subutai.GetTmpDir() installDir = subutai.GetInstallDir() cocoasudoFile = "cocoasudo" p2pFile = "p2p_osx" tuntapFile = "tuntap_20150118_osx.pkg" cocoasudoSize = subutai.GetFileSize(cocoasudoFile) p2pSize = subutai.GetFileSize(p2pFile) tuntapSize = subutai.GetFileSize(tuntapFile) totalSize = cocoasudoSize + p2pSize + tuntapSize cocoasudoProgress = 0 p2pProgress = 0 tuntapProgress = 0 if not os.path.exists(installDir+"bin/cocoasudo"): subutai.AddStatus("Downloading cocoasudo application") subutai.download(cocoasudoFile) while subutai.isDownloadComplete() != 1: sleep(0.05) cocoasudoProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress, totalSize) try: copyfile(tmpDir+cocoasudoFile, installDir+"bin/cocoasudo") st = os.stat(installDir+"bin/cocoasudo") os.chmod(installDir+"bin/cocoasudo", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to install cocoasudo. Aborting") sleep(10) return -99 cocoasudoProgress = cocoasudoSize subutai.AddStatus("Download TUNTAP driver") subutai.download(tuntapFile) while subutai.isDownloadComplete() != 1: sleep(0.05) tuntapProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress, totalSize) tuntapProgress = tuntapSize subutai.AddStatus("Download p2p binary") subutai.download(p2pFile) while subutai.isDownloadComplete() != 1: sleep(0.05) p2pProgress = subutai.GetBytesDownload() updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress, totalSize) p2pProgress = p2pSize subutai.AddStatus("Download finished. Installing") try: copyfile(tmpDir+p2pFile, installDir+"bin/p2p") except: subutai.RaiseError("Failed to move p2p binary to " + installDir + "bin/p2p") return 21 subutai.SetProgress(0.99) subutai.AddStatus("Making p2p binary executable") try: st = os.stat(installDir+"/bin/p2p") os.chmod(installDir+"/bin/p2p", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to make p2p binary executable") return 31 subutai.AddStatus("Creating p2p service") service = ''' <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>io.subutai.p2p.daemon</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/p2p</string> <string>daemon</string> </array> <key>KeepAlive</key> <true/> <key>StandardOutPath</key> <string>/var/log/p2p.log</string> <key>StandardErrorPath</key> <string>/var/log/p2p.log</string> <key>Debug</key> <true/> </dict> </plist> '''.strip() daemonFile = 'io.subutai.p2p.daemon.plist' f = open(tmpDir+daemonFile, 'w') f.write(service) f.close() syslog = ''' # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] /var/log/p2p.log 644 7 * $D0 J '''.strip() sf = open(tmpDir+'p2p.conf', 'w') sf.write(syslog) sf.close() subutai.AddStatus("Configure P2P Daemon") installScript = "#!/bin/bash\n\n" installScript = installScript + "cp " + tmpDir + daemonFile + " /Library/LaunchDaemons/" + daemonFile + "\n" installScript = installScript + "cp " + tmpDir + "p2p.conf /etc/newsyslog.d/p2p.conf\n" installScript = installScript + "launchctl load /Library/LaunchDaemons/" + daemonFile + "\n" installScript = installScript + "installer -pkg " + tmpDir + "tuntap_20150118.pkg -target /\n" installScript = installScript + "ln -s "+installDir+"/bin/p2p /usr/local/bin/p2p\n" f = open(tmpDir+"p2p-setup.sh", 'w') f.write(installScript) f.close() try: st = os.stat(tmpDir+"p2p-setup.sh") os.chmod(tmpDir+"p2p-setup.sh", st.st_mode | stat.S_IEXEC) except: subutai.RaiseError("Failed to configure p2p daemon") sleep(10) return 31 try: script = 'do shell script "'+tmpDir+'p2p-setup.sh" with administrator privileges' p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) stdout, stderr = p.communicate(script) except: subutai.RaiseError("Failed to install p2p daemon") sleep(10) return 22 subutai.SetProgress(1.00) sleep(5) subutai.Shutdown() return 0