Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # GENTOO INSTALL SCRIPT FROM BASE INSTALL AND DEFAULT CONFIGS
- # Created by: Morpheus (YYC)
- # Modernized and customized by Charlie Heselton (dataking)
- # (C) 2013
- #
- # checks if the environment is proper before chroot'ing
- function mount_chk() {
- for M in /dev/sda3 /dev/sda1 proc dev sys; do
- mount | grep "$M" >/dev/null 2>&1
- if [ $? != 0 ]; then
- case $M in
- /dev/sda3)
- mount /dev/sda3 /mnt/gentoo;;
- /dev/sda1)
- mount /dev/sda1 /mnt/gentoo/boot;;
- proc)
- mount -t proc none /mnt/gentoo/proc;;
- dev)
- mount --rbind /dev /mnt/gentoo/dev;;
- sys)
- mount --rbind /sys /mnt/gentoo/sys;;
- *)
- # do nothing
- esac
- fi
- done
- }
- function color(){
- #Set up colors
- NO=$'\x1b[0;0m'
- BR=$'\x1b[0;01m'
- RD=$'\x1b[31;01m' Rd=$'\x1b[00;31m'
- GR=$'\x1b[32;01m' Gr=$'\x1b[00;32m'
- YL=$'\x1b[33;01m' Yl=$'\x1b[00;33m'
- BL=$'\x1b[34;01m' Bl=$'\x1b[00;34m'
- FC=$'\x1b[35;01m' Fc=$'\x1b[00;35m'
- CY=$'\x1b[36;01m' Cy=$'\x1b[00;36m'
- }
- color
- # Display Introduction
- echo "${FC}Welcome to the GENTOO install script, please note you must be at your system for instructions${NO}"
- echo "${FC}this script will perform a majority of the configurations for you however certain interaction${NO}"
- echo "${FC}may be required on your part.${NO}"
- echo
- if [ ! -d crumbs ]; then mkdir -p ${PWD}/crumbs; fi
- if [ -e crumbs/partitions.done ]; then
- echo "${GN}Partitions already done.${NO}"
- else
- echo
- echo "${RD}NOTE: THIS WILL RESULT IN DATA LOSS OF THE CURRENT DRIVE${NO}"
- echo "Please press enter when your ready to continue."
- read
- # Configure hard disk
- echo "The following is a list of found Hard Disk devices (sda/hda):"
- ls /dev/ | grep -E [s:h]d[a:b:c]$
- echo
- echo "Please enter the device you would like to install to:"
- read HD_DEVICE
- HDD="/dev/${HD_DEVICE}"
- echo ${HD_DEVICE} >> .harddrive
- #export $HD_DEVICE
- # warn user last time
- echo
- echo "${RD}THIS IS YOUR LAST CHANCE TO CANCEL, Press ${NO}CTRL+C${RD} to cancel this install or ${NO}ENTER${RD} to continue${NO}"
- read
- echo "p" | fdisk $HDD
- echo "Please specifiy the total number of partitions:"
- read PARTS
- #TODO: add integer checking
- echo -n "Generating fdisk operation file"
- # Create fdisc auto file
- ((i = 1))
- while (( i < PARTS ))
- do
- echo "d" >> fdisc.in
- echo "$i" >> fdisc.in
- ((i += 1))
- done
- echo "d" >> fdisc.in # Delete last sector
- echo "n" >> fdisc.in # New Partiton
- echo "p" >> fdisc.in # Primary
- echo "1" >> fdisc.in # Partion 1
- echo "" >> fdisc.in # default
- echo "+32M" >> fdisc.in # 32 MB size
- echo "a" >> fdisc.in # Set flag
- echo "1" >> fdisc.in # bootable
- echo -n "."
- echo "n" >> fdisc.in # New Partion
- echo "p" >> fdisc.in # Primary
- echo "2" >> fdisc.in # Partion 2
- echo "" >> fdisc.in # default
- echo "+512M" >> fdisc.in # 512 MB size
- echo "t" >> fdisc.in # Set partition type
- echo "2" >> fdisc.in # Partition 2
- echo "82" >> fdisc.in # 82 = SWAP
- echo -n "."
- echo "n" >> fdisc.in # New Partition
- echo "p" >> fdisc.in # Primary
- echo "3" >> fdisc.in # Partition 2
- echo "" >> fdisc.in # default
- echo "" >> fdisc.in # new Line
- echo -n "."
- echo "w" >> fdisc.in # Write partion table
- echo "q" >> fdisc.in # Quit
- echo ". Done"
- # Execute file
- echo "Executing fdisk script ..."
- echo
- fdisk $HDD < fdisc.in
- #clean up
- rm -f fdisc.in
- touch crumbs/partitions.done
- fi
- if [ -e crumbs/filesystems.done ]; then
- echo "${GN}Filesystems already done.${NO}"
- else
- set +x
- HD_DEVICE=`cat .harddrive`
- echo ""
- echo "Partions created"
- echo "Applying filesystem to partitions"
- mke2fs /dev/${HD_DEVICE}1
- mke2fs -j /dev/${HD_DEVICE}3
- mkswap /dev/${HD_DEVICE}2
- echo "Activating swap partition"
- swapon /dev/${HD_DEVICE}2
- touch crumbs/filesystems.done
- set -x
- fi
- if [ -e crumbs/stage3.done ]; then
- echo "${GN}Stage 3 tarball already unpacked.${NO}"
- else
- set +x
- HD_DEVICE=`cat .harddrive`
- echo ""
- echo "Mounting partitions"
- mount /dev/${HD_DEVICE}3 /mnt/gentoo
- if [ -d /mnt/gentoo/boot ]; then
- echo "${YL}Boot directory exists.${NO}";
- else
- mkdir /mnt/gentoo/boot
- fi
- mount /dev/${HD_DEVICE}1 /mnt/gentoo/boot
- echo "Starting STAGE 3 Install"
- echo ""
- cd /mnt/gentoo
- wget http://gentoo.netnitco.net/releases/amd64/current-stage3/stage3-amd64-20130130.tar.bz2
- tar xjpf stage3-*.tar.bz2
- cd
- touch crumbs/stage3.done
- set -x
- fi
- if [ -e crumbs/portage.done ]; then
- echo "${GN}Portage tarball already unpacked.${NO}"
- else
- echo ""
- echo "Installing portage..."
- cd /mnt/gentoo
- wget http://gentoo.netnitco.net/snapshots/portage-latest.tar.xz
- tar xJf /mnt/gentoo/portage-latest.tar.xz -C /mnt/gentoo/usr
- echo "Cleaning up..."
- rm -f portage-latest.tar.xz
- rm -f stage3-*.tar.bz2
- cd
- touch crumbs/portage.done
- fi
- if [ -e crumbs/chrooted.done ]; then
- echo "${GN}chroot prep already updated.${NO}"
- # still need to reprep the chroot environment
- mount_chk
- else
- echo ""
- echo "${GN}Getting ready to CHROOT${NO}"
- cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
- mount -t proc none /mnt/gentoo/proc
- mount --rbind /sys /mnt/gentoo/sys
- mount --rbind /dev /mnt/gentoo/dev
- # FIX ME: Check the handbook for additional mount points
- echo "Chrooted"
- cd
- touch crumbs/chrooted.done
- fi
- if [ -e crumbs/eselect-profile.done ]; then
- echo "${GN}Profile already selected.${NO}"
- else
- mount_chk
- echo "Select your system's profile:"
- chroot /mnt/gentoo eselect profile list
- read PROFILE
- chroot /mnt/gentoo eselect profile set $PROFILE
- cd
- touch crumbs/eselect-profile.done
- fi
- if [ -e crumbs/portage-updated.done ]; then
- echo "${GN}Portage already updated.${NO}"
- else
- mount_chk
- echo "${GN}Updating portage...${NO}"
- sleep 2
- chroot /mnt/gentoo emerge --sync
- echo "Patching portage..."
- chroot /mnt/gentoo emerge portage
- echo "Portage updated, downloading kernel source..."
- cd
- touch crumbs/portage-updated.done
- sleep 2
- fi
- if [ -e crumbs/timezone.done ]; then
- echo "${GN}Timezone info already done.${NO}"
- else
- mount_chk
- echo "${GN}Updating timezone info.${NO}"
- chroot /mnt/gentoo cp /usr/share/zoneinfo/US/Pacific /etc/localtime
- chroot /mnt/gentoo echo "US/Pacific" >> /etc/timezone
- cd
- touch crumbs/timezone.done
- fi
- if [ -e crumbs/kernel.done ]; then
- echo "${GN}Kernel already compiled.${NO}"
- else
- mount_chk
- echo "${GN}Emerging and compiling the kernel.${NO}"
- echo "#!/bin/bash" > /mnt/gentoo/portage
- echo 'USE="-doc symlink" emerge gentoo-sources' >> /mnt/gentoo/portage
- chmod 700 /mnt/gentoo/portage
- chroot /mnt/gentoo ./portage
- rm -f /mnt/gentoo/portage
- echo "#!/bin/bash" > /mnt/gentoo/portage
- echo 'cd /usr/src/linux' >> /mnt/gentoo/portage
- echo 'echo ""' >> /mnt/gentoo/portage
- echo 'echo "***************************************************"' >> /mnt/gentoo/portage
- echo 'echo "** KERNEL CONFIGURATION **"' >> /mnt/gentoo/portage
- echo 'echo "***************************************************"' >> /mnt/gentoo/portage
- echo 'echo "* You will now be prompted with the linux kernel *"' >> /mnt/gentoo/portage
- echo 'echo "*menu configurator, please ensure that you specify*"' >> /mnt/gentoo/portage
- echo 'echo "*the right settings, as once you exit this script *"' >> /mnt/gentoo/portage
- echo 'echo "*will compile and install the new kernel *"' >> /mnt/gentoo/portage
- echo 'echo "***************************************************"' >> /mnt/gentoo/portage
- echo 'echo ""' >> /mnt/gentoo/portage
- echo 'echo "Please press enter to continue"' >> /mnt/gentoo/portage
- echo 'read' >> /mnt/gentoo/portage
- echo 'emerge genkernel' >> /mnt/gentoo/portage
- echo 'genkernel --menuconfig all' >> /mnt/gentoo/portage
- echo 'echo ""' >> /mnt/gentoo/portage
- chmod 700 /mnt/gentoo/portage
- chroot /mnt/gentoo ./portage
- rm -f /mnt/gentoo/portage
- cd
- touch crumbs/kernel.done
- fi
- if [ -e crumbs/fstab.done ]; then
- echo "${GN}fstab already done.${NO}"
- else
- echo "${GN}Generating FSTAB${NO}"
- #GENERATE FSTAB
- echo "# /etc/fstab: static file system information." > /mnt/gentoo/etc/fstab
- echo "#" >> /mnt/gentoo/etc/fstab
- echo "# noatime turns off atimes for increased performance (atimes normally aren't" >> /mnt/gentoo/etc/fstab
- echo "# needed; notail increases performance of ReiserFS (at the expense of storage" >> /mnt/gentoo/etc/fstab
- echo "# efficiency). It's safe to drop the noatime options if you want and to" >> /mnt/gentoo/etc/fstab
- echo "# switch between notail / tail freely." >> /mnt/gentoo/etc/fstab
- echo "#" >> /mnt/gentoo/etc/fstab
- echo "# The root filesystem should have a pass number of either 0 or 1." >> /mnt/gentoo/etc/fstab
- echo "# All other filesystems should have a pass number of 0 or greater than 1." >> /mnt/gentoo/etc/fstab
- echo "#" >> /mnt/gentoo/etc/fstab
- echo "# See the manpage fstab(5) for more information." >> /mnt/gentoo/etc/fstab
- echo "#" >> /mnt/gentoo/etc/fstab
- echo "" >> /mnt/gentoo/etc/fstab
- echo "# <fs> <mountpoint> <type> <opts> <dump/pass>" >> /mnt/gentoo/etc/fstab
- echo "" >> /mnt/gentoo/etc/fstab
- echo "# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts." >> /mnt/gentoo/etc/fstab
- echo "/dev/${HD_DEVICE}1 /boot ext2 noauto,noatime 1 2" >> /mnt/gentoo/etc/fstab
- echo "/dev/${HD_DEVICE}3 / ext3 noatime 0 1" >> /mnt/gentoo/etc/fstab
- echo "/dev/${HD_DEVICE}2 none swap sw 0 0" >> /mnt/gentoo/etc/fstab
- echo "#/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0" >> /mnt/gentoo/etc/fstab
- echo "#/dev/fd0 /mnt/floppy auto noauto 0 0" >> /mnt/gentoo/etc/fstab
- echo "" >> /mnt/gentoo/etc/fstab
- echo "# NOTE: The next line is critical for boot!" >> /mnt/gentoo/etc/fstab
- echo "proc /proc proc defaults 0 0" >> /mnt/gentoo/etc/fstab
- echo "" >> /mnt/gentoo/etc/fstab
- echo "# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for" >> /mnt/gentoo/etc/fstab
- echo "# POSIX shared memory (shm_open, shm_unlink)." >> /mnt/gentoo/etc/fstab
- echo "# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will" >> /mnt/gentoo/etc/fstab
- echo "# use almost no memory if not populated with files)" >> /mnt/gentoo/etc/fstab
- echo "shm /dev/shm tmpfs nodev,nosuid,noexec 0 0" >> /mnt/gentoo/etc/fstab
- cat /mnt/gentoo/etc/fstab
- echo ""
- cd
- touch crumbs/fstab.done
- fi
- if [ -e crumbs/initscripts.done ]; then
- echo "${GN}Init scripts already done.${NO}"
- else
- mount_chk
- echo "Configuring rc scripts"
- chroot /mnt/gentoo ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
- chroot /mnt/gentoo rc-update add net.eth0 default
- chroot /mnt/gentoo rc-update add sshd default
- echo "*************** ROOT PASSWORD ********************"
- echo "YOU ARE NOW REQUIRED TO ENTER A NEW ROOT PASSWORD "
- echo "**************************************************"
- chroot /mnt/gentoo passwd
- echo "Installing tools..."
- chroot /mnt/gentoo emerge syslog-ng vixie-cron mlocate dhcpcd
- EXIT_STATUS=$?
- if [ $EXIT_STATUS == 0 ]; then
- chroot /mnt/gentoo rc-update add syslog-ng default
- chroot /mnt/gentoo rc-update add vixie-cron default
- chroot /mnt/gentoo rc-update add dhcpcd default
- echo ""
- echo ""
- touch crumbs/initscripts.done
- else
- echo "${RD}There was a problem installing basic tools.${NO}"
- exit $EXIT_STATUS
- fi
- fi
- if [ -e crumbs/fstab-double-check.done ]; then
- echo "${GN}FStab double-check already done.${NO}"
- else
- mount_chk
- echo "${YL}You need to double check your /etc/fstab${NO}"
- echo "${YL}before installing grub, because grub will need${NO}"
- echo "${YL}to write some files to /boot.${NO}"
- sleep 15
- chroot /mnt/gentoo nano /etc/fstab
- touch crumbs/fstab-double-check.done
- fi
- if [ -e crumbs/grub.done ]; then
- echo "${GN}Grub installation and configuration already done.${NO}"
- else
- mount_chk
- if [ -e crumbs/grub-emerged.done ]; then
- echo "Grub already emerged."
- else
- echo "Emerging GRUB"
- chroot /mnt/gentoo emerge grub
- touch crumbs/grub-emerged.done
- fi
- if [ -e crumbs/grub-installed.done ]; then
- echo "${GN}Grub already installed.${NO}"
- else
- echo "#!/bin/bash" > /mnt/gentoo/grub.sh
- echo "grep -v rootfs /proc/mounts > /etc/mtab" >> /mnt/gentoo/grub.sh
- echo "grub-install --no-floppy /dev/sda" >> /mnt/gentoo/grub.sh
- echo "sed -i.bak -e 's/2.6.24-r5/3.7.10/' -e 's/2.6.24-gentoo-r5/3.7.10-gentoo/' -e 's/^#\\(\\w.*\\)/\\1/' -e 's/x86/x86_64/' /boot/grub/grub.conf" >> /mnt/gentoo/grub.sh
- chmod 700 /mnt/gentoo/grub.sh
- chroot /mnt/gentoo ./grub.sh
- EXIT_STATUS=$?
- if [ $EXIT_STATUS == 0 ]; then
- touch crumbs/grub-installed.done
- touch crumbs/grub.done
- else
- echo "${RD}There was a problem with the grub install${NO}"
- fi
- rm -f /mnt/gentoo/grub.sh
- fi
- fi
- cd /
- umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
- echo "Done"
- # echo "****************************"
- # echo "****************************"
- # echo "** SYSTEM WILL NOW REBOOT **"
- # echo "****************************"
- # echo "****************************"
- # sleep 5
- # reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement