update blockchain install

This commit is contained in:
Josh Harvey 2017-07-12 15:07:13 +03:00
parent 4affb11ba2
commit 8b7a391b41
3 changed files with 30 additions and 10 deletions

View file

@ -5,7 +5,15 @@ const cp = require('child_process')
const fs = require('fs')
const logger = require('console-log-level')({level: 'info'})
module.exports = {es, writeSupervisorConfig, firewall, randomPass, fetchAndInstall, logger}
module.exports = {
es,
writeSupervisorConfig,
firewall,
randomPass,
fetchAndInstall,
logger,
isInstalledSoftware
}
const BINARIES = {
BTC: {
@ -49,6 +57,8 @@ function es (cmd) {
}
function writeSupervisorConfig (coinRec, cmd) {
if (isInstalledSoftware(coinRec)) return
const blockchain = coinRec.code
const supervisorConfig = `[program:${blockchain}]
@ -63,9 +73,15 @@ environment=HOME="/root"
fs.writeFileSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig)
}
function fetchAndInstall (crypto) {
const binaries = BINARIES[crypto.cryptoCode]
if (!binaries) throw new Error(`No such coin: ${crypto.code}`)
function isInstalledSoftware (coinRec) {
return fs.existsSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`)
}
function fetchAndInstall (coinRec) {
if (isInstalledSoftware(coinRec)) return
const binaries = BINARIES[coinRec.coinRecCode]
if (!binaries) throw new Error(`No such coin: ${coinRec.code}`)
const url = binaries.url
const downloadFile = path.basename(url)