-
Notifications
You must be signed in to change notification settings - Fork 29
/
cygwin.js
100 lines (86 loc) · 3.26 KB
/
cygwin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
let fs = require('fs');
let request = require('request');
let path = require('path');
let ipcRenderer = require('electron').ipcRenderer;
import InstallableItem from './installable-item';
import Downloader from './helpers/downloader';
import Logger from '../services/logger';
import Installer from './helpers/installer';
import VirtualBoxInstall from './virtualbox';
class CygwinInstall extends InstallableItem {
constructor(installerDataSvc, downloadUrl, installFile) {
super('Cygwin', 720, downloadUrl, installFile);
this.installerDataSvc = installerDataSvc;
this.downloadedFileName = 'ssh-rsync.zip';
this.downloadedFile = path.join(this.installerDataSvc.tempDir(), this.downloadedFileName);
this.cygwinPathScript = path.join(this.installerDataSvc.tempDir(), 'set-cygwin-path.ps1');
}
static key() {
return 'cygwin';
}
checkForExistingInstall() {
}
downloadInstaller(progress, success, failure) {
progress.setStatus('Downloading');
var downloads = path.normalize(path.join(__dirname,"../../.."));
if(! fs.existsSync(path.join(downloads, this.downloadedFileName))) {
// Need to download the file
let writeStream = fs.createWriteStream(this.downloadedFile);
let downloader = new Downloader(progress, success, failure);
downloader.setWriteStream(writeStream);
downloader.download(this.downloadUrl);
} else {
this.downloadedFile = path.join(downloads, this.downloadedFileName);
success();
}
}
install(progress, success, failure) {
let vboxInstall = this.installerDataSvc.getInstallable(VirtualBoxInstall.key());
if( vboxInstall !== undefined && vboxInstall.isInstalled() ) {
this.postVirtualboxInstall(progress, success, failure);
} else {
progress.setStatus('Waiting for VirtualBox to finish installation');
ipcRenderer.on('installComplete', (event, arg) => {
if (arg == 'virtualbox') {
this.postVirtualboxInstall(progress, success, failure);
}
});
}
}
postVirtualboxInstall(progress, success, failure) {
progress.setStatus('Installing');
let installer = new Installer(CygwinInstall.key(), progress, success, failure);
let opts = [
'--no-admin',
'--quiet-mode',
'--only-site',
'--site',
'http://mirrors.xmission.com/cygwin',
'--root',
this.installerDataSvc.cygwinDir(),
'--categories',
'Base',
'--packages',
'openssh,rsync'
];
let data = [
'$cygwinPath = "' + path.join(this.installerDataSvc.cygwinDir(), 'bin') + '"',
'$oldPath = [Environment]::GetEnvironmentVariable("path", "User");',
'[Environment]::SetEnvironmentVariable("Path", "$cygwinPath;$oldPath", "User");',
'[Environment]::Exit(0)'
].join('\r\n');
installer.unzip(this.downloadedFile, this.installerDataSvc.cygwinDir())
.then((result) => { return installer.writeFile(this.cygwinPathScript, data, result); })
.then((result) => { return installer.execFile('powershell',
[
'-ExecutionPolicy',
'ByPass',
'-File',
this.cygwinPathScript
], result); })
.then((result) => { return installer.succeed(result); })
.catch((error) => { return installer.fail(error); });
}
}
export default CygwinInstall;