mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 18:56:31 +00:00
fix(CLI): check CLI elevation early on (#864)
The CLI requires elevation permissions to actually be able to write to drives. For this reason, it makes sense that we introduce such a check early on. See: https://github.com/resin-io/etcher/issues/726 Change-Type: patch Changelog-Entry: Check available permissions in the CLI early on. Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
parent
4e3bdb7e22
commit
b4f1d82a51
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const Bluebird = require('bluebird');
|
const Bluebird = require('bluebird');
|
||||||
|
const isElevated = Bluebird.promisify(require('is-elevated'));
|
||||||
const visuals = require('resin-cli-visuals');
|
const visuals = require('resin-cli-visuals');
|
||||||
const form = require('resin-cli-form');
|
const form = require('resin-cli-form');
|
||||||
const drivelist = Bluebird.promisifyAll(require('drivelist'));
|
const drivelist = Bluebird.promisifyAll(require('drivelist'));
|
||||||
@ -26,28 +27,34 @@ const utils = require('./utils');
|
|||||||
const options = require('./cli');
|
const options = require('./cli');
|
||||||
const EXIT_CODES = require('../src/exit-codes');
|
const EXIT_CODES = require('../src/exit-codes');
|
||||||
|
|
||||||
form.run([
|
isElevated().then((elevated) => {
|
||||||
{
|
if (!elevated) {
|
||||||
message: 'Select drive',
|
throw new Error('This should should be run with root/administrator permissions');
|
||||||
type: 'drive',
|
|
||||||
name: 'drive'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: 'This will erase the selected drive. Are you sure?',
|
|
||||||
type: 'confirm',
|
|
||||||
name: 'yes',
|
|
||||||
default: false
|
|
||||||
}
|
}
|
||||||
], {
|
|
||||||
override: {
|
|
||||||
drive: options.drive,
|
|
||||||
|
|
||||||
// If `options.yes` is `false`, pass `undefined`,
|
return form.run([
|
||||||
// otherwise the question will not be asked because
|
{
|
||||||
// `false` is a defined value.
|
message: 'Select drive',
|
||||||
yes: options.robot || options.yes || undefined
|
type: 'drive',
|
||||||
|
name: 'drive'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: 'This will erase the selected drive. Are you sure?',
|
||||||
|
type: 'confirm',
|
||||||
|
name: 'yes',
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
], {
|
||||||
|
override: {
|
||||||
|
drive: options.drive,
|
||||||
|
|
||||||
}
|
// If `options.yes` is `false`, pass `undefined`,
|
||||||
|
// otherwise the question will not be asked because
|
||||||
|
// `false` is a defined value.
|
||||||
|
yes: options.robot || options.yes || undefined
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}).then((answers) => {
|
}).then((answers) => {
|
||||||
if (!answers.yes) {
|
if (!answers.yes) {
|
||||||
throw new Error('Aborted');
|
throw new Error('Aborted');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user