add lamassu-coins script

This commit is contained in:
Josh Harvey 2017-07-07 12:57:02 +03:00
parent 44ea450ec5
commit ab58908de0
5 changed files with 254 additions and 34 deletions

View file

@ -1,8 +1,10 @@
const fs = require('fs')
const options = require('../options')
const common = require('./common')
const MOUNT_POINT = '/mnt/blockchains'
const MOUNT_POINT = options.blockchainDir
module.exports = {prepareVolume}
@ -13,7 +15,7 @@ function isMounted () {
}
function isFormatted (volumePath) {
const res = common.es(`file --dereference -s ${volumePath}`)
const res = common.es(`file --dereference -s ${volumePath}`).trim()
return res !== `${volumePath}: data`
}

View file

@ -24,6 +24,8 @@ const PLUGINS = {
ZEC: require('./zcash.js')
}
module.exports = {run}
function installedFilePath (crypto) {
return path.resolve(options.blockchainDir, crypto.code, '.installed')
}
@ -32,32 +34,18 @@ function isInstalled (crypto) {
return fs.existsSync(installedFilePath(crypto))
}
const choices = _.map(c => {
const checked = isInstalled(c)
return {
name: c.display,
value: c.code,
checked,
disabled: checked && 'Installed'
}
}, cryptos)
const questions = []
questions.push({
type: 'checkbox',
name: 'crypto',
message: 'Which cryptocurrencies would you like to install?',
choices
})
function processCryptos (codes) {
if (_.isEmpty(codes)) {
logger.info('No cryptos selected. Exiting.')
process.exit(0)
}
doVolume.prepareVolume()
const goodVolume = doVolume.prepareVolume()
if (!goodVolume) {
logger.error('There was an error preparing the disk volume. Exiting.')
process.exit(1)
}
logger.info('Thanks! Installing: %s. Will take a while...', _.join(', ', codes))
@ -67,15 +55,6 @@ function processCryptos (codes) {
logger.info('Installation complete.')
}
inquirer.prompt(questions)
.then(answers => processCryptos(answers.crypto))
function plugin (crypto) {
const plugin = PLUGINS[crypto.cryptoCode]
if (!plugin) throw new Error(`No such plugin: ${crypto.cryptoCode}`)
return plugin
}
function setupCrypto (crypto) {
logger.info(`Installing ${crypto.display}...`)
const cryptoDir = path.resolve(options.blockchainDir, crypto.code)
@ -93,3 +72,33 @@ function setupCrypto (crypto) {
process.chdir(oldDir)
}
function plugin (crypto) {
const plugin = PLUGINS[crypto.cryptoCode]
if (!plugin) throw new Error(`No such plugin: ${crypto.cryptoCode}`)
return plugin
}
function run () {
const choices = _.map(c => {
const checked = isInstalled(c)
return {
name: c.display,
value: c.code,
checked,
disabled: checked && 'Installed'
}
}, cryptos)
const questions = []
questions.push({
type: 'checkbox',
name: 'crypto',
message: 'Which cryptocurrencies would you like to install?',
choices
})
inquirer.prompt(questions)
.then(answers => processCryptos(answers.crypto))
}