really-bad-gentoo-install/install.sh

107 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2024-09-21 06:27:28 +00:00
#!/bin/bash
set -e
source funcs.sh
log_msg INFO "Welcome to the code stolen Gentoo installer script!"
2024-09-21 06:27:28 +00:00
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)" "16384")"
2024-09-21 06:27:28 +00:00
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" "")"
export CFG_USER_USERNAME="$(prompt_value "Username for daily use" "gentoo")"
export CFG_USER_PASSWORD="$(prompt_value "Password for your user" "")"
2024-09-21 06:27:28 +00:00
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
- CFG_USER_USERNAME: $CFG_USER_USERNAME
- CFG_USER_PASSWORD: $CFG_USER_PASSWORD
2024-09-21 06:27:28 +00:00
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
parted -a optimal $CFG_BLOCK_DEVICE mklabel gpt
# 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
log_msg INFO "Automatic installation completed, look at README for steps"
log_msg INFO "DO NOT IGNORE THE LAST STEP OR GENTOO WILL NOT BOOT!"