#!/bin/bash set -e source funcs.sh # # stage3 install # # sync time ntpd -q -g || true # download & unpack stage3 tarball links https://www.gentoo.org/downloads/mirrors/ LINKS_RUNNING="true" while [[ $LINKS_RUNNING == "true" ]]; do log_msg INFO "Waiting for user to quit links ..." LINKS_RUNNING=$(ps -aux | (grep -o '[l]inks') || true) sleep 5s done tar xpvf stage3-*.tar.xz --xattrs-include="*.*" --numeric-owner rm stage3-*.tar.xz # set USE flags for later rm -rf /mnt/gentoo/etc/package.use touch /mnt/gentoo/etc/package.use cat package.use > /mnt/gentoo/etc/package.use # configure portage (COMMON/USE) cat make.conf > /mnt/gentoo/etc/make.conf # make sure DNS works after chroot cp --dereference /etc/resolv.conf /mnt/gentoo/etc/ # mount filesystems mount --types proc /proc /mnt/gentoo/proc mount --rbind /sys /mnt/gentoo/sys mount --make-rslave /mnt/gentoo/sys mount --rbind /dev /mnt/gentoo/dev mount --make-rslave /mnt/gentoo/dev mount --bind /run /mnt/gentoo/run mount --make-slave /mnt/gentoo/run # change root! chroot /mnt/gentoo /bin/bash << EOF set -e source funcs.sh source /etc/profile export PS1="(chroot) ${PS1}" log_msg INFO "mount boot partition (EFI)" >> /var/log/installer.log mkdir -p /boot/efi mount ${CFG_BLOCK_PART}1 /boot/efi log_msg INFO "synchronize gentoo ebuild repo" >> /var/log/installer.log emerge --ask n --sync # set some makeopts and default opts # WARNING: THE DEFAULT USES ALL THE THREADS IN THE SYSTEM! # IF YOU DO NOT WANT THIS PLEASE CHANGE IT TO WHAT GENTOO RECOMMENDS # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS emerge --ask n cpuid2cpuflags cpuid2cpuflags | sed 's/:\s/="/; s/$/"/' >> /etc/portage/make.conf echo "EMERGE_DEFAULT_OPTS=\"--jobs=$(nproc) --load-average=$(nproc) --keep-going --verbose --quiet-build --with-bdeps=y --complete-graph=y --deep --ask\"" >> /etc/portage/make.conf echo "MAKEOPTS=\"-j$(nproc) -l$(nproc)\"" >> /etc/portage/make.conf # install custom compiler for firefox mkdir -p /etc/portage/env curl -L https://gist.githubusercontent.com/emrakyz/23bf6fe9c30aa0b1eb88021889750ace/raw/832a0160ac0d0383c4f600da5cf8af4290019ff6/compiler-firefox -o /etc/portage/env/compiler-firefox echo "www-client/firefox compiler-firefox" > /etc/portage/package.env # TODO: select profile log_msg INFO "update @world set (@system and @selected)" >> /var/log/installer.log emerge --ask n --update --deep --newuse @world emerge --ask n @preserved-rebuild emerge --ask n --depclean log_msg INFO "configure licenses" >> /var/log/installer.log echo "ACCEPT_LICENSE=\"*\"" >> /etc/portage/make.conf log_msg INFO "configure timezone (glibc)" >> /var/log/installer.log echo ${CFG_TIMEZONE} > /etc/timezone emerge --ask n --config sys-libs/timezone-data log_msg INFO "configure locales (glibc)" >> /var/log/installer.log echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen locale-gen log_msg INFO "reload environment" >> /var/log/installer.log env-update && source /etc/profile && export PS1="(chroot) ${PS1}" # # firmware install # log_msg INFO "installing microcode and firmware" >> /var/log/installer.log emerge --ask n intel-microcode SIGNATURE=$(iucode_tool -S 2>&1 | grep -o "0.*$") sed -i "s/MICROCODE_SIGNATURES=\"-S\"/MICROCODE_SIGNATURES=\"-s $SIGNATURE\"/" /etc/portage/make.conf emerge --ask n intel-microcode USE="-compress-xz" emerge --ask n linux-firmware emerge --oneshot --ask n pciutils GPU_CODE=$(lspci | grep -i 'vga\|3d\|2d' | awk -F'[[]' '{print $1}' | awk '{print $NF}' | tr '[:upper:]' '[:lower:]') sed -i "/^nvidia\/\($GPU_CODE\)/!d" /etc/portage/savedconfig/sys-kernel/linux-firmware-* # fix depen problems with freetype and harfbuzz USE="-harfbuzz" emerge --oneshot --ask n freetype emerge --oneshot --ask n freetype # # kernel install # log_msg INFO "install kernel sources" >> /var/log/installer.log emerge --ask n sys-kernel/gentoo-sources # testing if cd works, if curl screws up this is probably the main issue cd /usr/src/linux curl -L https://gist.githubusercontent.com/emrakyz/0ff8674792bd844fcab6afb2063ffa94/raw/e91e60ae2f74ccee8fcd7b7b93db942ba60277ce/.config -o .config MICROCODE_PATH=$(iucode_tool -S -l /lib/firmware/intel-ucode/* 2>&1 | grep 'microcode bundle' | awk -F': ' '{print $2}' | cut -d'/' -f4-) sed -i "s#CONFIG_EXTRA_FIRMWARE=.*#CONFIG_EXTRA_FIRMWARE=\"$MICROCODE_PATH\"#g" /usr/src/linux/.config THREAD_NUM=$(nproc) sed -i "s#CONFIG_NR_CPUS=.*#CONFIG_NR_CPUS=$THREAD_NUM#g" /usr/src/linux/.config make menuconfig MAKEMENUCONFIG_RUNNING="true" while [[ $MAKEMENUCONFIG_RUNNING == "true" ]]; do log_msg INFO "Waiting for user to end modifying kernel ..." MAKEMENUCONFIG_RUNNING=$(ps -aux | (grep -o '[m]ake') || true) sleep 5s done make -j$(nproc) emerge nvidia-drivers linux-firmware make modules_install # # filesystem install # #needed so motherboard can detect it mkdir -p /boot/EFI/BOOT cp /usr/src/linux/arch/x86/boot/bzImage /boot/EFI/BOOT/BOOTX64.EFI log_msg INFO "set swap, / and cdrom in fstab" >> /var/log/installer.log mkdir -p /mnt/cdrom echo "${CFG_BLOCK_PART}"2 none swap sw 0 0 >> /etc/fstab echo "${CFG_BLOCK_PART}"3 / ext4 defaults,noatime 0 1 >> /etc/fstab echo "${CFG_BLOCK_PART}"4 / ext4 defaults,noatime 0 1" >> /etc/fstab echo /dev/cdrom /mnt/cdrom auto noauto,user 0 0 >> /etc/fstab # # networking install # log_msg INFO "set hostname" >> /var/log/installer.log echo "hostname=\"${CFG_HOSTNAME}\"" > /etc/conf.d/hostname log_msg INFO "install networkmanager" >> /var/log/installer.log emerge --ask n --noreplace net-misc/networkmanager log_msg INFO "install dhcpcd" >> /var/log/installer.log emerge --ask n net-misc/dhcpcd log_msg INFO "install wireless" >> /var/log/installer.log emerge --ask n net-wireless/iw net-wireless/wpa_supplicant log_msg INFO "configure networking" >> /var/log/installer.log # placeholder /etc/hosts file, replace later curl https://git.keyemail.dev/lurk/really-bad-gentoo-install/raw/branch/master/README.md >> /etc/hosts log_msg INFO "configure hosts" >> /var/log/installer.log echo "127.0.0.1 ${CFG_HOSTNAME} localhost" >> /etc/hosts # # system install # log_msg INFO "set root password" >> /var/log/installer.log echo "root:${CFG_ROOT_PASSWORD}" | chpasswd log_msg INFO "set keymap" >> /var/log/installer.log sed -i '/^keymap/s/=.*$/=$"'"fi"'"/' /etc/conf.d/keymaps rc-update add keymaps boot rc-service keymaps restart log_msg INFO "install syslog" >> /var/log/installer.log emerge --ask n app-admin/sysklogd rc-update add sysklogd default log_msg INFO "install crond" >> /var/log/installer.log emerge --ask n sys-process/cronie rc-update add cronie default log_msg INFO "install file indexer" >> /var/log/installer.log emerge --ask n sys-apps/mlocate log_msg INFO "install filesystem tools" >> /var/log/installer.log emerge --ask n sys-fs/e2fsprogs emerge --ask n sys-fs/dosfstools log_msg INFO "set clock" >> /var/log/installer.log sed -i 's/clock=.*/clock=\"local\"/g' /etc/conf.d/hwclock log_msg INFO "install doas (sudo replacement)" >> /var/log/installer.log emerge --ask n doas echo "permit :wheel permit nopass keepenv :$CFG_USER_USERNAME permit nopass keepenv :root" > /etc/doas.conf log_msg INFO "install git" >> /var/log/installer.log emerge --ask n app-eselect/eselect-repository dev-vcs/git log_msg INFO "set up git ver of gentoo repo" >> /var/log/installer.log eselect repository remove gentoo rm -rf /var/db/repos/gentoo eselect repository add gentoo git https://github.com/gentoo-mirror/gentoo.git log_msg INFO "install pipewire" >> /var/log/installer.log emerge --ask n pipewire emerge --ask n wireplumber log_msg INFO "install efibootmgr" >> /var/log/installer.log emerge --ask n efibootmgr # create user useradd -mG wheel,audio,video,usb,input,portage,pipewire $CFG_USER_USERNAME echo "$CFG_USER_USERNAME:$CFG_USER_PASSWORD" | chpasswd # nvidia modules mkdir -p /etc/modules-load.d echo "nvidia nvidia_modeset nvidia_uvm nvidia_drm" > /etc/modules-load.d/video.conf echo "nvidia-drm options nvidia-drm modeset=1" > /etc/modules-load.d/nvidia-drm.conf # clean up portage rm -rf /var/tmp/portage/* rm -rf /var/cache/distfiles/* rm -rf /var/cache/binpkgs/* # # bootloader install should be done manually # EOF