All pastes #155356 Raw Edit

start-chroot.sh

public text v1 · immutable
#155356 ·published 2006-08-31 00:37 UTC
rendered paste body
#!/bin/bash

CHROOTDIR="/chroot"

NO_COLOR="\033[0m"
BLUEGREEN="\033[0,36m"
RED="\033[1,31m"
GREEN="\033[0,32m"
YELLOW="\033[0,33m"
BLUE="\033[0,34m"

function mountverify {

  [[ $# != 1 ]] && return 1

  local mountpoint=${CHROOTDIR}$1

  echo -en "  ${BLUE}${mountpoint} ... "
  if grep -q ${mountpoint} /etc/mtab; then
    echo -e "${YELLOW}already mounted${NO_COLOR}"
  else
    [[ $1 == "/proc" ]] \
      && local mountcommand="mount -t proc none ${mountpoint}" \
      || local mountcommand="mount -o bind $1 ${mountpoint}"
    ${mountcommand} >/dev/null \
      && echo -e "${GREEN}done${NO_COLOR}" \
      || echo -e "${RED}failed${NO_COLOR}"
  fi

}

echo -e "${BLUEGREEN}Mouting directories into chroot ... ${NO_COLOR}"
mountverify /proc
mountverify /dev
mountverify /sys
mountverify /var/portage
mountverify /var/distfiles
mountverify /usr/src/linux
mountverify /lib/modules
mountverify /tmp

echo -en "${BLUEGREEN}Coping /etc/resolv.conf into chroot ... ${NO_COLOR}"
cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf \
  && echo -e "${GREEN}done${NO_COLOR}" \
  || echo -e "${RED}failed${NO_COLOR}"

echo -e "${BLUEGREEN}Chrooting ... ${NO_COLOR}\n"
chroot ${CHROOTDIR} /bin/bash