Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # gentoo install script -- akira2501 -- 2012 -- for the public domain
- PATH="/sbin:/usr/sbin:/bin:/usr/bin"
- GENTOO_MIRRORS="http://distfiles.gentoo.org/"
- I_MIRROR="http://distfiles.gentoo.org/"
- export LANG=en_US.UTF-8
- export LANGUAGE=${LANG}
- export LC_COLLATE=C
- shopt -s expand_aliases
- alias dialog="dialog --stdout"
- ## check pre-requisites
- READY=1
- ## ensure the user has mounted a boot filesystem if we are on efi
- if [[ -d /sys/firmware/efi ]]; then
- grep /mnt/gentoo/boot /proc/mounts 1>/dev/null 2>&1
- if [[ $? != 0 ]]; then
- echo "* please mount your EFI boot partition under /mnt/gentoo/boot"
- echo "* create a 256MiB vfat32 filesystem for grub EFI:"
- echo "= mkfs.vfat -F32 dev"
- echo
- READY=0
- fi
- fi
- ## ensure the user has mounted some block device to install into
- grep /mnt/gentoo /proc/mounts 1>/dev/null 2>&1
- if [[ $? != 0 ]]; then
- echo "* please mount your installation target partiton(s) under /mnt/gentoo"
- echo "* create filesystem and swap partitions:"
- echo "= mke2fs -v -m0 -j -O dir_index,sparse_super,uninit_bg,extents,filetype dev"
- echo
- READY=0
- fi
- ## ensure we are ready to proceed
- if [[ "$READY" != "1" ]]; then
- exit
- fi
- ## select architecture and processor (amd64, x86, etc...)
- while [[ "$I_ARCH" == "" ]]; do
- I_ARCH=$(dialog --menu 'Select Architecture' 0 0 0 amd64 '64-bit Intel/AMD' x86 '32-bit Intel/AMD')
- if [[ "$I_ARCH" == "amd64" ]]; then
- I_PROC="amd64"
- I_HOST="x86_64-pc-linux-gnu"
- elif [[ "$I_ARCH" == "x86" ]]; then
- while [[ "$I_PROC" == "" ]]; do
- I_PROC=$(dialog --menu 'Select Processor Family' 0 0 0 i486 'i486 Intel/AMD' i686 'Pentium Intel/AMD')
- done
- I_HOST="${I_PROC}-pc-linux-gnu"
- else
- I_PROC=""
- I_ARCH=""
- I_HOST=""
- fi
- done
- ## main menu methods
- dcommand() {
- eval "$2" 2>&1 | dialog --programbox "$1" -1 -1
- }
- C_MENU=('' '' '' '' '' '' '' '' '')
- D_MENU=(
- 'Quit'
- 'Set Time and Date'
- 'Set Gentoo Mirror'
- 'Install Gentoo System'
- 'Install Portage Snapshot'
- 'Install Bundled Portage Tree'
- 'Install Linux Kernel'
- 'Setup Gentoo System'
- 'Start Chroot Environment'
- )
- # Quit
- menu0() {
- rm -f /mnt/gentoo/root/{.gentoo-chroot-install,dialog,libdialog.so}*
- exit
- }
- # Set Time and Date
- menu1() {
- dcommand "Using NTPD to get current time:" "ntpd -q"
- C_MENU[1]="*DONE*"
- }
- # Set Gentoo Mirror
- menu2() {
- I_MENU=""
- I_MENU=$(dialog --menu 'Gentoo Mirror Selection Method' 0 0 0 \
- 1 'Interactively Select Mirror' \
- 2 'Automatically Determine Mirror' \
- 3 'Manually Set Mirror Variable' )
- if [[ "$I_MENU" == "1" ]]; then
- eval `mirrorselect -i -4 -H -o`
- elif [[ "$I_MENU" == "2" ]]; then
- eval `mirrorselect -s1 -4 -H -o`
- elif [[ "$I_MENU" == "3" ]]; then
- GENTOO_MIRRORS=$(dialog --inputbox 'GENTOO_MIRRORS=' 0 -1 "$GENTOO_MIRRORS")
- fi
- I_MIRROR=`echo "$GENTOO_MIRRORS" | cut -d' ' -f1`
- if [[ "${I_MIRROR: -1}" != "/" ]]; then
- I_MIRROR="${I_MIRROR}/"
- fi
- C_MENU[2]="*DONE*"
- }
- # Install Gentoo System
- menu3() {
- echo "* downloading list of gentoo ${I_ARCH} stage3 tarballs.."
- R_STAGE=${I_MIRROR}releases/${I_ARCH}/autobuilds/
- T_STAGE=$(mktemp -d)
- (
- cd $T_STAGE
- wget --quiet -r -l 1 -nd -np --accept-regex "latest-stage3.*${I_PROC}.*\.txt$" ${R_STAGE}
- )
- I_STAGE=$(dialog --no-items --menu 'Choose Stage3 Tarball' 0 0 0 $(cat $T_STAGE/*.txt | grep -v '^#' | sort | uniq | cut -d' ' -f1))
- rm -rf $T_STAGE
- if [[ "$I_STAGE" != "" ]]; then
- dcommand "Download and Install Stage3 Tarball" "wget -O- ${R_STAGE}${I_STAGE} | tar xJfp - -C /mnt/gentoo"
- C_MENU[3]="*DONE*"
- fi
- }
- # Install Portage Snapshot
- menu4() {
- dcommand "Download and Install Latest Portage Snapshot" "wget -O- ${I_MIRROR}snapshots/portage-latest.tar.bz2 | tar xjfp - -C /mnt/gentoo/usr"
- C_MENU[4]="*DONE*"
- }
- # Install Bundled Portage Add Ons
- menu5() {
- dcommand "Install Bundled Portage Add Ons" "tail -c $EMBED_TAR_SIZE $0 | tar xjf - -C /mnt/gentoo/usr/local"
- C_MENU[5]="*DONE*"
- }
- # Install Linux Kernel
- menu6() {
- echo "* downloading list of available kernels"
- U_KERNEL=$(dialog --no-items --menu 'Choose Linux Kernel' 0 0 0 $(
- wget --quiet -O- https://www.kernel.org/releases.json | grep '"source"' | grep "tar.xz" | awk -F '"' '{print $4}'
- ))
- if [[ "$U_KERNEL" != "" ]]; then
- P_KERNEL=$(basename $U_KERNEL .tar.xz)
- dcommand "Download and Install Latest Linux Kernel" \
- "wget -O- ${U_KERNEL} | tee /mnt/gentoo/usr/src/${P_KERNEL}.tar.xz | tar xfJ - -C /mnt/gentoo/usr/src"
- (
- cd /mnt/gentoo/usr/src
- ln -s ${P_KERNEL} linux
- echo $(cut -d'-' -f2 <<< $P_KERNEL) > linux/.i_kernel
- )
- C_MENU[6]="*DONE*"
- fi
- }
- # Setup Gentoo System
- menu7() {
- echo "* creating fstab"
- FSTAB="/mnt/gentoo/etc/fstab"
- printf "%-15s %-15s %-15s %-23s s\n" "device" "mount" "type" "options" "dump/order" > $FSTAB
- cut -d' ' -f1-3 /proc/mounts | while read xdev xmnt xfst; do
- # only real devices that are currently mounted in /mnt/gentoo
- if [[ "${xdev:0:5}" != "/dev/" ]] || [[ "${xmnt:0:11}" != "/mnt/gentoo" ]]; then
- continue
- fi
- # remove /mnt/gentoo from start of mount path then determine pass order
- xmnt=${xmnt:11}
- [[ "$xmnt" == "/" ]] && xpas=1 || xpas=2
- printf "%-15s %-15s %-15s %-23s 0 %d\n" $xdev $xmnt $xfst "defaults" $xpas >> $FSTAB
- done
- echo >> $FSTAB
- swapon -s | grep partition | cut -d' ' -f1 | while read xdev; do
- printf "%-15s %-15s %-15s %-23s 0 0\n" $xdev "none" "swap" "defaults" >> $FSTAB
- done
- echo >> $FSTAB
- echo "shm /dev/shm tmpfs nodev,nosuid,noexec 0 0" >> $FSTAB
- echo "devpts /dev/pts devpts gid=5,mode=0620 0 0" >> $FSTAB
- echo "proc /proc proc defaults 0 0" >> $FSTAB
- echo "sysfs /sys sysfs defaults 0 0" >> $FSTAB
- # create make.conf
- MCORES=$(grep processor /proc/cpuinfo | wc -l)
- MFLAGS=""
- RFLAGS=$(grep -e '^flags' /proc/cpuinfo | head -1)
- 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
- [[ "$RFLAGS" == *" ${x}"* ]] && MFLAGS="${MFLAGS} ${x}"
- done
- echo "* creating make.conf"
- MAKE="/mnt/gentoo/etc/portage/make.conf"
- echo "CHOST=\"${I_HOST}\"" > $MAKE
- echo >> $MAKE
- echo "CFLAGS=\"-O2 -march=native -fomit-frame-pointer -pipe\"" >> $MAKE
- echo "CXXFLAGS=\"\${CFLAGS}\"" >> $MAKE
- echo >> $MAKE
- echo "CPU_FLAGS_X86=\"${MFLAGS}\"" >> $MAKE
- echo >> $MAKE
- echo "ACCEPT_KEYWORDS=\"${I_ARCH} ~${I_ARCH}\"" >> $MAKE
- echo "FEATURES=\"nodoc clean-logs parallel-fetch\"" >> $MAKE
- echo "MAKEOPTS=\"-j${MCORES}\"" >> $MAKE
- echo >> $MAKE
- echo "USE=\"" >> $MAKE
- echo -e "\tdjbfft fftw" >> $MAKE
- echo -e "\tacpi acl caps maildir mmap glibc-omitfp threads dvd dvdr dvdread" >> $MAKE
- echo -e "\tlm_sensors sql vnc rdp pdf qt3support" >> $MAKE
- echo -e "\treadline libedit python ruby sqlite3" >> $MAKE
- echo -e "\tpam spell curl expat xml zlib bzip2 lzo lzma cdb crypt icu" >> $MAKE
- echo -e "\tsdl gif jpeg jbig jpeg2k png pnm tiff svg exif" >> $MAKE
- echo -e "\tX xv xvmc truetype cairo qt4 gtk xscreensaver nsplugin" >> $MAKE
- echo -e "\topengl avi mpeg ffmpeg theora real dirac x264 dv xvid" >> $MAKE
- echo -e "\talsa ogg a52 aac audiofile lame mad sox openal vorbis dts" >> $MAKE
- echo -e "\tjack speex flac mp2 mp3 faac faad" >> $MAKE
- echo -e "\t-tcpd -dbus -openrc -redistributable" >> $MAKE
- echo "\"" >> $MAKE
- echo >> $MAKE
- echo "PORTDIR_OVERLAY=\"/usr/local/portage\"" >> $MAKE
- echo "PORTDIR=\"/usr/portage\"" >> $MAKE
- echo >> $MAKE
- echo "GENTOO_MIRRORS=\"${GENTOO_MIRRORS}\"" >> $MAKE
- echo >> $MAKE
- echo "PYTHON_SINGLE_TARGETS='python3_6'" >> $MAKE
- echo "PYTHON_TARGETS='python3_6 python2_7'" >> $MAKE
- echo "USE_PYTHON='3.6'" >> $MAKE
- echo >> $MAKE
- echo "RUBY_TARGETS='ruby27'" >> $MAKE
- echo "USE_RUBY='ruby27'" >> $MAKE
- echo >> $MAKE
- echo "ACCEPT_LICENSE=\"\"" >> $MAKE
- echo >> $MAKE
- echo "VIDEO_CARDS=\"\"" >> $MAKE
- echo >> $MAKE
- # ensure chroot is usable
- echo "* setting up chroot"
- cp /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
- # dialog isn't in stage3
- echo "* copy dialog executable and libraries"
- cp /usr/bin/dialog /mnt/gentoo/root
- cp -a /usr/lib*/libdialog.so* /mnt/gentoo/root
- # create chroot install script
- echo "* create chroot install script"
- cat <<'__END__' >/mnt/gentoo/root/.gentoo-chroot-install.sh
- $EMBED_CHROOT_SH
- __END__
- C_MENU[7]="*DONE*"
- }
- # Start Gentoo Chroot Environment
- menu8() {
- chroot /mnt/gentoo /bin/bash --rcfile /root/.gentoo-chroot-install.sh
- C_MENU[8]="*DONE*"
- }
- ## run the main menu loop
- while [[ true ]]; do
- I_MENU=$(dialog --menu 'Gentoo Installer Menu' 0 0 0 \
- 1 "${D_MENU[1]} ${C_MENU[1]}" \
- 2 "${D_MENU[2]} ${C_MENU[2]}" \
- 3 "${D_MENU[3]} ${C_MENU[3]}" \
- 4 "${D_MENU[4]} ${C_MENU[4]}" \
- 5 "${D_MENU[5]} ${C_MENU[5]}" \
- 6 "${D_MENU[6]} ${C_MENU[6]}" \
- 7 "${D_MENU[7]} ${C_MENU[7]}" \
- 8 "${D_MENU[8]} ${C_MENU[8]}" \
- 0 "${D_MENU[0]}" )
- if [[ "$I_MENU" != "" ]]; then
- echo
- eval "menu${I_MENU}"
- fi
- done
- ##############################################################################
Advertisement
Add Comment
Please, Sign In to add comment