Advertisement
Guest User

build-gentoo-amd64-example.sh Update1

a guest
Mar 15th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.17 KB | None | 0 0
  1. #!/bin/bash
  2. # GENTOO INSTALL SCRIPT FROM BASE INSTALL AND DEFAULT CONFIGS
  3. # Created by: Morpheus (YYC)
  4. # Modernized and customized by Charlie Heselton (dataking)
  5. # (C) 2013
  6. #
  7.  
  8. # checks if the environment is proper before chroot'ing
  9. function mount_chk() {
  10.     for M in /dev/sda3 /dev/sda1 proc dev sys; do
  11.         mount | grep "$M" >/dev/null 2>&1
  12.         if [ $? != 0 ]; then
  13.             case $M in
  14.                 /dev/sda3)
  15.                     mount /dev/sda3 /mnt/gentoo;;
  16.                 /dev/sda1)
  17.                     mount /dev/sda1 /mnt/gentoo/boot;;
  18.                 proc)
  19.                     mount -t proc none /mnt/gentoo/proc;;
  20.                 dev)
  21.                     mount --rbind /dev /mnt/gentoo/dev;;
  22.                 sys)
  23.                     mount --rbind /sys /mnt/gentoo/sys;;
  24.                 *)
  25.                     # do nothing
  26.             esac
  27.         fi
  28.     done
  29. }
  30.  
  31. function color(){
  32.     #Set up colors
  33.     NO=$'\x1b[0;0m'
  34.     BR=$'\x1b[0;01m'
  35.     RD=$'\x1b[31;01m' Rd=$'\x1b[00;31m'
  36.     GR=$'\x1b[32;01m' Gr=$'\x1b[00;32m'
  37.     YL=$'\x1b[33;01m' Yl=$'\x1b[00;33m'
  38.     BL=$'\x1b[34;01m' Bl=$'\x1b[00;34m'
  39.     FC=$'\x1b[35;01m' Fc=$'\x1b[00;35m'
  40.     CY=$'\x1b[36;01m' Cy=$'\x1b[00;36m'
  41. }
  42.  
  43. color
  44.  
  45. # Display Introduction
  46. echo "${FC}Welcome to the GENTOO install script, please note you must be at your system for instructions${NO}"
  47. echo "${FC}this script will perform a majority of the configurations for you however certain interaction${NO}"
  48. echo "${FC}may be required on your part.${NO}"
  49. echo
  50.  
  51.  
  52. if [ ! -d crumbs ]; then mkdir -p ${PWD}/crumbs; fi
  53.  
  54. if [ -e crumbs/partitions.done ]; then
  55.     echo "${GN}Partitions already done.${NO}"
  56. else
  57.     echo
  58.     echo "${RD}NOTE: THIS WILL RESULT IN DATA LOSS OF THE CURRENT DRIVE${NO}"
  59.     echo "Please press enter when your ready to continue."
  60.     read
  61.    
  62.     # Configure hard disk
  63.     echo "The following is a list of found Hard Disk devices (sda/hda):"
  64.     ls /dev/ | grep -E [s:h]d[a:b:c]$
  65.     echo
  66.     echo "Please enter the device you would like to install to:"
  67.     read HD_DEVICE
  68.     HDD="/dev/${HD_DEVICE}"
  69.     echo ${HD_DEVICE} >> .harddrive
  70.     #export $HD_DEVICE
  71.  
  72.     # warn user last time
  73.     echo
  74.     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}"
  75.     read
  76.     echo "p" | fdisk $HDD
  77.     echo "Please specifiy the total number of partitions:"
  78.     read PARTS
  79.  
  80.     #TODO: add integer checking
  81.     echo -n "Generating fdisk operation file"
  82.     # Create fdisc auto file
  83.     ((i = 1))
  84.     while (( i < PARTS ))
  85.     do
  86.         echo "d" >> fdisc.in
  87.         echo "$i" >> fdisc.in
  88.         ((i += 1))
  89.     done
  90.     echo "d"    >> fdisc.in # Delete last sector
  91.     echo "n"    >> fdisc.in # New Partiton
  92.     echo "p"    >> fdisc.in # Primary
  93.     echo "1"    >> fdisc.in # Partion 1
  94.     echo ""     >> fdisc.in # default
  95.     echo "+32M"     >> fdisc.in # 32 MB size
  96.     echo "a"    >> fdisc.in # Set flag
  97.     echo "1"    >> fdisc.in # bootable
  98.     echo -n "."
  99.     echo "n"    >> fdisc.in # New Partion
  100.     echo "p"    >> fdisc.in # Primary
  101.     echo "2"    >> fdisc.in # Partion 2
  102.     echo ""     >> fdisc.in # default
  103.     echo "+512M"    >> fdisc.in # 512 MB size
  104.     echo "t"    >> fdisc.in # Set partition type
  105.     echo "2"    >> fdisc.in # Partition 2
  106.     echo "82"   >> fdisc.in # 82 = SWAP
  107.     echo -n "."
  108.     echo "n"    >> fdisc.in # New Partition
  109.     echo "p"    >> fdisc.in # Primary
  110.     echo "3"    >> fdisc.in # Partition 2
  111.     echo ""     >> fdisc.in # default
  112.     echo ""     >> fdisc.in # new Line
  113.     echo -n "."
  114.     echo "w"    >> fdisc.in # Write partion table
  115.     echo "q"    >> fdisc.in # Quit
  116.     echo ". Done"
  117.  
  118.     # Execute file
  119.     echo "Executing fdisk script ..."
  120.     echo
  121.     fdisk $HDD < fdisc.in
  122.  
  123.     #clean up
  124.     rm -f fdisc.in
  125.     touch crumbs/partitions.done
  126. fi
  127.  
  128. if [ -e crumbs/filesystems.done ]; then
  129.     echo "${GN}Filesystems already done.${NO}"
  130. else
  131.     set +x
  132.     HD_DEVICE=`cat .harddrive`
  133.     echo ""
  134.     echo "Partions created"
  135.     echo "Applying filesystem to partitions"
  136.     mke2fs /dev/${HD_DEVICE}1
  137.     mke2fs -j /dev/${HD_DEVICE}3
  138.     mkswap /dev/${HD_DEVICE}2
  139.     echo "Activating swap partition"
  140.     swapon /dev/${HD_DEVICE}2
  141.     touch crumbs/filesystems.done
  142.     set -x
  143. fi
  144.  
  145. if [ -e crumbs/stage3.done ]; then
  146.     echo "${GN}Stage 3 tarball already unpacked.${NO}"
  147. else
  148.     set +x
  149.     HD_DEVICE=`cat .harddrive`
  150.     echo ""
  151.     echo "Mounting partitions"
  152.     mount /dev/${HD_DEVICE}3 /mnt/gentoo
  153.     if [ -d /mnt/gentoo/boot ]; then
  154.         echo "${YL}Boot directory exists.${NO}";
  155.     else
  156.         mkdir /mnt/gentoo/boot
  157.     fi
  158.     mount /dev/${HD_DEVICE}1 /mnt/gentoo/boot
  159.     echo "Starting STAGE 3 Install"
  160.     echo ""
  161.     cd /mnt/gentoo
  162.     wget http://gentoo.netnitco.net/releases/amd64/current-stage3/stage3-amd64-20130130.tar.bz2
  163.     tar xjpf stage3-*.tar.bz2
  164.     cd
  165.     touch crumbs/stage3.done
  166.     set -x
  167. fi
  168.  
  169. if [ -e crumbs/portage.done ]; then
  170.     echo "${GN}Portage tarball already unpacked.${NO}"
  171. else
  172.     echo ""
  173.     echo "Installing portage..."
  174.     cd /mnt/gentoo
  175.     wget http://gentoo.netnitco.net/snapshots/portage-latest.tar.xz
  176.     tar xJf /mnt/gentoo/portage-latest.tar.xz -C /mnt/gentoo/usr
  177.     echo "Cleaning up..."
  178.     rm -f portage-latest.tar.xz
  179.     rm -f stage3-*.tar.bz2
  180.     cd
  181.     touch crumbs/portage.done
  182. fi
  183.  
  184. if [ -e crumbs/chrooted.done ]; then
  185.     echo "${GN}chroot prep already updated.${NO}"
  186.     # still need to reprep the chroot environment
  187.     mount_chk
  188. else
  189.     echo ""
  190.     echo "${GN}Getting ready to CHROOT${NO}"
  191.     cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
  192.     mount -t proc none /mnt/gentoo/proc
  193.     mount --rbind /sys /mnt/gentoo/sys
  194.     mount --rbind /dev /mnt/gentoo/dev
  195.     # FIX ME:  Check the handbook for additional mount points
  196.     echo "Chrooted"
  197.     cd
  198.     touch crumbs/chrooted.done
  199. fi
  200.  
  201. if [ -e crumbs/eselect-profile.done ]; then
  202.     echo "${GN}Profile already selected.${NO}"
  203. else
  204.     mount_chk
  205.     echo "Select your system's profile:"
  206.     chroot /mnt/gentoo eselect profile list
  207.     read PROFILE
  208.     chroot /mnt/gentoo eselect profile set $PROFILE
  209.     cd
  210.     touch crumbs/eselect-profile.done
  211. fi
  212.  
  213. if [ -e crumbs/portage-updated.done ]; then
  214.     echo "${GN}Portage already updated.${NO}"
  215. else
  216.     mount_chk
  217.     echo "${GN}Updating portage...${NO}"
  218.     sleep 2
  219.     chroot /mnt/gentoo emerge --sync
  220.     echo "Patching portage..."
  221.     chroot /mnt/gentoo emerge portage
  222.     echo "Portage updated, downloading kernel source..."
  223.     cd
  224.     touch crumbs/portage-updated.done
  225.     sleep 2
  226. fi
  227.  
  228. if [ -e crumbs/timezone.done ]; then
  229.     echo "${GN}Timezone info already done.${NO}"
  230. else
  231.     mount_chk
  232.     echo "${GN}Updating timezone info.${NO}"
  233.     chroot /mnt/gentoo cp /usr/share/zoneinfo/US/Pacific /etc/localtime
  234.     chroot /mnt/gentoo echo "US/Pacific" >> /etc/timezone
  235.     cd
  236.     touch crumbs/timezone.done
  237. fi
  238.  
  239. if [ -e crumbs/kernel.done ]; then
  240.     echo "${GN}Kernel already compiled.${NO}"
  241. else
  242.     mount_chk
  243.     echo "${GN}Emerging and compiling the kernel.${NO}"
  244.     echo "#!/bin/bash" > /mnt/gentoo/portage
  245.     echo 'USE="-doc symlink" emerge gentoo-sources' >> /mnt/gentoo/portage
  246.     chmod 700 /mnt/gentoo/portage
  247.     chroot /mnt/gentoo ./portage
  248.     rm -f /mnt/gentoo/portage
  249.  
  250.     echo "#!/bin/bash" > /mnt/gentoo/portage
  251.     echo 'cd /usr/src/linux' >> /mnt/gentoo/portage
  252.     echo 'echo ""' >> /mnt/gentoo/portage
  253.     echo 'echo "***************************************************"' >> /mnt/gentoo/portage
  254.     echo 'echo "**            KERNEL CONFIGURATION               **"' >> /mnt/gentoo/portage
  255.     echo 'echo "***************************************************"' >> /mnt/gentoo/portage
  256.     echo 'echo "* You will now be prompted with the linux kernel  *"' >> /mnt/gentoo/portage
  257.     echo 'echo "*menu configurator, please ensure that you specify*"' >> /mnt/gentoo/portage
  258.     echo 'echo "*the right settings, as once you exit this script *"' >> /mnt/gentoo/portage
  259.     echo 'echo "*will compile and install the new kernel          *"' >> /mnt/gentoo/portage
  260.     echo 'echo "***************************************************"' >> /mnt/gentoo/portage
  261.     echo 'echo ""' >> /mnt/gentoo/portage
  262.     echo 'echo "Please press enter to continue"' >> /mnt/gentoo/portage
  263.     echo 'read' >> /mnt/gentoo/portage
  264.     echo 'emerge genkernel' >> /mnt/gentoo/portage
  265.     echo 'genkernel --menuconfig all' >> /mnt/gentoo/portage
  266.     echo 'echo ""' >> /mnt/gentoo/portage
  267.     chmod 700 /mnt/gentoo/portage
  268.     chroot /mnt/gentoo ./portage
  269.     rm -f /mnt/gentoo/portage
  270.     cd
  271.     touch crumbs/kernel.done
  272. fi
  273.  
  274. if [ -e crumbs/fstab.done ]; then
  275.     echo "${GN}fstab already done.${NO}"
  276. else
  277.     echo "${GN}Generating FSTAB${NO}"
  278.     #GENERATE FSTAB
  279.     echo "# /etc/fstab: static file system information." > /mnt/gentoo/etc/fstab
  280.     echo "#" >> /mnt/gentoo/etc/fstab
  281.     echo "# noatime turns off atimes for increased performance (atimes normally aren't" >> /mnt/gentoo/etc/fstab
  282.     echo "# needed; notail increases performance of ReiserFS (at the expense of storage" >> /mnt/gentoo/etc/fstab
  283.     echo "# efficiency).  It's safe to drop the noatime options if you want and to" >> /mnt/gentoo/etc/fstab
  284.     echo "# switch between notail / tail freely." >> /mnt/gentoo/etc/fstab
  285.     echo "#" >> /mnt/gentoo/etc/fstab
  286.     echo "# The root filesystem should have a pass number of either 0 or 1." >> /mnt/gentoo/etc/fstab
  287.     echo "# All other filesystems should have a pass number of 0 or greater than 1." >> /mnt/gentoo/etc/fstab
  288.     echo "#" >> /mnt/gentoo/etc/fstab
  289.     echo "# See the manpage fstab(5) for more information." >> /mnt/gentoo/etc/fstab
  290.     echo "#" >> /mnt/gentoo/etc/fstab
  291.     echo "" >> /mnt/gentoo/etc/fstab
  292.     echo "# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>" >> /mnt/gentoo/etc/fstab
  293.     echo "" >> /mnt/gentoo/etc/fstab
  294.     echo "# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts." >> /mnt/gentoo/etc/fstab
  295.     echo "/dev/${HD_DEVICE}1               /boot           ext2            noauto,noatime  1 2" >> /mnt/gentoo/etc/fstab
  296.     echo "/dev/${HD_DEVICE}3               /               ext3            noatime         0 1" >> /mnt/gentoo/etc/fstab
  297.     echo "/dev/${HD_DEVICE}2               none            swap            sw              0 0" >> /mnt/gentoo/etc/fstab
  298.     echo "#/dev/cdroms/cdrom0      /mnt/cdrom      iso9660         noauto,ro       0 0" >> /mnt/gentoo/etc/fstab
  299.     echo "#/dev/fd0               /mnt/floppy     auto            noauto          0 0" >> /mnt/gentoo/etc/fstab
  300.     echo "" >> /mnt/gentoo/etc/fstab
  301.     echo "# NOTE: The next line is critical for boot!" >> /mnt/gentoo/etc/fstab
  302.     echo "proc                    /proc           proc            defaults        0 0" >> /mnt/gentoo/etc/fstab
  303.     echo "" >> /mnt/gentoo/etc/fstab
  304.     echo "# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for" >> /mnt/gentoo/etc/fstab
  305.     echo "# POSIX shared memory (shm_open, shm_unlink)." >> /mnt/gentoo/etc/fstab
  306.     echo "# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will" >> /mnt/gentoo/etc/fstab
  307.     echo "#  use almost no memory if not populated with files)" >> /mnt/gentoo/etc/fstab
  308.     echo "shm                     /dev/shm        tmpfs           nodev,nosuid,noexec     0 0" >> /mnt/gentoo/etc/fstab
  309.     cat /mnt/gentoo/etc/fstab
  310.     echo ""
  311.     cd
  312.     touch crumbs/fstab.done
  313. fi
  314.  
  315. if [ -e crumbs/initscripts.done ]; then
  316.     echo "${GN}Init scripts already done.${NO}"
  317. else
  318.     mount_chk
  319.     echo "Configuring rc scripts"
  320.     chroot /mnt/gentoo ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
  321.     chroot /mnt/gentoo rc-update add net.eth0 default
  322.     chroot /mnt/gentoo rc-update add sshd default
  323.     echo "*************** ROOT PASSWORD ********************"
  324.     echo "YOU ARE NOW REQUIRED TO ENTER A NEW ROOT PASSWORD "
  325.     echo "**************************************************"
  326.     chroot /mnt/gentoo passwd
  327.     echo "Installing tools..."
  328.     chroot /mnt/gentoo emerge syslog-ng vixie-cron mlocate dhcpcd
  329.     EXIT_STATUS=$?
  330.     if [ $EXIT_STATUS == 0 ]; then
  331.         chroot /mnt/gentoo rc-update add syslog-ng default
  332.         chroot /mnt/gentoo rc-update add vixie-cron default
  333.         chroot /mnt/gentoo rc-update add dhcpcd default
  334.         echo ""
  335.         echo ""
  336.         touch crumbs/initscripts.done
  337.     else
  338.         echo "${RD}There was a problem installing basic tools.${NO}"
  339.         exit $EXIT_STATUS
  340.     fi
  341. fi
  342.  
  343. if [ -e crumbs/fstab-double-check.done ]; then
  344.     echo "${GN}FStab double-check already done.${NO}"
  345. else
  346.     mount_chk
  347.     echo "${YL}You need to double check your /etc/fstab${NO}"
  348.     echo "${YL}before installing grub, because grub will need${NO}"
  349.     echo "${YL}to write some files to /boot.${NO}"
  350.     sleep 15
  351.     chroot /mnt/gentoo nano /etc/fstab
  352.     touch crumbs/fstab-double-check.done
  353. fi
  354.  
  355. if [ -e crumbs/grub.done ]; then
  356.     echo "${GN}Grub installation and configuration already done.${NO}"
  357. else
  358.     mount_chk
  359.     if [ -e crumbs/grub-emerged.done ]; then
  360.         echo "Grub already emerged."
  361.     else
  362.         echo "Emerging GRUB"
  363.         chroot /mnt/gentoo emerge grub
  364.         touch crumbs/grub-emerged.done
  365.     fi
  366.     if [ -e crumbs/grub-installed.done ]; then
  367.         echo "${GN}Grub already installed.${NO}"
  368.     else
  369.         echo "#!/bin/bash" > /mnt/gentoo/grub.sh
  370.         echo "grep -v rootfs /proc/mounts > /etc/mtab" >> /mnt/gentoo/grub.sh
  371.         echo "grub-install --no-floppy /dev/sda" >> /mnt/gentoo/grub.sh
  372.         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
  373.         chmod 700 /mnt/gentoo/grub.sh
  374.         chroot /mnt/gentoo ./grub.sh
  375.         EXIT_STATUS=$?
  376.         if [ $EXIT_STATUS == 0 ]; then
  377.             touch crumbs/grub-installed.done
  378.             touch crumbs/grub.done
  379.         else
  380.             echo "${RD}There was a problem with the grub install${NO}"
  381.         fi
  382.         rm -f /mnt/gentoo/grub.sh
  383.     fi
  384. fi
  385.  
  386.  
  387.  
  388. cd /
  389. umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
  390. echo "Done"
  391. # echo "****************************"
  392. # echo "****************************"
  393. # echo "** SYSTEM WILL NOW REBOOT **"
  394. # echo "****************************"
  395. # echo "****************************"
  396. # sleep 5
  397. # reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement