mad changes

This commit is contained in:
lurk 2024-09-20 23:27:28 -07:00
commit d6871d64d0
4 changed files with 371 additions and 0 deletions

28
README.md Normal file
View file

@ -0,0 +1,28 @@
# a horrible customized gentoo-install
i was too lazy to figure out how to fork it from github my apologies
[source/upstream/whatever it's called i forgot](https://gitlab.com/harha_/gentoo-installer)
[stole lots of flags and config stuff from here](https://www.reddit.com/r/Gentoo/comments/150r74m/guide_hyprland_nvidia_extremely_minimal_gentoo/)
## todo
- DO NOT USE!!!!! I'M NOT DONE (actually it would probably work cause i didnt change anything)
- figure out how shell works
- cut down on unneeded features
- automatically install programs i like
- not break things (hopefully)
## hopefully added features
- cut down on unneeded features
- fully automate certain portions (installing kernel/decent portage flags etc etc)
- default programs because i do not want to modify files just to get xorg working ever again
- actually working efibootmgr
## some notes for me (in the future)
1. no mbr
2. no full disk encryption
3. only uses efistub (no bootloader)
4. amd64 openrc only (could probably modify this in less than 10 seconds by changing stage3 download)
5. assumes intel cpu and nvidia gpu
gentoo is awful(ly good)

37
funcs.sh Normal file
View file

@ -0,0 +1,37 @@
#!/bin/bash
check_args() {
if [[ "$1" -ne "$2" ]]; then
echo "check_args error, number of given arguments was $1, must be $2!"
exit 1
fi
}
log_msg() {
check_args "$#" "2"
echo "$(date '+%d/%m/%Y %H:%M:%S') $1: $2"
}
prompt_accept() {
check_args "$#" "1"
read -p "$1: " choice
case "$choice" in
y|Y|yes|YES ) echo "y";;
n|N|no|NO ) echo "n";;
* ) echo "n";;
esac
}
prompt_value() {
check_args "$#" "2"
read -p "$1 ('.' for default: '$2'): " value
if [[ "$value" == "." ]]; then
echo $2
else
echo $value
fi
}

107
install.sh Executable file
View file

@ -0,0 +1,107 @@
#!/bin/bash
set -e
source funcs.sh
log_msg INFO "Welcome to the simple Gentoo installer script!"
log_msg INFO "$(cat <<-END
This script assumes the following things:
- networking works
- gpt & uefi
- ext4 filesystems
- openrc
END
)"
#
# initial install
#
# make sure all scripts are executable
chmod +x *.sh
# configure installer
export CFG_BLOCK_DEVICE="$(prompt_value "Target block device handle" "")"
export CFG_PART_PREFIX="$(prompt_value "Partition number prefix (eg. 'p' for NVMe, '' for HDD/SSD)" "")"
export CFG_BLOCK_PART="${CFG_BLOCK_DEVICE}${CFG_PART_PREFIX}"
export CFG_PART_BOOT_SIZE="$(prompt_value "Boot partition size (in MB)" "256")"
export CFG_PART_SWAP_SIZE="$(prompt_value "Swap partition size (in MB)" "4096")"
export CFG_PART_ROOT_SIZE="$(prompt_value "Root partition size (in MB)" "")"
export CFG_PART_HOME_SIZE="$(prompt_value "Home partition size (in %)" "100")%"
export CFG_LLVM="$(prompt_accept "Use LLVM instead of GNU CC")"
export CFG_TIMEZONE="$(prompt_value "System timezone" "America/Los_Angeles")"
export CFG_LOCALE="$(prompt_value "System locale" "en_US")"
export CFG_HOSTNAME="$(prompt_value "System hostname" "gentoo")"
export CFG_NETWORK_INTERFACE="$(prompt_value "Network interface name" "enp0s3")"
export CFG_KEYMAP="$(prompt_value "Keymap to use" "fi")"
export CFG_ROOT_PASSWORD="$(prompt_value "Root user password" "")"
log_msg INFO "$(cat <<END
Verify configuration:
- CFG_BLOCK_DEVICE: $CFG_BLOCK_DEVICE
- CFG_PART_PREFIX: $CFG_PART_PREFIX
- CFG_BLOCK_PART: $CFG_BLOCK_PART
- CFG_PART_BOOT_SIZE: $CFG_PART_BOOT_SIZE
- CFG_PART_SWAP_SIZE: $CFG_PART_SWAP_SIZE
- CFG_PART_ROOT_SIZE: $CFG_PART_ROOT_SIZE
- CFG_PART_HOME_SIZE: $CFG_PART_HOME_SIZE
- CFG_LLVM: $CFG_LLVM
- CFG_TIMEZONE: $CFG_TIMEZONE
- CFG_LOCALE: $CFG_LOCALE
- CFG_HOSTNAME: $CFG_HOSTNAME
- CFG_NETWORK_INTERFACE: $CFG_NETWORK_INTERFACE
- CFG_KEYMAP: $CFG_KEYMAP
- CFG_ROOT_PASSWORD: $CFG_ROOT_PASSWORD
END
)"
PROMPT_PROCEED=$(prompt_accept "Verify that the above info is correct and proceed at your own risk")
if [[ "$PROMPT_PROCEED" == "n" ]]; then
log_msg WARN "Exiting installer safely, nothing was done..."
exit 0
fi
# wipe old fs
PROMPT_WIPEFS=$(prompt_accept "Wipe all from target filesystem")
if [[ "$PROMPT_WIPEFS" == "y" ]]; then
log_msg WARN "Executing 'wipefs -a $CFG_BLOCK_DEVICE' ..."
wipefs -a $CFG_BLOCK_DEVICE
fi
# setup disklabel
if [[ "${CFG_PART_UEFI}" == "y" ]]; then
parted -a optimal $CFG_BLOCK_DEVICE mklabel gpt
else
parted -a optimal $CFG_BLOCK_DEVICE mklabel msdos
fi
# setup partitions
parted -s $CFG_BLOCK_DEVICE mkpart primary 0% $CFG_PART_BOOT_SIZE
parted -s $CFG_BLOCK_DEVICE mkpart primary $CFG_PART_BOOT_SIZE $CFG_PART_SWAP_SIZE
parted -s $CFG_BLOCK_DEVICE mkpart primary $(($CFG_PART_BOOT_SIZE+$CFG_PART_SWAP_SIZE)) $CFG_PART_ROOT_SIZE
parted -s $CFG_BLOCK_DEVICE mkpart primary $(($CFG_PART_BOOT_SIZE+$CFG_PART_SWAP_SIZE+$CFG_PART_ROOT_SIZE)) $CFG_PART_HOME_SIZE
parted -s $CFG_BLOCK_DEVICE print
# setup filesystems
mkfs.fat -F 32 ${CFG_BLOCK_PART}1
mkswap ${CFG_BLOCK_PART}2
mkfs.ext4 ${CFG_BLOCK_PART}3
mkfs.ext4 ${CFG_BLOCK_PART}4
# activate swap partition
swapon ${CFG_BLOCK_PART}2
# mount root parition
mkdir -p /mnt/gentoo
mount ${CFG_BLOCK_PART}3 /mnt/gentoo
# execute stage3 install
cp stage3.sh /mnt/gentoo/
cp funcs.sh /mnt/gentoo/
(cd /mnt/gentoo ; bash stage3.sh)
# finalize installation
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
log_msg INFO "All is done! You can execute 'reboot' now!"

199
stage3.sh Normal file
View file

@ -0,0 +1,199 @@
#!/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
# configure portage (COMMON/USE)
PROMPT_PORTAGE=$(prompt_accept "Configure /etc/portage/make.conf COMMON/USE/MAKE/etc flags")
if [[ "$PROMPT_PORTAGE" == "y" ]]; then
nano -w ./etc/portage/make.conf
NANO_RUNNING="true"
while [[ $NANO_RUNNING == "true" ]]; do
log_msg INFO "Waiting for user to quit nano ..."
NANO_RUNNING=$(ps -aux | (grep -o '[n]ano') || true)
sleep 5s
done
fi
# 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
# TODO: select profile
log_msg INFO "update @world set (@system and @selected)" >> /var/log/installer.log
emerge --ask n --update --deep --newuse @world
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 sys-libs/timezone-data
log_msg INFO "configure locales (glibc)" >> /var/log/installer.log
echo "fi_FI.UTF-8 UTF-8" >> /etc/locale.gen
echo "fi_FI ISO-8859-1" >> /etc/locale.gen
echo "en_GB.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
#
#
# kernel install
#
log_msg INFO "install kernel sources" >> /var/log/installer.log
emerge --ask n sys-kernel/gentoo-sources
log_msg INFO "select kernel sources" >> /var/log/installer.log
eselect kernel list
eselect kernel set 1
log_msg INFO "install genkernel" >> /var/log/installer.log
emerge --ask n sys-kernel/genkernel
log_msg INFO "set /boot/efi in fstab" >> /var/log/installer.log
echo "${CFG_BLOCK_PART}1 /boot/efi vfat defaults 0 2" >> /etc/fstab
if [[ "${CFG_LLVM}" == "y" ]]; then
log_msg INFO "compile kernel sources (llvm)" >> /var/log/installer.log
LLVM=1 LLVM_IAS=1 genkernel all \
--kernel-as=llvm-as \
--kernel-ar=llvm-ar \
--kernel-cc=clang \
--kernel-ld=ld.lld \
--kernel-nm=llvm-nm \
--utils-as=llvm-as \
--utils-ar=llvm-ar \
--utils-cc=clang \
--utils-cxx=clang++ \
--utils-ld=ld.lld \
--utils-nm=llvm-nm
else
log_msg INFO "compile kernel sources (gcc)" >> /var/log/installer.log
genkernel all
fi
#
# filesystem install
#
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 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
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
#
# bootloader install
#
log_msg INFO "install grub2 with efi" >> /var/log/installer.log
echo "GRUB_PLATFORMS=\"efi-64\"" >> /etc/portage/make.conf
emerge --ask n sys-boot/grub
log_msg INFO "install EFI bootloader" >> /var/log/installer.log
grub-install --target=x86_64-efi --efi-directory=/boot/efi
log_msg INFO "configure bootloader" >> /var/log/installer.log
grub-mkconfig -o /boot/grub/grub.cfg
EOF