From 26e96f8bf53b804c1a5cf53b3e99d25afde02de2 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Thu, 28 Apr 2011 10:41:07 -0500 Subject: [PATCH] enter: use jail_params to probe for a usable shell instead of hardcoding --- enter | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/enter b/enter index 1efee77..fda08d4 100755 --- a/enter +++ b/enter @@ -17,8 +17,7 @@ cmd="$(basename "${0}")" base="$(realpath "$(dirname "${0}")")" jail="$(basename "${1:-DebianChroot}")" jdir="${base}/${jail}" - -[ -d "${jdir}" ] || wtf "not a jail?" +jail_shell="" # Propagate certain environment variables; sterilize the rest of the environment env=" @@ -31,6 +30,20 @@ jail_new() { DEBOOTSTRAP_DIR="$(base)/debootstrap" "${DEBOOTSTRAP_DIR}/debootstrap" --arch=amd64 squeeze "${jdir}" } +# Figure out jail parameters +jail_params() { + # Where is the shell? + for shell in /bin/bash /usr/bin/bash /usr/local/bin/bash /bin/sh + do + if [ -f "${jdir}/${shell}" ] + then + jail_shell=${shell} + break + fi + wtf "cannot locate usable shell; is this a real jail?" + done +} + # Jail is 'up' if /dev/pts and /proc are mounted jail_up() { grep -q "^devpts ${jdir}/dev/pts devpts" /proc/mounts || return 1 @@ -50,7 +63,7 @@ jail_start() { jail_enter() { jail_up || wtf "jail not up" meh "entering ${jail} ..." - env -i ${env} /usr/bin/chroot "${jdir}" /bin/su "${USER}" -c /bin/bash -l + env -i ${env} /usr/bin/chroot "${jdir}" /bin/su "${USER}" -c "${jail_shell}" -l } # Unmount /dev/pts and /proc in the jail @@ -64,6 +77,8 @@ jail_stop() { # Need root beyond here [ "$(id -u)" -eq 0 ] || exec sudo env ${env} "${0}" "${@}" +jail_params + case "${cmd}" in start) jail_start ;; enter) jail_enter ;; -- 2.42.0