From 10451fd27dcebfbe584db41fa47eeb2c4935393e Mon Sep 17 00:00:00 2001 From: Vasilis Souleles Date: Mon, 28 Apr 2014 13:56:17 +0300 Subject: [PATCH] added getSupevisorVersion --- src/app.coffee | 7 ++++--- src/application.coffee | 4 ++-- src/bootstrap.coffee | 4 +++- src/utils.coffee | 10 ++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app.coffee b/src/app.coffee index 7ae8430e..32826ec8 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -13,15 +13,16 @@ console.log('Supervisor started..') newUuid = utils.getDeviceUuid() oldUuid = knex('config').select('value').where(key: 'uuid') +version = utils.getSupevisorVersion() -Promise.all([newUuid, oldUuid]) -.then ([newUuid, [oldUuid]]) -> +Promise.all([newUuid, oldUuid, version]) +.then ([newUuid, [oldUuid], version]) -> oldUuid = oldUuid?.value if newUuid is oldUuid return true console.log('New device detected. Bootstrapping..') - return bootstrap(newUuid) + return bootstrap(newUuid, version) .then -> console.log('Starting OpenVPN..') openvpn = spawn('openvpn', ['client.conf'], cwd: '/data') diff --git a/src/application.coffee b/src/application.coffee index 2f191057..acf4d098 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -147,13 +147,13 @@ exports.update = -> promises = toBeInstalled.map (imageId) -> app = remoteApps[imageId] start(app) - .then -> + .then -> knex('app').insert(app) # And restart updated apps and update db as they succeed promises = promises.concat toBeUpdated.map (imageId) -> app = remoteApps[imageId] restart(app) - .then -> + .then -> knex('app').update(app).where(imageId: app.imageId) # And delete all the ones to remove in one go promises.push( diff --git a/src/bootstrap.coffee b/src/bootstrap.coffee index ae636070..d8cce9f3 100644 --- a/src/bootstrap.coffee +++ b/src/bootstrap.coffee @@ -7,7 +7,7 @@ crypto = require 'crypto' csrgen = Promise.promisify require 'csr-gen' request = Promise.promisify require 'request' -module.exports = (uuid) -> +module.exports = (uuid, version) -> # Load config file config = fs.readFileAsync('/boot/config.json', 'utf8').then(JSON.parse) @@ -30,6 +30,7 @@ module.exports = (uuid) -> console.log('UUID:', uuid) console.log('User ID:', config.userId) console.log('User:', config.username) + console.log('Supervisor Version:', version) console.log('API key:', config.apiKey) console.log('Application ID:', config.applicationId) console.log('CSR :', keys.csr) @@ -67,6 +68,7 @@ module.exports = (uuid) -> {key: 'apiKey', value: config.apiKey} {key: 'username', value: config.username} {key: 'userId', value: config.userId} + {key: 'version', value: version} ]) knex('app').truncate() ]) diff --git a/src/utils.coffee b/src/utils.coffee index f35a57bd..2866cf5b 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -16,3 +16,13 @@ exports.getDeviceUuid = -> .trim() or os.hostname() return crypto.createHash('sha1').update(serial, 'utf8').digest('hex') + +# Parses package.json and returns resin-supervisor's version +exports.getSupervisorVersion = -> + fs.readFileAsync '../package.json' + .then (data) -> + obj = JSON.parse data + + Promise.resolve obj + .then (obj) -> + return obj.version