#!/bin/bash CHROOTDIR="/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 [[ $1 == "/proc" ]] \ && local mountcommand="mount -t proc none ${mountpoint}" \ || local mountcommand="mount -o bind $1 ${mountpoint}" ${mountcommand} \ && echo -e "${GREEN}done${NOCOLOR}" \ || echo -e "${RED}failed${NOCOLOR}" fi } [ ${UID} != 0 ] && echo -e "${RED}You need to be root to run this !${NOCOLOR}" && exit 1 echo -e "${BLUEGREEN}Mouting directories into chroot ... ${NOCOLOR}" 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 ... ${NOCOLOR}" cp -f /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf \ && echo -e "${GREEN}done${NOCOLOR}" \ || echo -e "${RED}failed${NOCOLOR}" echo -e "${BLUEGREEN}Chrooting ... ${NOCOLOR}\n" chroot ${CHROOTDIR} /bin/bash