arch/pkg/de-p1st-installer/de-p1st-installer.sh

178 lines
5.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-04-29 20:25:30 +02:00
# load config
2021-05-01 13:37:28 +02:00
source installer.cfg || { exit 1; }
2021-04-29 20:25:30 +02:00
2021-04-30 21:42:12 +02:00
# load functions
2021-05-01 13:37:28 +02:00
source lib/util.sh || { exit 1; }
source lib/user-input.sh || { exit 1; }
source lib/block-device.sh || { exit 1; }
2021-04-30 21:42:12 +02:00
2021-04-29 20:25:30 +02:00
function check_network() {
echo "Sending ping to wikipedia.de ..."
ping -c 1 wikipedia.de || {
echo "Pleas set up network access."
return 1
}
}
function increase_cow_space() {
# May be useful when running 'pacman -Syu' on the live medium.
# Usually not necessary!
# make sure that we are on a live medium:
findmnt /run/archiso/cowspace || {
echo "Not on live medium, did not increase cowspace!"
return 1
}
echo "Increasing cowspace partition of live medium ..."
mount -o remount,size=2G /run/archiso/cowspace || return $?
}
function get_user_input() {
# return: the following variables:
# BIOS_TYPE (uefi or bios)
# KERNEL (linux or linux-lts)
# FS (BTRFS, EXT4, F2FS)
# HOSTNAME
# USERNAME, USER_PWD
# LUKS_PWD
get_block_devices_with_size || return $?
2021-04-30 21:42:12 +02:00
get_single_choice TARGET_BLOCK_DEVICE "Select target device for installation" BLOCK_DEVICE_SIZES || return $?
2021-04-29 20:25:30 +02:00
2021-05-01 12:25:25 +02:00
TMP1=('uefi' 'Newer mainboards' 'bios' 'Legacy BIOS on older mainboards')
2021-04-30 21:42:12 +02:00
get_single_choice BIOS_TYPE "Select your bios type" TMP1 || return $?
2021-04-29 20:25:30 +02:00
2021-05-01 12:25:25 +02:00
TMP1=('linux-lts' 'Long-Time-Stable Linux kernel' 'linux' 'Latest Linux kernel')
2021-04-30 21:42:12 +02:00
get_single_choice KERNEL "Select kernel version" TMP1 || return $?
2021-04-29 20:25:30 +02:00
2021-05-01 12:25:25 +02:00
TMP1=('BTRFS' 'Allows snapshots and dynamic extension of the FS' 'EXT4' 'Default FS of many distributions' 'F2FS' 'Flash-Friendly-FS for SSD or NVMe')
2021-04-30 21:42:12 +02:00
get_single_choice FS "Select filesystem to use" TMP1 || return $?
2021-04-29 20:25:30 +02:00
get_text_input HOSTNAME "Enter hostname:" || return $?
get_text_input USERNAME "Enter username:" || return $?
if [ -z "${USER_PWD}" ]; then
get_text_input USER_PWD "Enter a user password:" || return $?
get_text_input USER_PWD2 "Please enter the password again:" || return $?
[[ "${USER_PWD}" == "${USER_PWD2}" ]] || {
echo "Passwords did not match";
exit 1;
}
fi
if [ -z "${LUKS_PWD}" ]; then
get_text_input LUKS_PWD "Enter a disk encryption password:" || return $?
get_text_input LUKS_PWD2 "Please enter the password again:" || return $?
[[ "${LUKS_PWD}" == "${LUKS_PWD2}" ]] || {
echo "Passwords did not match";
exit 1;
}
fi
}
function get_cpu_vendor() {
2021-04-30 21:42:12 +02:00
# return: the following variables:
# CPU_VENDOR ("amd", "intel", "none")
2021-04-29 20:25:30 +02:00
if [ -z "${CPU_VENDOR}" ]; then
# if CPU_VENDOR has no value yet, ask user for input!
local vendor_id
vendor_id=$(cat /proc/cpuinfo | grep vendor_id | head -1 | sed 's|vendor_id\s*:\s*||')
if [ "$vendor_id" = "AuthenticAMD" ]; then
CPU_VENDOR="amd"
elif [ "$vendor_id" = "GenuineIntel" ]; then
CPU_VENDOR="intel"
else
echo "Unknown CPU vendor: $vendor_id"
return 1
fi
fi
}
2021-04-30 21:42:12 +02:00
function get_default_mount_options() {
# return: the following variables:
# FS_DEFAULT_MOUNT_OPTIONS (array)
FS_DEFAULT_MOUNT_OPTIONS=()
case "${FS}" in
BTRFS)
# compress=lzo: archwiki -> Btrfs#Compression
# "Enable compression (better performance, longer flash lifespan)"
FS_DEFAULT_MOUNT_OPTIONS+=('compress=lzo')
;;
EXT4)
# https://wiki.archlinux.org/index.php/Ext4#Enabling_metadata_checksums
# If the CPU supports SSE 4.2, make sure the crc32c_intel kernel module is loaded (TODO)
FS_DEFAULT_MOUNT_OPTIONS+=('metadata_csum')
;;
F2FS)
# When mounting the filesystem, specify compress_algorithm=(lzo|lz4|zstd|lzo-rle).
# Using compress_extension=txt will cause all txt files to be compressed by default.
FS_DEFAULT_MOUNT_OPTIONS+=('compress_algorithm=lz4')
;;
*)
echo "Filesystem $FS not yet supported!"
return 1
;;
esac
}
function choose_mount_options() {
# return: the following variables:
# FS_MOUNT_OPTIONS (array)
case "${FS}" in
BTRFS)
# noatime, nodiratime:
# - The atime options do impact drive performance;
# - noatime implies nodiratime, one does not need to specify both;
# - The noatime option fully disables writing file access times to the drive every time you read a file.
# This works well for almost all applications, except for those that need to know if a file has been
# read since the last time it was modified.
2021-05-01 12:25:25 +02:00
TMP1=('noatime' "Don't write file/folder access times" 'on' 'ssd' 'Enable if using SSD/NVMe' 'off')
2021-04-30 21:42:12 +02:00
;;
EXT4)
2021-05-01 12:25:25 +02:00
TMP1=('noatime'" Don't write file/folder access times" 'on')
2021-04-30 21:42:12 +02:00
;;
F2FS)
2021-05-01 12:25:25 +02:00
TMP1=('noatime' "Don't write file/folder access times" 'on')
2021-04-30 21:42:12 +02:00
;;
*)
echo "Filesystem $FS not yet supported!"
return 1
;;
esac
get_multi_choice FS_MOUNT_OPTIONS "Select mount options" TMP1 || return $?
}
2021-04-29 20:25:30 +02:00
function main() {
2021-04-30 21:42:12 +02:00
check_network || return $?
get_user_input || return $?
get_cpu_vendor || return $?
2021-04-30 22:02:50 +02:00
2021-04-30 21:42:12 +02:00
get_default_mount_options || return $?
choose_mount_options || return $?
2021-04-30 22:02:50 +02:00
2021-05-01 14:24:42 +02:00
partition "${TARGET_BLOCK_DEVICE}" "$BIOS_TYPE" || return $?
format "$BIOS_TYPE" "${BOOT_PART}" "${LUKS_PART}" "${LUKS_PWD}" "${FS}" DATA_PART || return $?
2021-04-30 22:02:50 +02:00
# TODO: use FS_DEFAULT_MOUNT_OPTIONS and FS_MOUNT_OPTIONS in combination
2021-05-01 14:24:42 +02:00
mount "$DATA_PART" /mnt || return $?
mkdir /mnt/boot && mount "$BOOT_PART" /mnt/boot || return $?
2021-05-01 15:08:40 +02:00
# TODO: testing
# if bios type is bios then ... :/
# amd/intel-ucode
pacstrap /mnt "${KERNEL}" "${KERNEL}-headers" de-p1st-base-efi
2021-04-29 20:25:30 +02:00
}
main "$@"