rendered paste body#!/bin/bashCHROOTDIR="/chroot"NOCOLOR="\033[0m"RED="\033[1;31m"GREEN="\033[0;32m"YELLOW="\033[0;33m"BLUE="\033[0;34m"BLUEGREEN="\033[0;36m"function mountverify { [[ "$#" -ne 1 ]] && return 1 local mountpoint=${CHROOTDIR}$1 echo -en " ${BLUE}${mountpoint} ... " if grep -q ${mountpoint} /etc/mtab; then echo -e "${YELLOW}already mounted${NOCOLOR}" else case "$1" in /proc) local mountcommand="mount -t proc none ${mountpoint}" ;; /dev/pts) local mountcommand="mount -t devpts none ${mountpoint}" ;; *) local mountcommand="mount -o bind $1 ${mountpoint}";; esac ${mountcommand} \ && echo -e "${GREEN}done${NOCOLOR}" \ || echo -e "${RED}failed${NOCOLOR}" fi}function copyfile { [[ "$#" -ne 1 ]] && return 1 echo -en " ${BLUE}$1 ... " cp -f $1 ${CHROOTDIR}$1 \ && echo -e "${GREEN}done${NOCOLOR}" \ || echo -e "${RED}failed${NOCOLOR}"}[ ${UID} != 0 ] && echo -e "${RED}You need to be root to run this !${NOCOLOR}" && exit 1echo -e "${BLUEGREEN}Mouting directories into chroot ... ${NOCOLOR}"mountverify /procmountverify /devmountverify /dev/ptsmountverify /sysmountverify /var/portagemountverify /var/distfilesmountverify /usr/src/linuxmountverify /lib/modulesmountverify /tmpecho -e "${BLUEGREEN}Coping files into chroot ... ${NOCOLOR}"copyfile /etc/resolv.confcopyfile /etc/hostsecho -e "${BLUEGREEN}Chrooting ... ${NOCOLOR}\n"chroot ${CHROOTDIR} /bin/bash