mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 15:27:17 +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 SDK = require('../../../sdk')
|
||||
const permissions = require('../../../shared/permissions')
|
||||
|
||||
const scanner = SDK.createScanner({
|
||||
blockdevice: {
|
||||
@ -29,17 +28,4 @@ const scanner = SDK.createScanner({
|
||||
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
|
||||
|
@ -19,6 +19,8 @@
|
||||
const _ = require('lodash')
|
||||
const os = require('os')
|
||||
|
||||
const permissions = require('../../shared/permissions')
|
||||
|
||||
/**
|
||||
* @summary The list of loaded adapters
|
||||
* @type {Object[]}
|
||||
@ -28,10 +30,8 @@ const ADAPTERS = [
|
||||
require('./blockdevice')
|
||||
]
|
||||
|
||||
// We don't support usbboot on GNU/Linux yet, given
|
||||
// that some distributions require root permissions
|
||||
// to open USB devices.
|
||||
if (os.platform() !== 'linux') {
|
||||
// On GNU/Linux, we only support usbboot when running as root.
|
||||
if ((os.platform() !== 'linux') || permissions.isElevatedUnixSync()) {
|
||||
ADAPTERS.push(require('./usbboot'))
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,26 @@ exports.isElevated = () => {
|
||||
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
|
||||
* @function
|
||||
|
Loading…
x
Reference in New Issue
Block a user