#!/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 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 1 echo -e "${BLUEGREEN}Mouting directories into chroot ... ${NOCOLOR}" mountverify /proc mountverify /dev mountverify /dev/pts mountverify /sys mountverify /var/portage mountverify /var/distfiles mountverify /usr/src/linux mountverify /lib/modules mountverify /tmp echo -e "${BLUEGREEN}Coping files into chroot ... ${NOCOLOR}" copyfile /etc/resolv.conf copyfile /etc/hosts echo -e "${BLUEGREEN}Chrooting ... ${NOCOLOR}\n" chroot ${CHROOTDIR} /bin/bash