Revert "check if daemon is already installed before installing again"

This commit is contained in:
Sean Yesmunt 2018-07-21 05:22:28 -04:00 committed by GitHub
parent 2d7cf51630
commit 814162f1e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 67 deletions

3
.gitignore vendored
View file

@ -1,8 +1,7 @@
/node_modules /node_modules
/dist /dist
/static/daemon/lbrynet-daemon* /static/daemon/lbrynet*
/static/locales /static/locales
yarn-error.log yarn-error.log
package-lock.json package-lock.json
.idea/ .idea/
/build/daemon.ver

View file

@ -1,6 +1,6 @@
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */ /* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs-path');
const packageJSON = require('../package.json'); const packageJSON = require('../package.json');
const axios = require('axios'); const axios = require('axios');
const decompress = require('decompress'); const decompress = require('decompress');
@ -11,80 +11,56 @@ const downloadDaemon = targetPlatform =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate; const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion; const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
const daemonDir = path.join(__dirname,'..',packageJSON.lbrySettings.lbrynetDaemonDir); const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir;
let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName; const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
let currentPlatform = os.platform(); let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macos'; if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') { if (currentPlatform === 'win32') currentPlatform = 'windows';
currentPlatform = 'windows';
daemonFileName = daemonFileName + '.exe';
}
const daemonFilePath = path.join(daemonDir, daemonFileName);
const daemonVersionPath = path.join(__dirname, 'daemon.ver');
const daemonPlatform = targetPlatform || currentPlatform; const daemonPlatform = targetPlatform || currentPlatform;
const tmpZipPath = path.join(__dirname, '../','dist','daemon.zip');
const daemonURL = daemonURLTemplate const daemonURL = daemonURLTemplate
.replace(/DAEMONVER/g, daemonVersion) .replace(/DAEMONVER/g, daemonVersion)
.replace(/OSNAME/g, daemonPlatform); .replace(/OSNAME/g, daemonPlatform);
const tmpZipPath = 'dist/daemon.zip';
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version axios
const hasDaemonDownloaded = fs.existsSync(daemonFilePath); .request({
const hasDaemonVersion = fs.existsSync(daemonVersionPath); responseType: 'arraybuffer',
let downloadedDaemonVersion; url: daemonURL,
if (hasDaemonVersion) { method: 'get',
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8"); headers: {
} 'Content-Type': 'application/zip',
},
if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) { })
console.log('\x1b[34minfo\x1b[0m Daemon already downloaded'); .then(
resolve('Done'); result =>
return; new Promise((newResolve, newReject) => {
} else { fs.writeFile(tmpZipPath, result.data, error => {
console.log('\x1b[34minfo\x1b[0m Downloading daemon...'); if (error) return newReject(error);
axios return newResolve();
.request({ });
responseType: 'arraybuffer', })
url: daemonURL, )
method: 'get', .then(() => del(`${daemonDir}/${daemonFileName}*`))
headers: { .then(() =>
'Content-Type': 'application/zip', decompress(tmpZipPath, daemonDir, {
},
})
.then(
result =>
new Promise((newResolve, newReject) => {
fs.writeFile(tmpZipPath, result.data, error => {
if (error) return newReject(error);
return newResolve();
});
})
)
.then(() => del(`${daemonFilePath}*`))
.then(() => decompress(tmpZipPath, daemonDir, {
filter: file => filter: file =>
path.basename(file.path) === daemonFileName, path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
}))
.then(() => del(`${tmpZipPath }*`))
.then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
if (hasDaemonVersion) {
del(daemonVersionPath);
}
fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8")
resolve('Done');
}) })
.catch(error => { )
console.error( .then(() => {
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m` console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
); resolve(true);
reject(error); })
}); .catch(error => {
} console.error(
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
);
reject(error);
});
}); });
module.exports = downloadDaemon; module.exports = downloadDaemon;