mirror of
https://codeberg.org/privacy1st/arch
synced 2024-12-23 01:16:04 +01:00
267 lines
7.4 KiB
Bash
Executable File
267 lines
7.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# load config
|
|
source installer.cfg || { exit 1; }
|
|
|
|
# load functions
|
|
source helper.sh || { exit 1; }
|
|
|
|
|
|
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_text_input {
|
|
# If variable with name $1 is zero, then ask user for input.
|
|
# Only one line user input is allowed.
|
|
# User input must not be empty.
|
|
#
|
|
# $1: name of variable to store user input
|
|
# $2: text to display (e.g. "Enter hostname:")
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "get_text_input requires two args!";
|
|
return 1
|
|
fi
|
|
for i in "$@"; do
|
|
if [ -z "$i" ]; then
|
|
echo "get_text_input: all given args must not be empty";
|
|
return 1;
|
|
fi
|
|
done
|
|
|
|
local -n ptr=$1
|
|
if [ -z "$ptr" ]; then
|
|
# if ptr has no value yet, ask user for input!
|
|
echo "$2"
|
|
read -r ptr || return $?
|
|
fi
|
|
|
|
# check string length to be greater than zero!
|
|
if [ "${#ptr}" -lt 1 ]; then
|
|
echo "get_text_input must not be empty!";
|
|
return 1;
|
|
fi
|
|
}
|
|
|
|
function get_single_choice {
|
|
# If variable with name $1 is zero, then ask user to select one option.
|
|
#
|
|
# $1: name of variable to store the selected option
|
|
# $2: text to display
|
|
# $3: name of variable with space-separated menu options to display (each menu option consists of an item and a description)
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "get_single_choice requires three args!";
|
|
return 1
|
|
fi
|
|
for i in "$@"; do
|
|
if [ -z "$i" ]; then
|
|
echo "get_single_choice: all given args must not be empty";
|
|
return 1;
|
|
fi
|
|
done
|
|
|
|
|
|
local -n ptr=$1
|
|
if [ -z "$ptr" ]; then
|
|
# if ptr has no value yet, ask user for input!
|
|
|
|
local -n MENU_OPTIONS=$3
|
|
ptr=$(dialog --stdout --menu "$2" 0 0 0 ${MENU_OPTIONS}) || {
|
|
echo "Error during menu selection!"
|
|
exit 1
|
|
}
|
|
clear
|
|
fi
|
|
}
|
|
|
|
function get_multi_choice {
|
|
# If variable with name $1 is zero, then ask user to select one ore more options.
|
|
#
|
|
# $1: name of variable to store array of selected options
|
|
# $2: text to display
|
|
# $3: name of variable with space-separated menu options to display (each menu option consists of an item, a description and on/off if preselected or not)
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "get_multi_choice requires three args!";
|
|
return 1
|
|
fi
|
|
for i in "$@"; do
|
|
if [ -z "$i" ]; then
|
|
echo "get_multi_choice: all given args must not be empty";
|
|
return 1;
|
|
fi
|
|
done
|
|
|
|
|
|
local -n ptr=$1
|
|
if [ -z "$ptr" ]; then
|
|
# if ptr has no value yet, ask user for input!
|
|
|
|
local -n MENU_OPTIONS=$3
|
|
local tmp=$(dialog --stdout --checklist "$2" 0 0 0 ${MENU_OPTIONS}) || {
|
|
echo "Error during menu selection!"
|
|
exit 1
|
|
}
|
|
clear
|
|
|
|
# Result of dialog is space separated list
|
|
# Store this as an array
|
|
readarray -d " " -t ptr <<<"$tmp"
|
|
fi
|
|
}
|
|
|
|
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 $?
|
|
get_single_choice TARGET_BLOCK_DEVICE "Select target device for installation" BLOCK_DEVICE_SIZES || return $?
|
|
|
|
TMP1="uefi Newer-mainboards bios Legacy-BIOS-on-older-mainboards"
|
|
get_single_choice BIOS_TYPE "Select your bios type" TMP1 || return $?
|
|
|
|
TMP1="linux-lts Long-Time-Stable-Linux-kernel linux Latest-Linux-kernel"
|
|
get_single_choice KERNEL "Select kernel version" TMP1 || return $?
|
|
|
|
TMP1="BTRFS allows-snapshots-and-dynamic-extension-of-the-fs EXT4 default-fs-of-many-distributions F2FS Flash-Friendly-fs-for-SSD-or-NVMe"
|
|
get_single_choice FS "Select filesystem to use" TMP1 || return $?
|
|
|
|
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() {
|
|
# return: the following variables:
|
|
# CPU_VENDOR ("amd", "intel", "none")
|
|
|
|
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
|
|
}
|
|
|
|
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.
|
|
TMP1="noatime Don't-write-file/folder-access-times off ssd Only-enable-when-on-ssd-or-nvme off"
|
|
;;
|
|
EXT4)
|
|
TMP1="noatime Don't-write-file/folder-access-times off"
|
|
;;
|
|
F2FS)
|
|
TMP1="noatime Don't-write-file/folder-access-times off"
|
|
;;
|
|
*)
|
|
echo "Filesystem $FS not yet supported!"
|
|
return 1
|
|
;;
|
|
esac
|
|
|
|
get_multi_choice FS_MOUNT_OPTIONS "Select mount options" TMP1 || return $?
|
|
|
|
# TODO: test FS_MOUNT_OPTIONS
|
|
echo "${FS_MOUNT_OPTIONS[@]}"
|
|
echo "${#FS_MOUNT_OPTIONS[@]}"
|
|
for i in "${FS_MOUNT_OPTIONS[@]}"; do
|
|
echo "<<$i>>"
|
|
done
|
|
}
|
|
|
|
function main() {
|
|
check_network || return $?
|
|
get_user_input || return $?
|
|
get_cpu_vendor || return $?
|
|
get_default_mount_options || return $?
|
|
choose_mount_options || return $?
|
|
}
|
|
|
|
main "$@"
|