MCPcopy
hub / github.com/ntfstool/ntfstool / execShellSudo

Function execShellSudo

src/common/utils/AlfwShell.js:78–122  ·  view source on GitHub ↗
(shell, force = false)

Source from the content-addressed store, hash-verified

76 * @returns {Promise}
77 */
78export function execShellSudo(shell, force = false) {
79 return new Promise((resolve, reject) => {
80 var password = getSudoPwd();
81 try {
82 exec(`echo '${password}'|sudo -Sk ${shell}`, (error, stdout, stderr) => {
83 stderr = stderr.replace( /^Password:/gi , '')
84 saveLog.log("execShellSudo", {
85 code: "[SUDO]" + shell,
86 stdout: stdout,
87 stderr: stderr,
88 // error:error
89 })
90 if (force == true) {
91 resolve();
92 return;
93 }
94 if (stderr) {
95 if (checkIncorrectPasswordStr(stderr)) {
96 checkSudoPassword().then(res => {
97 if (!res) {
98 reject(stderr);
99 return;
100 }
101 });
102 }else if(!checkFuseStr(stderr)){
103 ipcRenderer.send("IPCMain",AlConst.InstallFuseEvent);
104 }else if(!checkNotSudoer(stderr)){
105 console.warn("checkNotSudoer ok");
106 ipcRenderer.send("IPCMain",{
107 name:AlConst.NotSudoerEvent,
108 data:stderr
109 });
110 } else {
111 reject(stderr);
112 return;
113 }
114 } else {
115 resolve(stdout, stderr)
116 }
117 });
118 } catch (e) {
119 saveLog.error(e, "execShellSudo");
120 }
121 })
122}
123
124
125/**

Callers 2

reMountNtfsFunction · 0.90
uMountDiskFunction · 0.90

Calls 5

getSudoPwdFunction · 0.90
checkSudoPasswordFunction · 0.85
checkFuseStrFunction · 0.85
checkNotSudoerFunction · 0.85

Tested by

no test coverage detected