Advertisement
Guest User

build-gentoo-amd64-example.sh

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