#! /bin/sh -e . /usr/share/debconf/confmodule chroot_has () { PATH="$CHROOT_PATH" /bin/search-path "$1" } chroot_run () { db_subst rescue/shell/title DEVICE "$RESCUE_ROOTDEV" start-shell rescue/shell/title chroot /target "$@" } # Work out a sensible $PATH with respect to /target. CHROOT_PATH= OLD_IFS="$IFS" IFS=: for element in $PATH; do # Only include absolute elements. if [ "${element#/}" != "$element" ]; then CHROOT_PATH="${CHROOT_PATH:+$CHROOT_PATH:}/target$element" fi done IFS="$OLD_IFS" shell_failed () { db_capb db_subst rescue/shell/run-failed SHELL "$*" db_subst rescue/shell/run-failed DEVICE "$RESCUE_ROOTDEV" db_input critical rescue/shell/run-failed db_go || true db_capb backup } if chroot_has bash; then chroot_run 'bash -i' || shell_failed 'bash -i' elif [ -f /target/bin/sh ] && [ -x /target/bin/sh ]; then chroot_run /bin/sh -i || shell_failed '/bin/sh -i' elif chroot_has sash; then chroot_run sash || shell_failed sash elif chroot_has busybox; then # Try this last even though busybox is useful, since it might fail # due to a missing sh applet. chroot_run busybox sh || shell_failed 'busybox sh' else db_capb db_subst rescue/shell/not-found DEVICE "$RESCUE_ROOTDEV" db_input critical rescue/shell/not-found db_go || true db_capb backup fi exit 0