-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcftokens.cfc
66 lines (55 loc) · 2.52 KB
/
cftokens.cfc
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
component {
function init(required any wirebox) {
variables.wirebox = wirebox;
}
function ensureExecutableExists(executablePath, downloadURL) {
if (fileExists(executablePath)) return;
directoryCreate(getDirectoryFromPath(executablePath), true, true);
var job = wirebox.getInstance('InteractiveJob');
job.start('cftokens executable not found. Please wait for a moment while it is downloaded.');
job.addLog('Downloading [#downloadURL#]');
var progressableDownloader = wirebox.getInstance(dsl = 'ProgressableDownloader');
var progressBar = wirebox.getInstance(dsl = 'ProgressBar');
try {
progressableDownloader.download(
downloadURL,
executablePath,
function(status) {
progressBar.update(argumentCollection = status);
}
);
job.complete();
} catch (any var e) {
job.addErrorLog('Unable to download the executable:');
job.addErrorLog('#e.message##chr(10)##e.detail#');
job.addLog('Please manually place the file here:');
job.addLog(executablePath);
// Remove any partial download.
if (fileExists(executablePath)) {
fileDelete(executablePath);
}
job.error(dumplog = true);
}
if (!wirebox.getInstance('filesystem').isWindows()) {
cfexecute(name = "chmod +x ""#executablePath#""", timeout = 10);
}
}
function getExecutable() {
var fs = wirebox.getInstance('filesystem');
if (fs.isWindows()) return 'cftokens.exe';
if (fs.isMac()) return 'cftokens_osx';
if (fs.isLinux()) {
// try to detect whether we are on a system using musl
// note ldd --version outputs to stderr
var p = createObject('java', 'java.lang.ProcessBuilder')
.init(['ldd', '--version'])
.redirectErrorStream(true)
.start();
var inputStreamReader = createObject('java', 'java.io.InputStreamReader').init(p.getInputStream(), 'utf-8');
var bufferedReader = createObject('java', 'java.io.BufferedReader').init(inputStreamReader);
var collector = createObject('java', 'java.util.stream.Collectors').joining(chr(10));
var output = bufferedReader.lines().collect(collector);
return output.findNoCase('musl') ? 'cftokens_linux_musl' : 'cftokens_linux';
}
}
}