mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 23:37:18 +00:00
fix(sdk): Load usbboot adapter on start
Change-type: patch Changelog-entry: Load usbboot adapter on start on GNU/Linux if running as root. Signed-off-by: Alexis Svinartchouk <alexis@resin.io>
This commit is contained in:
parent
fd19af23a6
commit
26779ef1fb
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
const settings = require('../models/settings')
|
const settings = require('../models/settings')
|
||||||
const SDK = require('../../../sdk')
|
const SDK = require('../../../sdk')
|
||||||
const permissions = require('../../../shared/permissions')
|
|
||||||
|
|
||||||
const scanner = SDK.createScanner({
|
const scanner = SDK.createScanner({
|
||||||
blockdevice: {
|
blockdevice: {
|
||||||
@ -29,17 +28,4 @@ const scanner = SDK.createScanner({
|
|||||||
usbboot: {}
|
usbboot: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
// NOTE: Enable USBBoot on Linux if run as root
|
|
||||||
permissions.isElevated().then((elevated) => {
|
|
||||||
if (elevated && process.platform === 'linux') {
|
|
||||||
const UsbbootAdapter = require('../../../sdk/adapters/usbboot')
|
|
||||||
const adapter = new UsbbootAdapter()
|
|
||||||
scanner.stop()
|
|
||||||
scanner.subscribe(adapter)
|
|
||||||
scanner.start()
|
|
||||||
}
|
|
||||||
}).catch((error) => {
|
|
||||||
console.warn('Could not add usbboot adapter:', error)
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = scanner
|
module.exports = scanner
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
|
|
||||||
|
const permissions = require('../../shared/permissions')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary The list of loaded adapters
|
* @summary The list of loaded adapters
|
||||||
* @type {Object[]}
|
* @type {Object[]}
|
||||||
@ -28,10 +30,8 @@ const ADAPTERS = [
|
|||||||
require('./blockdevice')
|
require('./blockdevice')
|
||||||
]
|
]
|
||||||
|
|
||||||
// We don't support usbboot on GNU/Linux yet, given
|
// On GNU/Linux, we only support usbboot when running as root.
|
||||||
// that some distributions require root permissions
|
if ((os.platform() !== 'linux') || permissions.isElevatedUnixSync()) {
|
||||||
// to open USB devices.
|
|
||||||
if (os.platform() !== 'linux') {
|
|
||||||
ADAPTERS.push(require('./usbboot'))
|
ADAPTERS.push(require('./usbboot'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,26 @@ exports.isElevated = () => {
|
|||||||
return Bluebird.resolve(process.geteuid() === UNIX_SUPERUSER_USER_ID)
|
return Bluebird.resolve(process.geteuid() === UNIX_SUPERUSER_USER_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Check if the current process is running with elevated permissions
|
||||||
|
* @function
|
||||||
|
* @public
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* permissions.isElevatedUnixSync()
|
||||||
|
* if (isElevated) {
|
||||||
|
* console.log('This process has elevated permissions');
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
exports.isElevatedUnixSync = () => {
|
||||||
|
return (process.geteuid() === UNIX_SUPERUSER_USER_ID)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Get environment command prefix
|
* @summary Get environment command prefix
|
||||||
* @function
|
* @function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user