pac
pac copied to clipboard
using sudo
Have you tried child_process.exec()? http://stackoverflow.com/questions/23209413/how-to-respond-to-a-command-line-promt-with-node-js
In Gnome and most of its derivatives, the standard graphical frontend for sudo is gksu/gksudo. In KDE it is kdesudo. (It depends on the desktop environment being used.)
I see what you're saying, but I still think that child_process.exec is going to be the answer. You're going to have to figure out which "sudo" to use with it. A super "hacky" way to do it would be something like this:
// whichGUISudo.js
const fs = require('fs');
module.exports = function() {
// possible locations to find a GUI sudo program
const sudoLocations = [
'/usr/bin/gksudo',
'/usr/bin/gksu',
'/usr/bin/kdesudo',
];
// iterate the list and if found, return it.
for (l in sudoLocations) {
if (fs.existsSync(l)) {
return l;
}
}
// return false if nothing is found
return false;
}
Add possible GUI sudos to the sudoLocations
array in the function, it will return which one was found, or false if none. You could run this once at app start up, and if none are found query the user for its location. You could then save that location somewhere and modify the function to use that when available, otherwise go checking for location dynamically.
You could also have it send you any "new locations" so you can add them to the sudoLocations
array (might want to ask the user if this is OK, but if all you send is the location to a sudo, I doubt anyone would mind...)
Also, if gksu is just a symlink to gksudo, I'd remove it from the list, no point in checking for symlinks ;)
Fall back could be to try opening a terminal and displaying sudo there? On 27 Jan 2016 17:05, "magicalcows" [email protected] wrote:
I see what you're saying, but I still think that child_process.exec is going to be the answer. You're going to have to figure out which "sudo" to use with it. A super "hacky" way to do it would be something like this:
// whichGUISudo.js const fs = require('fs');
module.exports = function() {
// possible locations to find a GUI sudo program const sudoLocations = [ '/usr/bin/gksudo', '/usr/bin/gksu', '/usr/bin/kdesudo', ]; // iterate the list and if found, return it. for (l in sudoLocations) { if (fs.existsSync(l)) { return l; } } // return false if nothing is found return false;
}
Add possible GUI sudos to the sudoLocations array in the function, it will return which one was found, or false if none. You could run this once at app start up, and if none are found query the user for its location. You could then save that location somewhere and modify the function to use that when available, otherwise go checking for location dynamically.
You could also have it send you any "new locations" so you can add them to the sudoLocations array (might want to ask the user if this is OK, but if all you send is the location to a sudo, I doubt anyone would mind...)
Also, if gksu is just a symlink to gksudo, I'd remove it from the list, no point in checking for symlinks ;)
— Reply to this email directly or view it on GitHub https://github.com/jonathanewerner/pac/issues/2#issuecomment-175748468.
I'd let folks open their own terminal. We're working here to figure out which gui sudo to run, what about which terminal? Chances are there's a few installed, and they may have installed their own favorite (for instance, I use terminator.)
I think just giving them a screen explaining that you were unable to automatically locate their graphical sudo program and to please enter the location into "the box below".
The screen could even list the locations you tried to look, but you'll want to move your array of locations to it's own module then so both the function and this screen can require
it in.
If you do enough research on where these graphical sudo programs might be located, this screen should rarely be seen. =)
Another thought, it's possible to install other GUI sudos is it not? So maybe this should be a preference, as opposed to something that is decided for them. You could use the "hack" I wrote earlier to set the default, but then if the user wanted to change it, they could go to the preferences screen in your app and set it there. You could also direct them there after failing to find a default and showing them the message (maybe even draw focus to that field in the preferences screen.)
The same could be true for a terminal. If you have other areas you'd open a terminal for them, then you could have a preference that lets them set which term to use.
What do you think of sudo-prompt?
Sorry guys. Haven't been very responsive here. sudo-prompt
seems promising, would you be willing to take a stab at implementing it @rkmax ?
tomorrow I'll test a bit if everything it's fine I could do PR
I'm having troubles with sudo-prompt and webpack. Cannot resolve module 'child_process' same for fs
I figure out how to do it. adding target: 'electron' to webpack.config.js