mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-06-02 23:42:30 +02:00
Removed redundant code
This commit is contained in:
parent
24204f2ec3
commit
c5ff3622ea
112
src/init.js
112
src/init.js
@ -30,23 +30,22 @@ const initEnvFile = async () => {
|
|||||||
const runMigrations = async () => {
|
const runMigrations = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('Run migrations');
|
console.log('Run migrations');
|
||||||
const resp = await knex.migrate.latest();
|
await knex.migrate.latest();
|
||||||
await createCkpoolConfigFile();
|
|
||||||
await createBitcoinConfigFile();
|
|
||||||
await runGenerateBitcoinPassword();
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const runGenerateBitcoinPassword = async () => {
|
|
||||||
try {
|
|
||||||
console.log('Checking bitcoin password existence');
|
|
||||||
const [settings] = await knex('settings')
|
const [settings] = await knex('settings')
|
||||||
.select(['node_rpc_password as nodeRpcPassword'])
|
.select(['node_rpc_password as nodeRpcPassword'])
|
||||||
.orderBy('created_at', 'desc')
|
.orderBy('created_at', 'desc')
|
||||||
.orderBy('id', 'desc')
|
.orderBy('id', 'desc')
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
await utils.auth.manageBitcoinConf(settings);
|
||||||
|
await runGenerateBitcoinPassword(settings);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const runGenerateBitcoinPassword = async (settings) => {
|
||||||
|
try {
|
||||||
|
console.log('Checking bitcoin password existence');
|
||||||
|
|
||||||
if (settings && settings.nodeRpcPassword)
|
if (settings && settings.nodeRpcPassword)
|
||||||
return console.log('Bitcoin password found');
|
return console.log('Bitcoin password found');
|
||||||
@ -56,95 +55,6 @@ const runGenerateBitcoinPassword = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createCkpoolConfigFile = async () => {
|
|
||||||
const configFilePath = path.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../backend/ckpool/ckpool.conf'
|
|
||||||
);
|
|
||||||
const configContent = `{
|
|
||||||
"btcd": [
|
|
||||||
{
|
|
||||||
"url": "127.0.0.1:8332",
|
|
||||||
"auth": "futurebit",
|
|
||||||
"pass": "",
|
|
||||||
"notify": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"logdir": "/opt/apolloapi/backend/ckpool/logs"
|
|
||||||
}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if the file exists
|
|
||||||
await fs.access(configFilePath);
|
|
||||||
console.log('File ckpool.conf already exists.');
|
|
||||||
} catch (error) {
|
|
||||||
try {
|
|
||||||
// Create the file
|
|
||||||
await fs.writeFile(configFilePath, configContent, 'utf-8');
|
|
||||||
console.log('File ckpool.conf created.');
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`Error during the creation of the file ckpool.conf: ${error.message}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
const [settings] = await knex('settings')
|
|
||||||
.select(['node_rpc_password as nodeRpcPassword'])
|
|
||||||
.orderBy('created_at', 'desc')
|
|
||||||
.orderBy('id', 'desc')
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (settings && settings.nodeRpcPassword) {
|
|
||||||
exec(
|
|
||||||
`sudo sed -i 's#"pass":.*#"pass": "${settings.nodeRpcPassword}",#g' ${configFilePath}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const createBitcoinConfigFile = async () => {
|
|
||||||
const configFilePath = path.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../backend/node/bitcoin.conf'
|
|
||||||
);
|
|
||||||
const configContent = `server=1
|
|
||||||
rpcuser=futurebit
|
|
||||||
rpcpassword=
|
|
||||||
daemon=0
|
|
||||||
maxconnections=32
|
|
||||||
upnp=1
|
|
||||||
uacomment=FutureBit-Apollo-Node`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if the file exists
|
|
||||||
await fs.access(configFilePath);
|
|
||||||
console.log('File bitcoin.conf already exists.');
|
|
||||||
} catch (error) {
|
|
||||||
try {
|
|
||||||
// Create the file
|
|
||||||
await fs.writeFile(configFilePath, configContent, 'utf-8');
|
|
||||||
console.log('File bitcoin.conf created.');
|
|
||||||
await utils.auth.changeNodeRpcPassword();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`Error during the creation of the file bitcoin.conf: ${error.message}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
const [settings] = await knex('settings')
|
|
||||||
.select(['node_rpc_password as nodeRpcPassword'])
|
|
||||||
.orderBy('created_at', 'desc')
|
|
||||||
.orderBy('id', 'desc')
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (settings && settings.nodeRpcPassword) {
|
|
||||||
exec(
|
|
||||||
`sudo sed -i 's/rpcpassword.*/rpcpassword=${settings.nodeRpcPassword}/g' ${configFilePath}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
initEnvFile();
|
initEnvFile();
|
||||||
runMigrations().then(startServer);
|
runMigrations().then(startServer);
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ module.exports = ({ define }) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
utils.auth.changeSystemPassword(password)
|
utils.auth.changeSystemPassword(password)
|
||||||
await utils.auth.changeNodeRpcPassword()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('ERROR', err);
|
console.log('ERROR', err);
|
||||||
}
|
}
|
||||||
|
13
src/utils.js
13
src/utils.js
@ -55,11 +55,11 @@ module.exports.auth = {
|
|||||||
await fsPromises.access(configCkpoolFilePath);
|
await fsPromises.access(configCkpoolFilePath);
|
||||||
|
|
||||||
exec(
|
exec(
|
||||||
`sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g ${configBitcoinFilePath}`
|
`sudo sed -i 's/rpcpassword.*/rpcpassword=${password}/g' ${configBitcoinFilePath}`
|
||||||
);
|
);
|
||||||
|
|
||||||
exec(
|
exec(
|
||||||
`sudo sed -i 's#"pass": ""#"pass": "${password}"#g' ${configCkpoolFilePath}`
|
`sudo sed -i 's#"pass":.*#"pass": "${password}",#g' ${configCkpoolFilePath}`
|
||||||
);
|
);
|
||||||
|
|
||||||
exec('sudo systemctl restart node');
|
exec('sudo systemctl restart node');
|
||||||
@ -109,11 +109,11 @@ module.exports.auth = {
|
|||||||
const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`;
|
const defaultConf = `server=1\nrpcuser=futurebit\nrpcpassword=${settings.nodeRpcPassword}\ndaemon=0\nmaxconnections=32\nupnp=1\nuacomment=FutureBit-Apollo-Node`;
|
||||||
let conf = defaultConf;
|
let conf = defaultConf;
|
||||||
|
|
||||||
|
this.manageCkpoolConf(settings);
|
||||||
|
|
||||||
if (settings.nodeEnableSoloMining) {
|
if (settings.nodeEnableSoloMining) {
|
||||||
conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`;
|
conf += `\n#SOLO_START\nzmqpubhashblock=tcp://127.0.0.1:28332\n#SOLO_END`;
|
||||||
|
|
||||||
this.manageCkpoolConf(settings);
|
|
||||||
|
|
||||||
exec(
|
exec(
|
||||||
`sudo cp ${configCkpoolServiceFilePath} /etc/systemd/system/ckpool.service`
|
`sudo cp ${configCkpoolServiceFilePath} /etc/systemd/system/ckpool.service`
|
||||||
);
|
);
|
||||||
@ -139,8 +139,9 @@ module.exports.auth = {
|
|||||||
|
|
||||||
console.log('Writing Bitcoin conf file', conf);
|
console.log('Writing Bitcoin conf file', conf);
|
||||||
|
|
||||||
exec(
|
await fsPromises.writeFile(
|
||||||
`echo "${conf}" | sudo tee ${configBitcoinFilePath}`
|
configBitcoinFilePath,
|
||||||
|
conf
|
||||||
);
|
);
|
||||||
|
|
||||||
exec('sudo systemctl restart node');
|
exec('sudo systemctl restart node');
|
||||||
|
Loading…
Reference in New Issue
Block a user