balena-supervisor/src/utils.coffee

29 lines
840 B
CoffeeScript
Raw Normal View History

2013-12-23 04:22:54 +00:00
Promise = require 'bluebird'
fs = Promise.promisifyAll require 'fs'
os = require 'os'
crypto = require 'crypto'
# 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) ->
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
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 = ->
fs.readFileAsync '../package.json'
.then (data) ->
obj = JSON.parse data
Promise.resolve obj
.then (obj) ->
return obj.version