Skip to content

Instantly share code, notes, and snippets.

@b333z
Last active August 29, 2015 14:19
Show Gist options
  • Save b333z/7d89f02536d619d42353 to your computer and use it in GitHub Desktop.
Save b333z/7d89f02536d619d42353 to your computer and use it in GitHub Desktop.
gentoo scripts
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
function chroot()
{
CHROOT_ROOT=$1
echo "Chrooting to $CHROOT_ROOT"
echo "Mounting filesytems"
mount /boot 2> /dev/null
mount -t proc none $CHROOT_ROOT/proc
mount -o bind /dev $CHROOT_ROOT/dev
mount -o bind /dev/pts $CHROOT_ROOT/dev/pts
mount -o bind /systems $CHROOT_ROOT/systems
mount -o bind /boot $CHROOT_ROOT/boot
mount -o bind /usr/portage $CHROOT_ROOT/usr/portage
mount -o bind /usr/portage/distfiles $CHROOT_ROOT/usr/portage/distfiles
mount -o bind /tmp $CHROOT_ROOT/tmp
cp $DIR/gentoo-chroot.init $CHROOT_ROOT/tmp
sed -i "s%chrootlabel%chroot:$CHROOT_ROOT%g" $CHROOT_ROOT/tmp/gentoo-chroot.init
echo "Setting disk priority to idle..."
ionice -c3 -p $$ | sed 's/^/ /'
echo "Setting cpu priority to low..."
renice -n 20 -p $$ | sed 's/^/ /'
echo "Entering chroot..."
/usr/bin/chroot $CHROOT_ROOT /bin/bash --rcfile /tmp/gentoo-chroot.init
echo "Exiting chroot."
sleep 3
umount $CHROOT_ROOT/tmp
umount $CHROOT_ROOT/usr/portage/distfiles
umount $CHROOT_ROOT/usr/portage
umount $CHROOT_ROOT/boot
umount $CHROOT_ROOT/dev/pts
umount $CHROOT_ROOT/dev
umount $CHROOT_ROOT/proc
}
chroot "$@"
# /etc/skel/.bashrc:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/skel/.bashrc,v 1.8 2003/02/28 15:45:35 azarah Exp $
# This file is sourced by all *interactive* bash shells on startup. This
# file *should generate no output* or it will break the scp and rcp commands.
# Colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
#alias d="ls --color"
#alias ls="ls --color=auto"
#alias ll="ls --color -l"
# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
;;
esac
## Uncomment the following to activate bash-completion:
[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion
## Set up environment when su'ed to root:
[ -f /etc/profile ] && source /etc/profile
env-update
. /etc/profile
export PS1="(chrootlabel) $PS1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment