How to use sudo-prompt - 10 common examples

To help you get started, we’ve selected a few sudo-prompt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
await new Promise((resolve, reject) => {
    const options = {
      name: "Fortify application",
      icons: "/Applications/Fortify.app/Contents/Resources/icons/icon.icns",
    };
    const appPath = path.dirname(certPath);
    const username = os.userInfo().username;
    sudo.exec(`appPath=${appPath} userDir=${os.homedir()} USER=${username} CERTUTIL=${process.cwd()} bash ${SRC_DIR}/resources/osx-ssl.sh`, options, (err, stdout) => {
      // console.log(stdout.toString());
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
github PeculiarVentures / fortify / src / main / ssl.ts View on Github external
await new Promise((resolve, reject) => {
    const options = {
      name: "Fortify application",
      icons: "/Applications/Fortify.app/Contents/Resources/icons/icon.icns",
    };
    const appPath = path.dirname(certPath);
    const username = os.userInfo().username;
    sudo.exec(`appPath=${appPath} userDir=${os.homedir()} USER=${username} bash ${SRC_DIR}/resources/osx-ssl.sh`, options, (err, stdout) => {
      // console.log(stdout.toString());
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}
github Houfeng / hoster / src / app.js View on Github external
const sleep = require('./common/sleep');
const i18n = require('./i18n');
const stp = require('stp');
const pkg = require('../package');
const hosts = require('./hosts');
const sudo = require('sudo-prompt');
const os = require('os');

const ENV_NAME = `${pkg.name}_env`;

if (process.env[ENV_NAME] != 'root') {
  let options = {
    name: pkg.displayName,
    icns: path.resolve(__dirname, '../design/icon.png')
  };
  sudo.exec(`${ENV_NAME}=root ${process.execPath}`, options, (error, stdout, stderr) => {
    if (!error) return;
    dialog.showMessageBox(null, {
      type: 'error',
      buttons: [locale.close],
      message: 'Error',
      detail: JSON.stringify(error)
    });
  });
  setTimeout(() => {
    app.quit();
  }, 500);
  return;
}

// 保持所有对于 window 对象的全局引用,如果你不这样做,
// 当 JavaScript 对象被垃圾回收, window 会被自动地关闭
github jie17 / v2ray-electron / src / proxy_conf_helper.js View on Github external
installHelper() {
    if (!fs.existsSync(this.proxyConfHelperPath)) {
      let options = {
        name: app.getName(),
        icns: path.join(global.ROOT, 'assets', 'icon.icns')
      };
      let command = `cp "${this.bundledProxyConfHelperPath}" "${this.proxyConfHelperPath}" && chown root:admin "${this.proxyConfHelperPath}" && chmod a+rx "${this.proxyConfHelperPath}" && chmod +s "${this.proxyConfHelperPath}"`
      sudo.exec(command, options,
        function(error, stdout, stderr) {
          if (error) {
            console.error(error)
          } else {
            console.log('Successfully installed helper')
          }
        }
      );
    }
  }
github quanglam2807 / webcatalog / public / libs / app-management / move-all-apps-async / forked-script.js View on Github external
const sudoAsync = prompt => new Promise((resolve, reject) => {
  const opts = {
    name: 'WebCatalog',
  };
  console.log(prompt);
  process.env.USER = username;
  sudo.exec(prompt, opts, (error, stdout, stderr) => {
    if (error) {
      console.log(error);
      return reject(error);
    }
    console.log(stdout);
    console.log(stderr);
    return resolve(stdout, stderr);
  });
});
github alvesjtiago / airpass / main.js View on Github external
function renewMacAddress() {
    let notification = new Notification({
      title: 'Changing MAC adddress 🤖',
      body: 'Please input your password when requested to make the necessary changes.',
      silent: true
    })
    notification.show();

    var sudo = require('sudo-prompt');
    var options = {
      name: 'Airpass'
    };
    sudo.exec("ifconfig en0 ether `openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`", options,
      function(error, stdout, stderr) {
        if (!error) {
          let notification = new Notification({
            title: 'MAC address changed 👌',
            body: 'Connect to the network again to start a new session 📡',
            silent: true
          })
          notification.show();
        } else {
          let issues_url = "https://github.com/alvesjtiago/airpass/issues"
          let notification = new Notification({
            title: 'Could not refresh MAC address',
            body: 'Please check ' + issues_url + ' for help.',
            silent: true
          })
          notification.show();
github icymind / VRouter / src / renderer / lib / win.js View on Github external
return new Promise((resolve, reject) => {
    sudo.exec(cmd, options, (err, stdout, stderr) => {
      if (err) {
        reject(err)
      } else {
        resolve(stdout || stderr)
      }
    })
  })
}
github mellow-io / mellow / src / main.js View on Github external
return new Promise((resolve, reject) => {
    var options = { name: 'Mellow' }
    sudo.exec(cmd, options, (err, stdout, stderr) => {
      if (err) {
        log.info(stderr)
        log.info(stdout)
        reject(err)
      }
      resolve(stdout)
    })
  })
}
github ottomatica / slim / lib / providers / hyperkit.js View on Github external
return new Promise((resolve, reject) => {
        require('sudo-prompt').exec(cmd, opts, (err, stdout) => {
            if (err) reject(err);
            else resolve(stdout);
        });
    });
};

sudo-prompt

Run a command using sudo, prompting the user with an OS dialog if necessary

MIT
Latest version published 5 years ago

Package Health Score

55 / 100
Full package analysis

Popular sudo-prompt functions