-
-
Save sorah/3905116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat <<EOF | |
net-setup has been done? | |
"yes" to continue | |
EOF | |
read confirmation | |
[ "$confirmation" == "yes" ] || exit | |
echo "=============== survey" | |
echo -n "root device (empty to sda): " | |
read rootdevice | |
[ "$rootdevice" = "" ] && rootdevice=sda | |
echo -n "distcc hosts (empty to disable): " | |
read distcc_hosts | |
if [ "$distcc_hosts" != "" ]; then | |
echo -n "makeopts (empty to disable): " | |
read distcc_makeopts | |
fi | |
myconfd_dir=`pwd`/myconfd | |
mkdir myconfd | |
echo -n "hostname: " | |
read myhostname | |
cat <<EOF > myconfd/hostname | |
hostname="${myhostname}" | |
EOF | |
cat <<'EOF' > myconfd/net | |
# /etc/conf.d/net | |
# config_eth0="dhcp" | |
# config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" | |
# routes_eth0="default via 192.168.0.1" | |
EOF | |
nano myconfd/net | |
echo -n "modules: " | |
read mymodules | |
cat <<EOF > myconfd/modules | |
modules="${mymodules}" | |
EOF | |
echo "=============== fdisk /dev/sda" | |
fdisk /dev/$rootdevice | |
echo "=============== mkfs" | |
mkfs.ext4 /dev/${rootdevice}1 | |
mkswap /dev/${rootdevice}2 | |
echo "=============== swapon & mount" | |
swapon /dev/${rootdevice}2 | |
mount /dev/${rootdevice}1 /mnt/gentoo | |
echo "=============== downloading tarballs" | |
cd /mnt/gentoo | |
wget 'ftp://ftp.jaist.ac.jp/pub/Linux/Gentoo/releases/amd64/current-stage3/*.tar.bz2' | |
wget 'ftp://ftp.jaist.ac.jp/pub/Linux/Gentoo/snapshots/portage-latest.tar.bz2' | |
echo "=============== unpacking tarballs" | |
tar xjpf stage3-*.tar.bz2 | |
tar xjf portage-latest.tar.bz2 -C /mnt/gentoo/usr | |
echo "=============== make.conf" | |
cat <<EOF >> etc/portage/make.conf | |
GENTOO_MIRRORS="ftp://ftp.iij.ad.jp/pub/linux/gentoo/ http://ftp.iij.ad.jp/pub/linux/gentoo/ http://ftp.jaist.ac.jp/pub/Linux/Gentoo/ ftp://ftp.jaist.ac.jp/pub/Linux/Gentoo/" | |
SYNC="rsync://rsync.jp.gentoo.org/gentoo-portage" | |
EOF | |
nano etc/portage/make.conf | |
echo "=============== fstab" | |
cat <<EOF > etc/fstab | |
/dev/${rootdevice}1 / ext4 defaults,noatime 1 1 | |
/dev/${rootdevice}2 none swap sw 0 0 | |
EOF | |
echo "=============== resolv" | |
cat <<EOF > etc/resolv.conf | |
nameserver 8.8.8.8 | |
nameserver 8.8.4.4 | |
EOF | |
echo "=============== hosts" | |
cat <<EOF > etc/hosts | |
127.0.0.1 ${myhostname} localhost | |
::1 ${myhostname} localhost | |
EOF | |
echo "=============== conf.d" | |
yes|cp -f ${myconfd_dir}/* /mnt/gentoo/etc/conf.d/ | |
echo "============== prepare to chroot" | |
chmod 644 /mnt/gentoo/etc/conf.d/net | |
mount -t proc none /mnt/gentoo/proc | |
mount --rbind /dev /mnt/gentoo/dev | |
export DISTCC_HOSTS="${distcc_hosts}" | |
export DISTCC_MAKEOPTS="${distcc_makeopts}" | |
cat <<'EOF' > /mnt/gentoo/kickstart.sh | |
#!/bin/bash | |
echo "--------------- Landed O_o --------------" | |
env-update | |
source /etc/profile | |
export MAKEOPTS=-j`grep "^processor" /proc/cpuinfo|wc -l` | |
if [ "$DISTCC_HOSTS" != "" ]; then | |
echo "=============== distcc" | |
USE='-*' emerge --nodeps sys-devel/distcc | |
export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}" | |
/usr/bin/distcc-config --set-hosts "$distcc_hosts" | |
export MAKEOPTS="${DISTCC_MAKEOPTS}" | |
fi | |
export CONFIG_PROTECT_MASK="/etc" | |
function autoemerge { | |
emerge --autounmask-write $1 | |
emerge $1 | |
} | |
echo "============== timezone" | |
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime | |
echo "============== flaggie" | |
autoemerge flaggie | |
flaggie vim +ruby +python +perl | |
echo "============== system tools" | |
emerge syslog-ng sudo vixie-cron dhcpcd less | |
rc-update add syslog-ng default | |
rc-update add vixie-cron default | |
rc-update add sshd default | |
echo "============== personal tools" | |
autoemerge zsh | |
autoemerge vim | |
autoemerge git | |
autoemerge tmux | |
autoemerge libyaml | |
autoemerge readline | |
autoemerge libxml2 | |
autoemerge zlib | |
echo "============== useradd sorah" | |
useradd -m -G users,wheel,audio -s /bin/zsh sorah | |
echo "++++++++++++++ dive into sorah, I'll setup it ++++++++++++" | |
sudo -u sorah /userkickstart.sh | |
echo "-------------- back from sorah world ------------" | |
echo "============== gentoo-sources" | |
emerge gentoo-sources | |
echo "============== passwd root" | |
passwd root | |
echo "============== passwd sorah" | |
passwd sorah | |
echo "============== build the kernel" | |
cd /usr/src/linux | |
make localyesconfig | |
make menuconfig | |
make $MAKEOPTS && make $MAKEOPTS modules_install | |
mykernelversion=`make kernelversion` | |
cp arch/x86_64/boot/bzImage "/boot/kernel-${mykernelversion}" | |
echo "============== grub" | |
emerge grub | |
cat <<EOL > /boot/grub/grub.conf | |
default 0 | |
timeout 30 | |
#splashimage=(hd0,0)/boot/grub/splash.xpm.gz | |
title Gentoo linux-${mykernelversion} | |
root (hd0,0) | |
kernel /boot/kernel-${mykernelversion} root=/dev/sda1 | |
title Gentoo linux-${mykernelversion} (rescue) | |
root (hd0,0) | |
kernel /boot/kernel-${mykernelversion} root=/dev/sda1 init=/bin/bb | |
EOL | |
grep -v rootfs /proc/mounts > /etc/mtab | |
grub-install --no-floppy /dev/sda | |
EOF | |
cat <<'EOF' > /mnt/gentoo/userkickstart.sh | |
#!/bin/bash | |
cd /home/sorah | |
echo "---- git/config" | |
mkdir -p git/ruby/foo/{bin,lib} | |
git clone https://github.com/sorah/config.git git/config | |
cd git/config | |
git submodule init | |
git submodule update | |
ln -s `pwd`/vim/dot.vim ~/.vim | |
ln -s `pwd`/vim/dot.vimrc ~/.vimrc | |
ln -s `pwd`/zsh/dot.zshrc ~/.zshrc | |
ln -s `pwd`/zsh/gentoo.zshrc_global_env ~/.zshrc_global_env | |
ln -s `pwd`/tmux/tmux.conf ~/.tmux.conf | |
ln -s `pwd`/misc/dot.irbrc ~/.irbrc | |
ln -s `pwd`/misc/dot.gemrc ~/.gemrc | |
cat <<'EOL' > /home/sorah/.tmux.reattacher | |
#!/bin/sh | |
exec $* | |
EOL | |
chmod +x /home/sorah/.tmux.reattacher | |
echo "---- rbenv" | |
cd /home/sorah | |
git clone https://github.com/sstephenson/rbenv.git .rbenv | |
mkdir -p .rbenv/plugins | |
git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build | |
export PATH="$HOME/.rbenv/bin:$PATH" | |
eval "$(rbenv init -)" | |
rbenv install 1.9.3-p286 | |
rbenv global 1.9.3-p286 | |
gem install bundler | |
echo "---- ssh key" | |
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3Bb9RazVPPBOsJDDrzuwHXkdtopM9ySp0n9J2PCGaZzwWxsuK/c/8YICGvYbH49nzcmwsli8OzvOPDFry2isGxWhk8kc9uz2C771d/1ZisCVN8bn0PqFFb9zm2/iYaXNXjEyyZNhidknGbMEQPL9oH8tV7IRRlKlfe5c/WCO7QysKoM2L8CAPw4o6HSJcJR9F8GAH+t5N8GKZksE++MlZ2VBahfPx2xkkA6gzo5uxO37hkLzOwdkpZEorYcymjmUG6g7jJ9c0Y4bdmccKmVMNyZsJGLc8ScGtkXm2+KKkEj8k+48bHBR3B1DrObE4CRRJCBErXzuz5pnqPrgDHizYQ== sorah@americano.local" > /home/sorah/.ssh/authorized_keys | |
chmod 644 /home/sorah/.ssh/authorized_keys | |
EOF | |
chmod +x /mnt/gentoo/kickstart.sh | |
chmod +x /mnt/gentoo/userkickstart.sh | |
echo "+++++++++++++++ WOooo, time to fly into new Gentoo World ++++++++++++++" | |
chroot /mnt/gentoo /bin/bash /kickstart.sh | |
echo "... whew, all done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment