@@ -115,8 +115,18 @@ class ContainerNotifier extends _$ContainerNotifier {
115115 final cmd = _wrap (ContainerCmdType .execAll (state.type, sudo: sudo, includeStats: includeStats, password: password));
116116 int ? code;
117117 String raw = '' ;
118+ var isPodmanEmulation = false ;
118119 if (client != null ) {
119- (code, raw) = await client! .execWithPwd (cmd, context: context, id: hostId);
120+ (code, raw) = await client! .execWithPwd (
121+ cmd,
122+ context: context,
123+ id: hostId,
124+ onStderr: (data, _) {
125+ if (data.contains (_podmanEmulationMsg)) {
126+ isPodmanEmulation = true ;
127+ }
128+ },
129+ );
120130 } else {
121131 state = state.copyWith (
122132 isBusy: false ,
@@ -144,7 +154,7 @@ class ContainerNotifier extends _$ContainerNotifier {
144154 }
145155
146156 /// Pre-parse Podman detection
147- if (raw. contains (_podmanEmulationMsg) ) {
157+ if (isPodmanEmulation ) {
148158 state = state.copyWith (
149159 error: ContainerErr (
150160 type: ContainerErrType .podmanDetected,
@@ -349,7 +359,7 @@ const _jsonFmt = '--format "{{json .}}"';
349359
350360String _buildSudoCmd (String baseCmd, String password) {
351361 final pwdBase64 = base64Encode (utf8.encode (password));
352- return 'echo "$pwdBase64 " | base64 -d | sudo -S $baseCmd 2>/dev/null' ; // Discard stderr to avoid password prompt
362+ return 'echo "$pwdBase64 " | base64 -d | sudo -S $baseCmd ' ;
353363}
354364
355365enum ContainerCmdType {
@@ -389,9 +399,42 @@ enum ContainerCmdType {
389399 }
390400
391401 static String execAll (ContainerType type, {bool sudo = false , bool includeStats = false , String ? password}) {
392- return ContainerCmdType .values
393- .map ((e) => e.exec (type, sudo: sudo , includeStats: includeStats, password : password ))
402+ final commands = ContainerCmdType .values
403+ .map ((e) => e.exec (type, sudo: false , includeStats: includeStats))
394404 .join ('\n echo ${ScriptConstants .separator }\n ' );
405+
406+ print ('[DEBUG] commands: $commands ' );
407+
408+ final needsShWrapper = commands.contains ('\n ' ) || commands.contains ('echo ${ScriptConstants .separator }' );
409+
410+ if (needsShWrapper) {
411+ if (sudo && password != null ) {
412+ final pwdBase64 = base64Encode (utf8.encode (password));
413+ final cmd = 'echo "$pwdBase64 " | base64 -d | sudo -S sh -c \' ${commands .replaceAll ("'" , "'\\ ''" )}\' ' ;
414+ print ('[DEBUG] final sudo cmd (with sh): $cmd ' );
415+ return cmd;
416+ }
417+ if (sudo) {
418+ final cmd = 'sudo -S sh -c \' ${commands .replaceAll ("'" , "'\\ ''" )}\' ' ;
419+ print ('[DEBUG] final sudo cmd: $cmd ' );
420+ return cmd;
421+ }
422+ final cmd = 'sh -c \' ${commands .replaceAll ("'" , "'\\ ''" )}\' ' ;
423+ print ('[DEBUG] final sh cmd: $cmd ' );
424+ return cmd;
425+ }
426+
427+ if (sudo && password != null ) {
428+ final cmd = _buildSudoCmd (commands, password);
429+ print ('[DEBUG] final sudo cmd: $cmd ' );
430+ return cmd;
431+ }
432+ if (sudo) {
433+ final cmd = 'sudo -S $commands ' ;
434+ print ('[DEBUG] final sudo cmd: $cmd ' );
435+ return cmd;
436+ }
437+ return commands;
395438 }
396439
397440 /// Find out the required segment from [segments]
0 commit comments