diff --git a/README.md b/README.md index aeacd3e..3925f08 100644 --- a/README.md +++ b/README.md @@ -86,12 +86,16 @@ Search filters at the bottom of this screen are self explanatory. It is fairly easy to have *Rdio Scanner* up and running. -Ensure that your operating system is fully updated and that the prerequisites are installed: +Ensure that your operating system is **fully updated** and that the prerequisites are met or installed: +* Minimum of **2 GB** of system memory * [Git v2.23.0 or higher](https://git-scm.com/downloads) -* [Node.js v10.9.0 or higher](https://nodejs.org/en/download/) +* [SQLite v3.30.0 or higher](https://www.sqlite.org/download.html) +* [Node.js v10.9.0 or higher](https://nodejs.org/en/download/) (get it [here](https://github.com/nodesource/distributions) if your distro doesn't have the required package) * [npm v6.2.0 or higher](https://www.npmjs.com/get-npm) +Note that it may be possible to run *Rdio Scanner* on a system with less than 2 Gb of memory. However, the client portion will most probably fail to build when you first start *Rdio Scanner*. Try it at your own risk. + Then clone the *Rdio Scanner* code and run it: ```bash @@ -114,7 +118,11 @@ Creating SQLITE database at /home/radio/rdio-scanner/server/database.sqlite... d Rdio Scanner is running at http://0.0.0.0:3000/ ``` -Note that the first time you start *Rdio Scanner*, it will be longer to do so as it has to install required node modules and build the progressive web app. +Note that the first time you start *Rdio Scanner*, it will be longer to do so as it has to install required node modules and build the progressive web app. If it fails at this point, you can rerun the following command for more information on the reasons for the failure. + +```bash +$ DEBUG=true node run.js +``` A default configuration file `rdio-scanner/server/.env` will be created. A new random API key will be generated where it will have to be use in your upload scripts. diff --git a/run.js b/run.js index 1c87bd7..b3ee1b6 100644 --- a/run.js +++ b/run.js @@ -4,68 +4,75 @@ const childProcess = require('child_process'); const fs = require('fs'); const path = require('path'); -const clientPath = path.resolve(__dirname, 'client'); -const serverPath = path.resolve(__dirname, 'server'); +try { + const stdio = `${!!process.env.DEBUG}` === 'true' ? 'inherit' : 'ignore'; -const missingModules = { - client: !fs.existsSync(path.resolve(clientPath, 'node_modules')), - server: !fs.existsSync(path.resolve(serverPath, 'node_modules')), -} + const clientPath = path.resolve(__dirname, 'client'); + const serverPath = path.resolve(__dirname, 'server'); -if (missingModules.client || missingModules.server) { - process.stdout.write('Installing node modules...'); - - if (missingModules.client) { - childProcess.execSync('npm install', { cwd: clientPath, stdio: ['ignore', 'ignore', 'pipe'] }); + const missingModules = { + client: !fs.existsSync(path.resolve(clientPath, 'node_modules')), + server: !fs.existsSync(path.resolve(serverPath, 'node_modules')), } - if (missingModules.server) { - childProcess.execSync('npm install', { cwd: serverPath, stdio: ['ignore', 'ignore', 'pipe'] }); - } + if (missingModules.client || missingModules.server) { + process.stdout.write('Installing node modules...'); - process.stdout.write(' done\n'); -} + if (missingModules.client) { + childProcess.execSync('npm install', { cwd: clientPath, stdio }); + } -const envFile = path.resolve(serverPath, '.env'); + if (missingModules.server) { + childProcess.execSync('npm install', { cwd: serverPath, stdio }); + } -if (!fs.existsSync(envFile)) { - const apiKey = require(`${serverPath}/node_modules/uuid/v4`)(); - - const data = [ - `DB_DIALECT=sqlite`, - `DB_STORAGE=database.sqlite`, - ``, - `NODE_ENV=production`, - `NODE_HOST=0.0.0.0`, - `NODE_PORT=3000`, - ``, - `RDIO_APIKEYS=["${apiKey}"]`, - `RDIO_PRUNEDAYS=7`, - ``, - ].join('\n'); - - fs.writeFileSync(envFile, data); - - process.stdout.write(`Default configuration created at ${envFile}\n`); - process.stdout.write(`Make sure your upload scripts use this API key: ${apiKey}\n`); -} - -if (!fs.existsSync(path.resolve(clientPath, 'dist/main.html'))) { - process.stdout.write('Building client app...'); - childProcess.execSync('npm run build', { cwd: clientPath, stdio: ['ignore', 'ignore', 'pipe'] }); - process.stdout.write(' done\n'); -} - -require(path.resolve(serverPath, 'node_modules/dotenv')).config({ path: envFile }); - -if (process.env.DB_DIALECT === 'sqlite') { - const dbFile = path.resolve(serverPath, process.env.DB_STORAGE || 'database.sqlite'); - - if (!fs.existsSync(dbFile)) { - process.stdout.write(`Creating SQLITE database at ${dbFile}...`); - childProcess.execSync('npm run migrate', { cwd: serverPath, stdio: ['ignore', 'ignore', 'pipe'] }); process.stdout.write(' done\n'); } -} -childProcess.execSync('node index.js', { cwd: serverPath, stdio: 'inherit' }); + const envFile = path.resolve(serverPath, '.env'); + + if (!fs.existsSync(envFile)) { + const apiKey = require(`${serverPath}/node_modules/uuid/v4`)(); + + const data = [ + `DB_DIALECT=sqlite`, + `DB_STORAGE=database.sqlite`, + ``, + `NODE_ENV=production`, + `NODE_HOST=0.0.0.0`, + `NODE_PORT=3000`, + ``, + `RDIO_APIKEYS=["${apiKey}"]`, + `RDIO_PRUNEDAYS=7`, + ``, + ].join('\n'); + + fs.writeFileSync(envFile, data); + + process.stdout.write(`Default configuration created at ${envFile}\n`); + process.stdout.write(`Make sure your upload scripts use this API key: ${apiKey}\n`); + } + + if (!fs.existsSync(path.resolve(clientPath, 'dist/main.html'))) { + process.stdout.write('Building client app...'); + childProcess.execSync('npm run build', { cwd: clientPath, stdio }); + process.stdout.write(' done\n'); + } + + require(path.resolve(serverPath, 'node_modules/dotenv')).config({ path: envFile }); + + if (process.env.DB_DIALECT === 'sqlite') { + const dbFile = path.resolve(serverPath, process.env.DB_STORAGE || 'database.sqlite'); + + if (!fs.existsSync(dbFile)) { + process.stdout.write(`Creating SQLITE database at ${dbFile}...`); + childProcess.execSync('npm run migrate', { cwd: serverPath, stdio }); + process.stdout.write(' done\n'); + } + } + + childProcess.execSync('node index.js', { cwd: serverPath, stdio: 'inherit' }); + +} catch (error) { + console.error('\n\nAn error has occured. Please re-run the command like this: \'DEBUG=true node run.js\''); +} \ No newline at end of file