move auto update to bash script

This commit is contained in:
Todd Treece 2016-06-08 08:17:17 -04:00
parent c9ec1e1c6a
commit a28bf3233c
5 changed files with 62 additions and 63 deletions

29
cli Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env bash
cat logo.txt
_LATEST=$(npm view npr-one version)
_CURRENT=$(node version.js)
_TEMPLATE='pm2.service'
_SERVICE='/etc/systemd/system/pm2.service'
_RELEASE='/etc/os-release'
if [ -f $_RELEASE ]; then
source $_RELEASE
if [ ID == 'rasbian' ] && [ ! -f $_SERVICE ]; then
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
sudo cp $_TEMPLATE $_SERVICE
sudo systemctl enable $_SERVICE
sudo systemctl start $_SERVICE
fi
fi
if [ $_CURRENT != $_LATEST ]; then
echo "updating..."
npm install -g npr-one &> /dev/null
fi
node index.js

View file

@ -1,4 +1,3 @@
#!/usr/bin/env node
'use strict';
process.title = 'npr-one';
@ -8,9 +7,7 @@ if(process.platform != 'linux' && process.platform != 'darwin') {
process.exit(1);
}
const AutoUpdate = require('cli-autoupdate'),
exec = require('child_process').exec,
NPR = require('npr-api'),
const NPR = require('npr-api'),
chalk = require('chalk'),
auth = require('./lib/auth'),
fs = require('fs'),
@ -19,33 +16,18 @@ const AutoUpdate = require('cli-autoupdate'),
Story = require('./lib/story'),
UI = require('./lib/ui');
let pkg = require('./package.json');
const logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8');
console.log(logo);
console.log('checking for update...');
if(process.platform == 'linux' && process.arch == 'arm')
exec('./install-service');
const update = new AutoUpdate(pkg);
update.on('error', (err) => { console.error('update failed.'); launch(); });
update.on('update', () => console.log('updating...'));
update.on('finish', () => launch());
const launch = function() {
const npr = new NPR(),
const npr = new NPR(),
story = new Story(npr),
player = new Player();
console.log('connecting to npr one...');
console.log('connecting to npr one...');
// silence swagger log output
process.env.NODE_ENV = 'test';
// silence swagger log output
process.env.NODE_ENV = 'test';
npr.one
npr.one
.init()
.then(auth.getToken.bind(auth, npr))
.then((token) => {
@ -68,6 +50,3 @@ const launch = function() {
.catch(function(err) {
console.error(err, err.stack);
});
};

View file

@ -1,10 +0,0 @@
#!/usr/bin/env bash
TEMPLATE='pm2.service'
SERVICE='/etc/systemd/system/pm2.service'
if [ ! -f $SERVICE ]; then
sudo cp $TEMPLATE $SERVICE
sudo systemctl enable $SERVICE
sudo systemctl start $SERVICE
fi

View file

@ -3,7 +3,7 @@
"version": "1.4.4",
"description": "A NPR One command line client",
"main": "index.js",
"bin": "index.js",
"bin": "./cli",
"repository": {
"type": "git",
"url": "git+https://github.com/adafruit/nprone_raspi.git"
@ -22,7 +22,6 @@
"license": "MIT",
"dependencies": {
"chalk": "^1.1.3",
"cli-autoupdate": "^2.0.4",
"dotenv": "^1.2.0",
"gauge": "^2.2.1",
"inquirer": "^0.9.0",

2
version.js Normal file
View file

@ -0,0 +1,2 @@
const pkg = require('./package.json');
console.log(pkg.version);