-
Notifications
You must be signed in to change notification settings - Fork 29
/
cdk.js
131 lines (114 loc) · 4.34 KB
/
cdk.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict';
import path from 'path';
import Logger from '../services/logger';
import InstallableItem from './installable-item';
import Platform from '../services/platform';
import Installer from './helpers/installer';
import globby from 'globby';
import fs from 'fs-extra';
import pify from 'pify';
class CDKInstall extends InstallableItem {
constructor(installerDataSvc, targetFolderName, downloadUrl, fileName, sha256sum) {
super(CDKInstall.KEY, downloadUrl, fileName, targetFolderName, installerDataSvc, true);
this.sha256 = sha256sum;
this.addOption('install', this.version, '', true);
}
static get KEY() {
return 'cdk';
}
get minishiftExeLocation() {
return path.join(this.installerDataSvc.ocDir(), Platform.OS === 'win32' ? 'minishift.exe' : 'minishift');
}
installAfterRequirements(progress, success, failure) {
progress.setStatus('Installing');
let minishiftExe = this.minishiftExeLocation;
let installer = new Installer(this.keyName, progress, success, failure);
let ocExe;
let ocExePattern = Platform.OS === 'win32' ? '/**/oc.exe' : '/**/oc';
let home;
let driverName = 'virtualbox';
return Promise.resolve().then(()=> {
if(this.downloadedFile.endsWith('.exe') || path.parse(this.downloadedFile).ext == '') {
return installer.copyFile(this.downloadedFile, minishiftExe);
}
return Promise.reject('Cannot process downloaded cdk distribution');
}).then(()=> {
return Platform.makeFileExecutable(minishiftExe);
}).then(()=> {
let hv = this.installerDataSvc.getInstallable('hyperv');
if (hv && hv.hasOption('detected')) {
driverName = 'hyperv';
return installer.exec(
'net localgroup "Hyper-V Administrators" %USERDOMAIN%\\%USERNAME% /add'
).catch(()=>Promise.resolve());
}
return Promise.resolve();
}).then(()=> {
return installer.exec(
`${minishiftExe} stop`
).catch(()=>Promise.resolve());
}).then(()=> {
return installer.exec(`${minishiftExe} setup-cdk --force --default-vm-driver=${driverName}`, this.createEnvironment());
}).then(()=> {
return Platform.getUserHomePath();
}).then((result)=> {
home = Platform.ENV.MINISHIFT_HOME ? Platform.ENV.MINISHIFT_HOME : path.join(result, '.minishift');
return globby(ocExePattern, {root: path.join(home, 'cache', 'oc')});
}).then((files)=> {
ocExe = files[0].replace(/\//g, path.sep);
return Promise.resolve();
}).then(()=> {
return Platform.makeFileExecutable(ocExe);
}).then(()=> {
return Platform.addToUserPath([ocExe, minishiftExe]);
}).then(()=> {
return pify(fs.appendFile)(
path.join(home, 'cdk'),
`rhel.subscription.username=${this.installerDataSvc.username}`);
}).then(()=> {
installer.succeed(true);
}).catch((error)=> {
installer.fail(error);
});
}
createEnvironment() {
let vboxInstall = this.installerDataSvc.getInstallable('virtualbox');
let cygwinInstall = this.installerDataSvc.getInstallable('cygwin');
let env = Object.assign({}, Platform.ENV);
let newPath = [];
let oldPath = Platform.ENV[Platform.PATH];
if(vboxInstall) {
newPath.push(vboxInstall.getLocation());
}
if(cygwinInstall) {
newPath.push(cygwinInstall.getLocation());
}
if(oldPath.trim()) {
newPath.push(oldPath);
}
env[Platform.PATH] = newPath.join(path.delimiter);
Logger.info(this.keyName + ' - Set PATH environment variable to \'' + env[Platform.PATH] + '\'');
return env;
}
isConfigurationValid() {
let cygwin = this.installerDataSvc.getInstallable('cygwin');
return this.isConfigured()
&& this.virtualizationIsConfigured()
&& (!cygwin || cygwin.isConfigured())
|| this.isSkipped();
}
virtualizationIsConfigured() {
let virtualbox = this.installerDataSvc.getInstallable('virtualbox');
let hyperv = this.installerDataSvc.getInstallable('hyperv');
return (virtualbox
&& virtualbox.isConfigured())
|| (hyperv
&& hyperv.isConfigured()
|| this.selectedOption !== 'install');
}
}
function fromJson({installerDataSvc, targetFolderName, downloadUrl, fileName, sha256sum}) {
return new CDKInstall(installerDataSvc, targetFolderName, downloadUrl, fileName, sha256sum);
}
CDKInstall.convertor = {fromJson};
export default CDKInstall;