rootCheck.js 1022 B

1234567891011121314151617181920212223242526272829303132
  1. /*jshint multistr:true*/
  2. 'use strict';
  3. var isRoot = require('is-root');
  4. var createError = require('./createError');
  5. var cli = require('./cli');
  6. var renderer;
  7. function rootCheck(options, config) {
  8. var errorMsg;
  9. // Allow running the command as root
  10. if (options.allowRoot || config.allowRoot) {
  11. return;
  12. }
  13. errorMsg = 'Since bower is a user command, there is no need to execute it with \
  14. superuser permissions.\nIf you\'re having permission errors when using bower without \
  15. sudo, please spend a few minutes learning more about how your system should work and \
  16. make any necessary repairs.\n\n\
  17. http://www.joyent.com/blog/installing-node-and-npm\n\
  18. https://gist.github.com/isaacs/579814\n\n\
  19. You can however run a command with sudo using --allow-root option';
  20. if (isRoot()) {
  21. renderer = cli.getRenderer('', false, config);
  22. renderer.error(createError('Cannot be run with sudo', 'ESUDO', { details : errorMsg }));
  23. process.exit(1);
  24. }
  25. }
  26. module.exports = rootCheck;