diff --git a/build/actions/os.js b/build/actions/os.js index 1a4373d9..91a2645b 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -1,5 +1,5 @@ (function() { - var _, async, commandOptions, elevate, mkdirp, npm, os, packageJSON, path, resin, updateActions, visuals; + var _, async, commandOptions, elevate, mkdirp, npm, os, packageJSON, path, resin, umount, updateActions, visuals; _ = require('lodash-contrib'); @@ -15,6 +15,8 @@ visuals = require('resin-cli-visuals'); + umount = require('umount').umount; + commandOptions = require('./command-options'); npm = require('../npm'); @@ -97,7 +99,7 @@ exports.install = { signature: 'os install [device]', description: 'write an operating system image to a device', - help: 'Use this command to write an operating system image to a device.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nSee the `drives` command to get a list of all connected devices to your machine and their respective ids.\n\nIn Mac OS X:\n\n $ sudo diskutil unmountDisk /dev/xxx\n\nIn GNU/Linux:\n\n $ sudo umount /dev/xxx\n\nExamples:\n\n $ resin os install rpi.iso /dev/disk2', + help: 'Use this command to write an operating system image to a device.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nExamples:\n\n $ resin os install rpi.iso /dev/disk2', options: [commandOptions.yes], permission: 'user', action: function(params, options, done) { @@ -131,10 +133,12 @@ message = "This will completely erase " + params.device + ". Are you sure you want to continue?"; return visuals.patterns.confirm(options.yes, message, callback); }, function(confirmed, callback) { - var bar; if (!confirmed) { return done(); } + return umount(params.device, _.unary(callback)); + }, function(callback) { + var bar; bar = new visuals.widgets.Progress('Writing Device OS'); params.progress = _.bind(bar.update, bar); return bundle.write(params, callback); diff --git a/doc/cli.markdown b/doc/cli.markdown index a12479f6..17d789cb 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -675,18 +675,6 @@ You can avoid this by passing the `--yes` boolean option. You can quiet the progress bar by passing the `--quiet` boolean option. -You may have to unmount the device before attempting this operation. - -See the `drives` command to get a list of all connected devices to your machine and their respective ids. - -In Mac OS X: - - $ sudo diskutil unmountDisk /dev/xxx - -In GNU/Linux: - - $ sudo umount /dev/xxx - Examples: $ resin os install rpi.iso /dev/disk2 diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index d3e5050a..b6e00f7c 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -5,6 +5,7 @@ path = require('path') mkdirp = require('mkdirp') resin = require('resin-sdk') visuals = require('resin-cli-visuals') +umount = require('umount').umount commandOptions = require('./command-options') npm = require('../npm') packageJSON = require('../../package.json') @@ -108,18 +109,6 @@ exports.install = You can quiet the progress bar by passing the `--quiet` boolean option. - You may have to unmount the device before attempting this operation. - - See the `drives` command to get a list of all connected devices to your machine and their respective ids. - - In Mac OS X: - - $ sudo diskutil unmountDisk /dev/xxx - - In GNU/Linux: - - $ sudo umount /dev/xxx - Examples: $ resin os install rpi.iso /dev/disk2 @@ -168,7 +157,9 @@ exports.install = (confirmed, callback) -> return done() if not confirmed + umount(params.device, _.unary(callback)) + (callback) -> bar = new visuals.widgets.Progress('Writing Device OS') params.progress = _.bind(bar.update, bar) bundle.write(params, callback) diff --git a/package.json b/package.json index 16bd67ca..0da703a2 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "resin-settings-client": "^1.0.0", "resin-vcs": "^1.2.0", "tmp": "^0.0.25", + "umount": "^1.0.0", "underscore.string": "~2.4.0", "update-notifier": "^0.3.1" }