forked from Mirror/pmbootstrap
Fix #5: proper error message, when chroot binary is not in PATH
This commit is contained in:
parent
c7f8e99fb8
commit
15a495b7e2
1 changed files with 18 additions and 5 deletions
|
@ -26,6 +26,20 @@ import pmb.chroot.binfmt
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
|
|
||||||
|
|
||||||
|
def executables_absolute_path():
|
||||||
|
"""
|
||||||
|
Get the absolute paths to the sh and chroot executables.
|
||||||
|
"""
|
||||||
|
ret = {}
|
||||||
|
for binary in ["sh", "chroot"]:
|
||||||
|
path = shutil.which(binary)
|
||||||
|
if not path:
|
||||||
|
raise RuntimeError("Could not find the '" + binary +
|
||||||
|
"' executable. Make sure, that it is in" " your current user's PATH.")
|
||||||
|
ret[binary] = path
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def root(args, cmd, suffix="native", working_dir="/", log=True,
|
def root(args, cmd, suffix="native", working_dir="/", log=True,
|
||||||
auto_init=True, return_stdout=False, check=True):
|
auto_init=True, return_stdout=False, check=True):
|
||||||
"""
|
"""
|
||||||
|
@ -43,20 +57,19 @@ def root(args, cmd, suffix="native", working_dir="/", log=True,
|
||||||
|
|
||||||
# Run the args with sudo chroot, and with cleaned environment
|
# Run the args with sudo chroot, and with cleaned environment
|
||||||
# variables
|
# variables
|
||||||
sh_bin = shutil.which("sh")
|
executables = executables_absolute_path()
|
||||||
chroot_bin = shutil.which("chroot")
|
|
||||||
for i in range(len(cmd)):
|
for i in range(len(cmd)):
|
||||||
cmd[i] = shlex.quote(cmd[i])
|
cmd[i] = shlex.quote(cmd[i])
|
||||||
|
|
||||||
cmd_inner_shell = ("cd " + shlex.quote(working_dir) + ";" +
|
cmd_inner_shell = ("cd " + shlex.quote(working_dir) + ";" +
|
||||||
" ".join(cmd))
|
" ".join(cmd))
|
||||||
cmd_full = ["sudo", sh_bin, "-c",
|
|
||||||
|
cmd_full = ["sudo", executables["sh"], "-c",
|
||||||
"unset $(env | cut -d= -f1);" + # unset all
|
"unset $(env | cut -d= -f1);" + # unset all
|
||||||
" CHARSET=UTF-8" +
|
" CHARSET=UTF-8" +
|
||||||
" PATH=" + pmb.config.chroot_path +
|
" PATH=" + pmb.config.chroot_path +
|
||||||
" SHELL=/bin/ash" +
|
" SHELL=/bin/ash" +
|
||||||
" HISTFILE=~/.ash_history" +
|
" HISTFILE=~/.ash_history" +
|
||||||
" " + chroot_bin +
|
" " + executables["chroot"] +
|
||||||
" " + chroot +
|
" " + chroot +
|
||||||
" sh -c " + shlex.quote(cmd_inner_shell)
|
" sh -c " + shlex.quote(cmd_inner_shell)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue