Strip sudo use if running as root on Linux/macOS

* Allows running under live macOS
This commit is contained in:
2Shirt 2020-01-30 13:03:21 -07:00
parent 41130a38ed
commit e1943b9fb4
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -3,6 +3,7 @@
import json
import logging
import os
import re
import subprocess
@ -77,6 +78,10 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
'shell': shell,
}
# Strip sudo if appropriate
if cmd[0] == 'sudo' and os.name == 'posix' and os.geteuid() == 0:
cmd.pop(0)
# Add additional kwargs if applicable
for key in 'check cwd encoding errors stderr stdin stdout'.split():
if key in kwargs: