2013-12-23 04:22:54 +00:00
|
|
|
Promise = require 'bluebird'
|
|
|
|
fs = Promise.promisifyAll require 'fs'
|
|
|
|
os = require 'os'
|
|
|
|
crypto = require 'crypto'
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
# Parses the output of /proc/cpuinfo to find the "Serial : 710abf21" line
|
|
|
|
# or the hostname if there isn't a serial number (when run in dev mode)
|
|
|
|
# The uuid is the SHA1 hash of that value.
|
|
|
|
exports.getDeviceUuid = ->
|
2014-03-19 19:17:07 +00:00
|
|
|
fs.readFileAsync('/proc/cpuinfo', 'utf8')
|
|
|
|
.then (cpuinfo) ->
|
2013-12-14 05:18:20 +00:00
|
|
|
serial = cpuinfo
|
|
|
|
.split('\n')
|
|
|
|
.filter((line) -> line.indexOf('Serial') isnt -1)[0]
|
|
|
|
?.split(':')[1]
|
|
|
|
.trim() or os.hostname()
|
2014-03-19 19:17:07 +00:00
|
|
|
|
2013-12-14 05:18:20 +00:00
|
|
|
return crypto.createHash('sha1').update(serial, 'utf8').digest('hex')
|
2014-04-28 10:56:17 +00:00
|
|
|
|
|
|
|
# Parses package.json and returns resin-supervisor's version
|
|
|
|
exports.getSupervisorVersion = ->
|
2014-04-29 07:29:10 +00:00
|
|
|
fs.readFileAsync '../package.json', 'utf-8'
|
2014-04-28 10:56:17 +00:00
|
|
|
.then (data) ->
|
|
|
|
obj = JSON.parse data
|
2014-04-29 07:29:10 +00:00
|
|
|
return obj.version
|