@ossmo/client
Advanced tools
Comparing version 1.0.5 to 1.0.7
@@ -15,3 +15,7 @@ 'use strict'; | ||
const pathToConf = path.join(pathToConfDir,'conf.json'); | ||
const util = require('util'); | ||
const writeFile = util.promisify(fs.writeFile); | ||
let config = {}; | ||
//TODO: check whether the user's system is one which is supported by the miner | ||
@@ -21,3 +25,2 @@ | ||
let configIsInitialized = false; | ||
let config = null; | ||
@@ -38,49 +41,129 @@ //check for configuration file and try to load existing config | ||
//do the prompts | ||
if(!configIsInitialized){ | ||
const prompt0 = new Confirm({message: prompts[0](packageName), initial: true}); | ||
const prompt0Response = await prompt0.run() | ||
if(prompt0Response){ | ||
console.log('\n'); | ||
const prompt1 = new Confirm({message: prompts[1], initial: true}); | ||
const prompt1Response = await prompt1.run() | ||
if(prompt1Response){ | ||
console.log('\n'); | ||
//TODO: check if he is already installed | ||
//TODO: hash the file to verify his integrity | ||
//TODO: check that the executable bit is set | ||
//install in ~/.ossmo | ||
await install(pathToConfDir) | ||
await prompt1(packageName); | ||
} | ||
//if installation succeeds | ||
const prompt2 = new Confirm({message: prompts[2]}); | ||
const mineAnonymously = await prompt2.run(); | ||
async function prompt1(packageName){ | ||
if(typeof config.wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency === 'undefined'){ | ||
await doPrompt1(packageName); | ||
}else{ | ||
if(config.wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency){ | ||
await prompt2(packageName); | ||
} else if(config.canWePromptYouAboutThisAgainInTheFuture){ | ||
delete config.canWePromptYouAboutThisAgainInTheFuture; //reset the prompt flag | ||
await doPrompt1(packageName); | ||
} else{ | ||
//do nothing we are done | ||
} | ||
} | ||
} | ||
let npmUsername = null; | ||
if(!mineAnonymously){ | ||
const {stdout, status, stderr} = childProcess.spawnSync('npm',['whoami']); | ||
if(status === 0){ | ||
npmUsername = stdout.toString().slice(0, -1); | ||
} | ||
} | ||
async function doPrompt1(packageName){ | ||
config.wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency = | ||
await (new Confirm({message: prompts.wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency(packageName), initial: true})).run(); | ||
console.log('\n'); | ||
await saveConfig(); | ||
console.log(prompts[3]); //dump the last prompt | ||
if(config.wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency){ | ||
await prompt2(packageName); | ||
}else { | ||
await handleWhenUserSaysNo(); | ||
} | ||
} | ||
//start the miner | ||
const miner = new Miner(pathToConfDir); | ||
const safePackageName = npmPkgNameToProhashingGroupName(packageName); //TODO: might be better to move this into my-multi-miner | ||
//TODO: capture his logs and dump them to ~/.ossmo/logs | ||
//TODO: make sure the process is actually run in ~/.ossmo | ||
//TODO: make sure the config files that get created are in ~/.ossmo | ||
//TODO: run at high nice level | ||
miner.launch({pkgName: safePackageName, npmUsername}); | ||
}else{ | ||
//TODO: decide what should happen if they say no | ||
} | ||
} else { | ||
//TODO: decide what should happen if they say no | ||
//OK. You can disable this prompt by running with environment variable DISABLE_OSSMO_PROMPT | ||
async function prompt2(packageName){ | ||
if(typeof config.isItOKToDownloadThisSoftwareNow === 'undefined'){ | ||
await doPrompt2(packageName); | ||
}else{ | ||
if(config.isItOKToDownloadThisSoftwareNow ){ | ||
const success = await installTheMiner(); | ||
//TODO: check if installation succeeds | ||
await prompt3(packageName); | ||
} else if(config.canWePromptYouAboutThisAgainInTheFuture){ | ||
delete config.canWePromptYouAboutThisAgainInTheFuture; //reset the prompt flag | ||
await doPrompt2(packageName); | ||
} else{ | ||
await handleWhenUserSaysNo(); | ||
} | ||
} | ||
} | ||
async function doPrompt2(packageName){ | ||
config.isItOKToDownloadThisSoftwareNow = await (new Confirm({message: prompts.isItOKToDownloadThisSoftwareNow, initial: true})).run(); | ||
console.log('\n'); | ||
await saveConfig(); | ||
if(config.isItOKToDownloadThisSoftwareNow){ | ||
const success = await installTheMiner(); | ||
//TODO: check if installation succeeds | ||
await prompt3(packageName); | ||
}else{ | ||
await handleWhenUserSaysNo(); | ||
} | ||
} | ||
async function prompt3(packageName){ | ||
if(typeof config.wouldYouLikeToMineAnonymously === 'undefined'){ | ||
config.wouldYouLikeToMineAnonymously = await (new Confirm({message: prompts.wouldYouLikeToMineAnonymously})).run(); | ||
console.log('\n'); | ||
await saveConfig(); | ||
console.log(prompts.thanks); | ||
} | ||
const npmUsername = getNpmUsername(config.wouldYouLikeToMineAnonymously); | ||
startTheMiner(packageName, npmUsername); | ||
} | ||
async function handleWhenUserSaysNo(){ | ||
if(typeof config.canWePromptYouAboutThisAgainInTheFuture === 'undefined'){ | ||
config.canWePromptYouAboutThisAgainInTheFuture = await (new Confirm({message: prompts.canWePromptYouAboutThisAgainInTheFuture, initial: true})).run(); | ||
console.log('\n'); | ||
await saveConfig(); | ||
if(!config.canWePromptYouAboutThisAgainInTheFuture){ | ||
console.log(prompts.okNoPrompt); | ||
} | ||
} else { | ||
//TODO: use the loaded config and start the miner | ||
// done. silentely do nothing | ||
return null; | ||
} | ||
} | ||
async function installTheMiner(){ | ||
//TODO: check if he is already installed | ||
//TODO: hash the file to verify his integrity | ||
//TODO: check that the executable bit is set | ||
//install in ~/.ossmo | ||
await install(pathToConfDir); | ||
} | ||
function getNpmUsername(mineAnonymously){ | ||
//TODO: make this an async function | ||
let npmUsername = null; | ||
if(!mineAnonymously){ | ||
const {stdout, status, stderr} = childProcess.spawnSync('npm',['whoami']); | ||
if(status === 0){ | ||
npmUsername = stdout.toString().slice(0, -1); | ||
} | ||
} | ||
return npmUsername; | ||
} | ||
function startTheMiner(packageName, npmUsername){ | ||
//start the miner | ||
const miner = new Miner(pathToConfDir); | ||
const safePackageName = npmPkgNameToProhashingGroupName(packageName); //TODO: might be better to move this into my-multi-miner | ||
miner.launch({ | ||
pkgName: safePackageName, | ||
npmUsername, | ||
minerUrl: 'stratum+tcp://prohashing.com:3341', | ||
minerUsername: 'jbeard4', | ||
cwd: pathToConfDir, | ||
niceness: 19 | ||
}); | ||
} | ||
function saveConfig(){ | ||
//write config to a file | ||
return writeFile(pathToConf, JSON.stringify(config, 4,4)) ; | ||
} |
{ | ||
"name": "@ossmo/client", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "Mine cryptocurrency to support open source sorftware projects.", | ||
@@ -21,6 +21,6 @@ "author": { | ||
"dependencies": { | ||
"@ossmo/my-multi-miner": "^1.0.5", | ||
"@ossmo/my-multi-miner": "^1.0.7", | ||
"enquirer": "^2.3.0" | ||
}, | ||
"gitHead": "a5d763b18585ee2162873937c50e348aad69bbcf" | ||
"gitHead": "6fdcde5da5f36c39e9f7707dc37cb0a2ec983bcd" | ||
} |
@@ -1,29 +0,38 @@ | ||
module.exports = [ | ||
(packageName) => (` | ||
Hi, it looks like this is the first time you are running ${packageName}. | ||
${packageName} is supported by the community of its users. | ||
module.exports = { | ||
wouldYouLikeToHelpSupportThisProjectByMiningForCryptocurrency : | ||
(packageName) => (` | ||
Hi, it looks like this is the first time you are running ${packageName}. | ||
${packageName} is supported by the community of its users. | ||
You can help sustain this project by mining for cryptocurrency on your | ||
computer. The mining process runs in the background with low priority so as to not | ||
disrupt other proceses, and 100% of the cryptocurrency mined goes toward the | ||
project authors (minus network fees). | ||
You can help sustain this project by mining for cryptocurrency on your | ||
computer. The mining process runs in the background with low priority so as to not | ||
disrupt other proceses, and 100% of the cryptocurrency mined goes toward the | ||
project authors (minus network fees). | ||
Would you like to help support this project by mining for cryptocurrency?`), | ||
Would you like to help support this project by mining for cryptocurrency?`), | ||
`Great! We will now download the mining binaries onto your system. Note that | ||
some antivirus software may flag these binaries as malware, but it is *not* | ||
malware. | ||
isItOKToDownloadThisSoftwareNow : | ||
`Great! We will now download the mining binaries onto your system. Note that | ||
some antivirus software may flag these binaries as malware, but it is *not* | ||
malware. | ||
Is it OK to download this software now?`, | ||
Is it OK to download this software now?`, | ||
`OK, one last thing. You can choose to mine anonymously, or you can | ||
report your npm username to the mining server, so that you and other people can | ||
see how much hashing power you have contributed. | ||
wouldYouLikeToMineAnonymously : | ||
`OK, one last thing. You can choose to mine anonymously, or you can | ||
report your npm username to the mining server, so that you and other people can | ||
see how much hashing power you have contributed. | ||
Would you like to mine anonymously?`, | ||
Would you like to mine anonymously?`, | ||
`Thanks! You are now set up. You can change your configuration at any time by | ||
editing ~/.ossmo/config.json. Logfiles will be stored in ~/.ossmo/logs | ||
thanks: | ||
`Thanks! You are now set up. You can change your configuration at any time by | ||
editing ~/.ossmo/config.json. Logfiles will be stored in ~/.ossmo/logs | ||
Happy hashing!` | ||
]; | ||
Happy hashing!`, | ||
canWePromptYouAboutThisAgainInTheFuture : | ||
'OK! Can we prompt you about this again in the future?', | ||
okNoPrompt : 'OK, we won\'t prompt you again.', | ||
}; |
216
20780
6
Updated@ossmo/my-multi-miner@^1.0.7