Guest User

gentoo install script part 1

a guest
Oct 30th, 2024
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.60 KB | Software | 0 0
  1. #!/bin/bash
  2. # gentoo install script -- akira2501 -- 2012 -- for the public domain
  3. PATH="/sbin:/usr/sbin:/bin:/usr/bin"
  4.  
  5. GENTOO_MIRRORS="http://distfiles.gentoo.org/"
  6. I_MIRROR="http://distfiles.gentoo.org/"
  7.  
  8. export LANG=en_US.UTF-8
  9. export LANGUAGE=${LANG}
  10. export LC_COLLATE=C
  11.  
  12. shopt -s expand_aliases
  13. alias dialog="dialog --stdout"
  14.  
  15. ## check pre-requisites
  16. READY=1
  17.  
  18. ## ensure the user has mounted a boot filesystem if we are on efi
  19. if [[ -d /sys/firmware/efi ]]; then
  20.     grep /mnt/gentoo/boot /proc/mounts 1>/dev/null 2>&1
  21.    
  22.     if [[ $? != 0 ]]; then
  23.         echo "* please mount your EFI boot partition under /mnt/gentoo/boot"
  24.         echo "* create a 256MiB vfat32 filesystem for grub EFI:"
  25.         echo "= mkfs.vfat -F32 dev"
  26.         echo
  27.         READY=0
  28.     fi
  29. fi
  30.  
  31. ## ensure the user has mounted some block device to install into
  32. grep /mnt/gentoo /proc/mounts 1>/dev/null 2>&1
  33. if [[ $? != 0 ]]; then
  34.     echo "* please mount your installation target partiton(s) under /mnt/gentoo"
  35.     echo "* create filesystem and swap partitions:"
  36.     echo "= mke2fs -v -m0 -j -O dir_index,sparse_super,uninit_bg,extents,filetype dev"
  37.     echo
  38.     READY=0
  39. fi
  40.  
  41. ## ensure we are ready to proceed
  42. if [[ "$READY" != "1" ]]; then
  43.     exit
  44. fi
  45.  
  46. ## select architecture and processor (amd64, x86, etc...)
  47. while [[ "$I_ARCH" == "" ]]; do
  48.     I_ARCH=$(dialog --menu 'Select Architecture' 0 0 0 amd64 '64-bit Intel/AMD' x86 '32-bit Intel/AMD')
  49.    
  50.     if [[ "$I_ARCH" == "amd64" ]]; then
  51.         I_PROC="amd64"
  52.         I_HOST="x86_64-pc-linux-gnu"
  53.     elif [[ "$I_ARCH" == "x86" ]]; then
  54.         while [[ "$I_PROC" == "" ]]; do
  55.             I_PROC=$(dialog --menu 'Select Processor Family' 0 0 0 i486 'i486 Intel/AMD' i686 'Pentium Intel/AMD')
  56.         done
  57.         I_HOST="${I_PROC}-pc-linux-gnu"
  58.     else
  59.         I_PROC=""
  60.         I_ARCH=""
  61.         I_HOST=""
  62.     fi
  63. done
  64.  
  65. ## main menu methods
  66. dcommand() {
  67.     eval "$2" 2>&1 | dialog --programbox "$1" -1 -1
  68. }
  69.  
  70. C_MENU=('' '' '' '' '' '' '' '' '')
  71. D_MENU=(
  72.     'Quit'
  73.     'Set Time and Date'
  74.     'Set Gentoo Mirror'
  75.     'Install Gentoo System'
  76.     'Install Portage Snapshot'
  77.     'Install Bundled Portage Tree'
  78.     'Install Linux Kernel'
  79.     'Setup Gentoo System'
  80.     'Start Chroot Environment'
  81. )
  82.  
  83. # Quit
  84. menu0() {
  85.     rm -f /mnt/gentoo/root/{.gentoo-chroot-install,dialog,libdialog.so}*
  86.     exit
  87. }
  88.  
  89. # Set Time and Date
  90. menu1() {
  91.     dcommand "Using NTPD to get current time:" "ntpd -q"
  92.     C_MENU[1]="*DONE*"
  93. }
  94.  
  95. # Set Gentoo Mirror
  96. menu2() {
  97.     I_MENU=""
  98.     I_MENU=$(dialog --menu 'Gentoo Mirror Selection Method' 0 0 0   \
  99.         1 'Interactively Select Mirror'             \
  100.         2 'Automatically Determine Mirror'          \
  101.         3 'Manually Set Mirror Variable'            )
  102.        
  103.     if [[ "$I_MENU" == "1" ]]; then
  104.         eval `mirrorselect -i -4 -H -o`
  105.     elif [[ "$I_MENU" == "2" ]]; then
  106.         eval `mirrorselect -s1 -4 -H -o`
  107.     elif [[ "$I_MENU" == "3" ]]; then
  108.         GENTOO_MIRRORS=$(dialog --inputbox 'GENTOO_MIRRORS=' 0 -1 "$GENTOO_MIRRORS")
  109.     fi
  110.    
  111.     I_MIRROR=`echo "$GENTOO_MIRRORS" | cut -d' ' -f1`
  112.     if [[ "${I_MIRROR: -1}" != "/" ]]; then
  113.         I_MIRROR="${I_MIRROR}/"
  114.     fi
  115.    
  116.     C_MENU[2]="*DONE*"
  117. }
  118.  
  119. # Install Gentoo System
  120. menu3() {
  121.     echo "* downloading list of gentoo ${I_ARCH} stage3 tarballs.."
  122.    
  123.     R_STAGE=${I_MIRROR}releases/${I_ARCH}/autobuilds/
  124.     T_STAGE=$(mktemp -d)
  125.     (
  126.         cd $T_STAGE
  127.         wget --quiet -r -l 1 -nd -np --accept-regex "latest-stage3.*${I_PROC}.*\.txt$" ${R_STAGE}
  128.     )
  129.    
  130.     I_STAGE=$(dialog --no-items --menu 'Choose Stage3 Tarball' 0 0 0 $(cat $T_STAGE/*.txt | grep -v '^#' | sort | uniq | cut -d' ' -f1))
  131.     rm -rf $T_STAGE
  132.  
  133.     if [[ "$I_STAGE" != "" ]]; then
  134.         dcommand "Download and Install Stage3 Tarball" "wget -O- ${R_STAGE}${I_STAGE} | tar xJfp - -C /mnt/gentoo"
  135.         C_MENU[3]="*DONE*"
  136.     fi
  137. }
  138.  
  139. # Install Portage Snapshot
  140. menu4() {
  141.     dcommand "Download and Install Latest Portage Snapshot" "wget -O- ${I_MIRROR}snapshots/portage-latest.tar.bz2 | tar xjfp - -C /mnt/gentoo/usr"
  142.     C_MENU[4]="*DONE*"
  143. }
  144.  
  145. # Install Bundled Portage Add Ons
  146. menu5() {
  147.     dcommand "Install Bundled Portage Add Ons" "tail -c $EMBED_TAR_SIZE $0 | tar xjf - -C /mnt/gentoo/usr/local"
  148.     C_MENU[5]="*DONE*"
  149. }
  150.  
  151. # Install Linux Kernel
  152. menu6() {
  153.     echo "* downloading list of available kernels"
  154.    
  155.     U_KERNEL=$(dialog --no-items --menu 'Choose Linux Kernel' 0 0 0 $(
  156.         wget --quiet -O- https://www.kernel.org/releases.json | grep '"source"' | grep "tar.xz" | awk -F '"' '{print $4}'
  157.     ))
  158.    
  159.     if [[ "$U_KERNEL" != "" ]]; then
  160.         P_KERNEL=$(basename $U_KERNEL .tar.xz)
  161.        
  162.         dcommand "Download and Install Latest Linux Kernel" \
  163.             "wget -O- ${U_KERNEL} | tee /mnt/gentoo/usr/src/${P_KERNEL}.tar.xz | tar xfJ - -C /mnt/gentoo/usr/src"
  164.            
  165.         (
  166.             cd /mnt/gentoo/usr/src
  167.             ln -s ${P_KERNEL} linux
  168.             echo $(cut -d'-' -f2 <<< $P_KERNEL) > linux/.i_kernel
  169.         )
  170.         C_MENU[6]="*DONE*"
  171.     fi
  172. }
  173.  
  174. # Setup Gentoo System
  175. menu7() {
  176.     echo "* creating fstab"
  177.     FSTAB="/mnt/gentoo/etc/fstab"
  178.    
  179.     printf "%-15s %-15s %-15s %-23s s\n" "device" "mount" "type" "options" "dump/order" > $FSTAB
  180.    
  181.     cut -d' ' -f1-3 /proc/mounts | while read xdev xmnt xfst; do
  182.         # only real devices that are currently mounted in /mnt/gentoo
  183.         if [[ "${xdev:0:5}" != "/dev/" ]] || [[ "${xmnt:0:11}" != "/mnt/gentoo" ]]; then
  184.             continue
  185.         fi
  186.        
  187.         # remove /mnt/gentoo from start of mount path then determine pass order
  188.         xmnt=${xmnt:11}
  189.         [[ "$xmnt" == "/" ]] && xpas=1 || xpas=2
  190.        
  191.         printf "%-15s %-15s %-15s %-23s 0 %d\n" $xdev $xmnt $xfst "defaults" $xpas  >> $FSTAB
  192.     done
  193.     echo                                            >> $FSTAB
  194.     swapon -s | grep partition | cut -d' ' -f1 | while read xdev; do
  195.         printf "%-15s %-15s %-15s %-23s 0 0\n" $xdev "none" "swap" "defaults"       >> $FSTAB
  196.     done
  197.     echo                                            >> $FSTAB
  198.     echo "shm             /dev/shm        tmpfs           nodev,nosuid,noexec     0 0"  >> $FSTAB
  199.     echo "devpts          /dev/pts        devpts          gid=5,mode=0620         0 0"  >> $FSTAB
  200.     echo "proc            /proc           proc            defaults                0 0"  >> $FSTAB
  201.     echo "sysfs           /sys            sysfs           defaults                0 0"  >> $FSTAB
  202.  
  203.     # create make.conf
  204.     MCORES=$(grep processor /proc/cpuinfo | wc -l)
  205.    
  206.     MFLAGS=""
  207.     RFLAGS=$(grep -e '^flags' /proc/cpuinfo | head -1)
  208.    
  209.     for x in 3dnow 3dnowext aes avx avx2 f16c fma fma3 fma4 mmx mmxext pclmul popcnt sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 xop; do
  210.         [[ "$RFLAGS" == *" ${x}"* ]] && MFLAGS="${MFLAGS} ${x}"
  211.     done
  212.    
  213.     echo "* creating make.conf"
  214.     MAKE="/mnt/gentoo/etc/portage/make.conf"
  215.  
  216.     echo "CHOST=\"${I_HOST}\""                           > $MAKE
  217.     echo                                        >> $MAKE
  218.     echo "CFLAGS=\"-O2 -march=native -fomit-frame-pointer -pipe\""          >> $MAKE
  219.     echo "CXXFLAGS=\"\${CFLAGS}\""                          >> $MAKE
  220.     echo                                        >> $MAKE   
  221.     echo "CPU_FLAGS_X86=\"${MFLAGS}\""                      >> $MAKE
  222.     echo                                        >> $MAKE
  223.     echo "ACCEPT_KEYWORDS=\"${I_ARCH} ~${I_ARCH}\""                 >> $MAKE
  224.     echo "FEATURES=\"nodoc clean-logs parallel-fetch\""             >> $MAKE
  225.     echo "MAKEOPTS=\"-j${MCORES}\""                         >> $MAKE
  226.     echo                                        >> $MAKE
  227.     echo "USE=\""                                   >> $MAKE
  228.     echo -e "\tdjbfft fftw"                             >> $MAKE
  229.     echo -e "\tacpi acl caps maildir mmap glibc-omitfp threads dvd dvdr dvdread"    >> $MAKE
  230.     echo -e "\tlm_sensors sql vnc rdp pdf qt3support"               >> $MAKE
  231.     echo -e "\treadline libedit python ruby sqlite3"                >> $MAKE
  232.     echo -e "\tpam spell curl expat xml zlib bzip2 lzo lzma cdb crypt icu"      >> $MAKE
  233.     echo -e "\tsdl gif jpeg jbig jpeg2k png pnm tiff svg exif"          >> $MAKE
  234.     echo -e "\tX xv xvmc truetype cairo qt4 gtk xscreensaver nsplugin"      >> $MAKE
  235.     echo -e "\topengl avi mpeg ffmpeg theora real dirac x264 dv xvid"       >> $MAKE
  236.     echo -e "\talsa ogg a52 aac audiofile lame mad sox openal vorbis dts"       >> $MAKE
  237.     echo -e "\tjack speex flac mp2 mp3 faac faad"                   >> $MAKE
  238.     echo -e "\t-tcpd -dbus -openrc -redistributable"                >> $MAKE
  239.     echo "\""                                   >> $MAKE                                                                                
  240.     echo                                        >> $MAKE
  241.     echo "PORTDIR_OVERLAY=\"/usr/local/portage\""                   >> $MAKE
  242.     echo "PORTDIR=\"/usr/portage\""                         >> $MAKE
  243.     echo                                        >> $MAKE
  244.     echo "GENTOO_MIRRORS=\"${GENTOO_MIRRORS}\""                     >> $MAKE
  245.     echo                                        >> $MAKE
  246.     echo "PYTHON_SINGLE_TARGETS='python3_6'"                    >> $MAKE
  247.     echo "PYTHON_TARGETS='python3_6 python2_7'"                 >> $MAKE
  248.     echo "USE_PYTHON='3.6'"                             >> $MAKE
  249.     echo                                        >> $MAKE
  250.     echo "RUBY_TARGETS='ruby27'"                            >> $MAKE
  251.     echo "USE_RUBY='ruby27'"                            >> $MAKE
  252.     echo                                        >> $MAKE
  253.     echo "ACCEPT_LICENSE=\"\""                          >> $MAKE
  254.     echo                                        >> $MAKE
  255.     echo "VIDEO_CARDS=\"\""                             >> $MAKE
  256.     echo                                        >> $MAKE
  257.  
  258.     # ensure chroot is usable
  259.     echo "* setting up chroot"
  260.     cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
  261.     mount -t proc none /mnt/gentoo/proc
  262.     mount --rbind /sys /mnt/gentoo/sys
  263.     mount --rbind /dev /mnt/gentoo/dev
  264.    
  265.     # dialog isn't in stage3
  266.     echo "* copy dialog executable and libraries"
  267.     cp /usr/bin/dialog /mnt/gentoo/root
  268.     cp -a /usr/lib*/libdialog.so* /mnt/gentoo/root
  269.    
  270.     # create chroot install script
  271.     echo "* create chroot install script"
  272.     cat <<'__END__' >/mnt/gentoo/root/.gentoo-chroot-install.sh
  273. $EMBED_CHROOT_SH
  274. __END__
  275.  
  276.     C_MENU[7]="*DONE*"
  277. }
  278.  
  279. # Start Gentoo Chroot Environment
  280. menu8() {
  281.     chroot /mnt/gentoo /bin/bash --rcfile /root/.gentoo-chroot-install.sh
  282.     C_MENU[8]="*DONE*"
  283. }
  284.  
  285. ## run the main menu loop
  286. while [[ true ]]; do
  287.     I_MENU=$(dialog --menu 'Gentoo Installer Menu' 0 0 0    \
  288.         1 "${D_MENU[1]} ${C_MENU[1]}"           \
  289.         2 "${D_MENU[2]} ${C_MENU[2]}"           \
  290.         3 "${D_MENU[3]} ${C_MENU[3]}"           \
  291.         4 "${D_MENU[4]} ${C_MENU[4]}"           \
  292.         5 "${D_MENU[5]} ${C_MENU[5]}"           \
  293.         6 "${D_MENU[6]} ${C_MENU[6]}"           \
  294.         7 "${D_MENU[7]} ${C_MENU[7]}"           \
  295.         8 "${D_MENU[8]} ${C_MENU[8]}"           \
  296.         0 "${D_MENU[0]}"                )
  297.        
  298.     if [[ "$I_MENU" != "" ]]; then
  299.         echo
  300.         eval "menu${I_MENU}"
  301.     fi
  302. done
  303.  
  304. ##############################################################################
Advertisement
Add Comment
Please, Sign In to add comment