Skip to content

Commit

Permalink
use another linux os info package
Browse files Browse the repository at this point in the history
finalized the linux download of the correct daemon executable
  • Loading branch information
taeguscromis committed Apr 16, 2019
1 parent 8c17ba1 commit 6562125
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 52 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"conceal-api": "^0.7.5",
"download-github-release": "^0.3.2",
"extract-zip": "^1.6.7",
"getos": "^3.1.1",
"inquirer": "^6.2.2",
"iplocation": "^6.1.0",
"linux-os-info": "^2.0.0",
"moment": "^2.24.0",
"nodemailer": "^6.1.0",
"object-path": "^0.11.4",
Expand All @@ -49,4 +49,4 @@
"expr": true,
"esversion": 8
}
}
}
118 changes: 68 additions & 50 deletions units/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
const downloadRelease = require('download-github-release');
const extractZIP = require('extract-zip');
const extractTAR = require('tar');
const vsprintf = require("sprintf-js").vsprintf;
const osInfo = require('linux-os-info');
const tempDir = require('temp-dir');
const utils = require("./utils.js");
const shell = require("shelljs");
const getos = require('getos');
const path = require("path");
const fs = require("fs");

Expand Down Expand Up @@ -50,71 +51,89 @@ function extractArchive(filePath, outDir, callback) {
module.exports = {
downloadLatestDaemon: function (nodePath, callback) {
var finalTempDir = path.join(tempDir, utils.ensureNodeUniqueId());
var linuxOSInfo = null;

shell.rm('-rf', finalTempDir);
shell.mkdir('-p', finalTempDir);

getos(function (error, system) {
if (error) {
callback(error);
// only for linux try to get it
if (process.platform === "linux") {
linuxOSInfo = osInfo({ mode: 'sync' });
}

if (linuxOSInfo) {
// if we are running on linux, print the version and flavor
console.log(vsprintf("Running on %s", [linuxOSInfo.pretty_name]));
}

if (process.platform == "linux") {
if (linuxOSInfo.id == "ubuntu") {
if ((linuxOSInfo.version_id !== "16.04") && (linuxOSInfo.version_id !== "18.04")) {
callback(wrongLinuxOSMsg);
return false;
}
} else {
if (system.os == "linux") {
if (system.dist == "Ubuntu Linux") {
if ((system.release !== "16.04") && (system.release !== "18.04")) {
callback(wrongLinuxOSMsg);
return false;
}
} else {
callback(wrongLinuxOSMsg);
return false;
}
} else if (system.os == "darwin") {
callback(wrongOSMsg);
callback(wrongLinuxOSMsg);
return false;
}
} else if (process.platform == "darwin") {
callback(wrongOSMsg);
return false;
}

// Define a function to filter assets.
var filterAssetNode = function (asset) {
if (process.platform === "win32") {
return asset.name.indexOf('win64') >= 0;
} else if (process.platform === "linux") {
if ((linuxOSInfo.id == "ubuntu") && (linuxOSInfo.version_id == "16.04")) {
return asset.name.indexOf('ubuntu-1604') >= 0;
} else if ((linuxOSInfo.id == "ubuntu") && (linuxOSInfo.version_id == "18.04")) {
return asset.name.indexOf('ubuntu-1804') >= 0;
} else {
return false;
}
} else if (process.platform === "darwin") {
return false;
} else {
return false;
}
};

// Define a function to filter assets.
var filterAssetNode = function (asset) {
if (process.platform === "win32") {
return asset.name.indexOf('win64') >= 0;
} else if (process.platform === "linux") {
if ((system.dist == "Ubuntu Linux") && (system.release == "16.04")) {
return asset.name.indexOf('ubuntu-1604') >= 0;
} else if ((system.dist == "Ubuntu Linux") && (system.release == "18.04")) {
return asset.name.indexOf('ubuntu-1804') >= 0;
} else {
return false;
}
} else if (process.platform === "darwin") {
return false;
} else {
return false;
}
};
downloadRelease('ConcealNetwork', 'conceal-core', finalTempDir, filterRelease, filterAssetNode, true)
.then(function () {
fs.readdir(finalTempDir, function (err, items) {
if (items.length > 0) {
extractArchive(path.join(finalTempDir, items[0]), finalTempDir, function (success) {
if (success) {
shell.rm('-rf', path.join(finalTempDir, items[0]));

downloadRelease('ConcealNetwork', 'conceal-core', finalTempDir, filterRelease, filterAssetNode, true)
.then(function () {
fs.readdir(finalTempDir, function (err, items) {
if (items.length > 0) {
extractArchive(path.join(finalTempDir, items[0]), finalTempDir, function (success) {
if (success) {
shell.cp(path.join(finalTempDir, utils.getNodeExecutableName()), path.dirname(nodePath));
fs.readdir(finalTempDir, function (err, items) {
if (items.length > 0) {
if (process.platform === "win32") {
shell.cp(path.join(finalTempDir, utils.getNodeExecutableName()), path.dirname(nodePath));
} else {
shell.cp(path.join(finalTempDir, items[0], utils.getNodeExecutableName()), path.dirname(nodePath));
}
shell.rm('-rf', finalTempDir);
shell.chmod('+x', nodePath);
callback(null);
} else {
callback("Failed to extract the archive");
callback("No downloaded archives found");
}
});
} else {
callback("No downloaded archives found");
callback("Failed to extract the archive");
}
});
})
.catch(function (err) {
callback(err.message);
});
}
});
} else {
callback("No downloaded archives found");
}
});
})
.catch(function (err) {
callback(err.message);
});
},
downloadLatestGuardian: function (nodePath, callback) {
var finalTempDir = path.join(tempDir, utils.ensureNodeUniqueId());
Expand Down Expand Up @@ -146,7 +165,6 @@ module.exports = {

shell.mv(path.join(process.cwd(), utils.getGuardianExecutableName()), path.join(process.cwd(), backupName));
shell.cp(path.join(finalTempDir, executableName), process.cwd());
shell.rm('-rf', finalTempDir);
shell.chmod('+x', nodePath);
callback(null);
} else {
Expand Down

0 comments on commit 6562125

Please sign in to comment.