From 2a5d7dff6f78e1b68ba163cc9843a478f108cd7b Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 13 Jul 2012 07:47:30 -0500 Subject: [PATCH] j: autodetect chroot binary location; different in different distros --- j | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/j b/j index ea86670..5b50932 100755 --- a/j +++ b/j @@ -50,6 +50,14 @@ jseed="${j}/seeds" jname="${J_NAME:-$(basename "${1}")}" #" juser="${J_USER}" +# Find chroot binary, since it can be in many different places on different distros +for chroot in /usr/sbin/chroot /usr/bin/chroot /sbin/chroot /bin/chroot +do + [ -f "${chroot}" ] && break + unset chroot +done +[ "${chroot}" ] || wtf "Cannot find chroot in /usr/sbin:/usr/bin:/sbin:/bin" + # cgroup to use; if not found, cgroup support will not be used jcgroup="freezer" # cgroup parent to use (${cgroup}/${parent}/${jname}) @@ -324,7 +332,7 @@ j_root_eval() { j_up "${jname}" || wtf "chroot not running" eval "$(j_params "${jname}")" j_cg_trap $$ - env -i ${jenv} /usr/bin/chroot "${jroot}" /bin/sh -c "${*}" + env -i ${jenv} "${chroot}" "${jroot}" /bin/sh -c "${*}" } # Execute command in chroot @@ -333,7 +341,7 @@ j_eval() { j_up "${jname}" || wtf "chroot not running" eval "$(j_params "${jname}")" j_cg_trap $$ - env -i ${jenv} /usr/bin/chroot "${jroot}" /bin/su "${juser:-${USER}}" -c "${*}" + env -i ${jenv} "${chroot}" "${jroot}" /bin/su "${juser:-${USER}}" -c "${*}" } # Invoke a shell within the chroot -- 2.45.0