2021-04-28 18:09:45 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-29 20:25:30 +02:00
|
|
|
# load config
|
2021-05-03 16:41:33 +02:00
|
|
|
source /etc/de-p1st-installer/installer.cfg || { exit 1; }
|
2021-04-29 20:25:30 +02:00
|
|
|
|
2021-04-30 21:42:12 +02:00
|
|
|
# load functions
|
2021-05-03 16:41:33 +02:00
|
|
|
source /usr/lib/de-p1st-installer/util.sh || { exit 1; }
|
|
|
|
source /usr/lib/de-p1st-installer/user-input.sh || { exit 1; }
|
|
|
|
source /usr/lib/de-p1st-installer/block-device.sh || { exit 1; }
|
2021-04-30 21:42:12 +02:00
|
|
|
|
2021-06-18 22:03:14 +02:00
|
|
|
function main() {
|
|
|
|
# @pre
|
|
|
|
# bash libraries imported
|
|
|
|
# @post
|
|
|
|
# installation finished
|
|
|
|
|
|
|
|
check_network || return $?
|
2021-09-30 10:11:00 +02:00
|
|
|
system_time || return $?
|
2021-11-13 13:56:47 +01:00
|
|
|
# in: BOOT_FIRMWARE, FS, HOSTNAME, USERNAME, USER_PWD, FDE, LUKS_PWD; (all variables are optional)
|
|
|
|
# out: BOOT_FIRMWARE, FS, HOSTNAME, USERNAME, USER_PWD, FDE, LUKS_PWD (if FDE='true')
|
2021-06-18 22:03:14 +02:00
|
|
|
get_user_input || return $?
|
|
|
|
# in: CPU_VENDOR (optional)
|
|
|
|
# out: CPU_VENDOR
|
|
|
|
get_cpu_vendor || return $?
|
|
|
|
|
|
|
|
# in: FS
|
|
|
|
# out: FS_DEFAULT_MOUNT_OPTIONS
|
2021-11-13 13:56:47 +01:00
|
|
|
get_default_mount_options || return $?
|
2021-06-18 22:03:14 +02:00
|
|
|
# in: FS
|
2021-06-22 13:52:41 +02:00
|
|
|
# out: FS_ADDITIONAL_MOUNT_OPTIONS
|
2021-11-13 13:56:47 +01:00
|
|
|
get_additional_mount_options || return $?
|
2021-06-18 22:03:14 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
# in: TARGET_BLOCK_DEVICE, BOOT_FIRMWARE
|
2021-06-18 22:03:14 +02:00
|
|
|
# out: BOOT_PART, LUKS_PART
|
|
|
|
partition || return $?
|
2021-11-13 13:56:47 +01:00
|
|
|
# in: BOOT_FIRMWARE, BOOT_PART, LUKS_PART, FDE, LUKS_PWD, FS
|
|
|
|
# out: LUKS_PART_UUID (if FDE='true'), DATA_PART
|
2021-06-18 22:03:14 +02:00
|
|
|
format || return $?
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
# Combine default and additional mount options
|
|
|
|
# out: FS_MOUNT_OPTIONS
|
|
|
|
{
|
|
|
|
TMP1=("${FS_DEFAULT_MOUNT_OPTIONS[@]}" "${FS_ADDITIONAL_MOUNT_OPTIONS[@]}") || return $?
|
|
|
|
# Join array elements by ","
|
|
|
|
join_by ',' TMP1 FS_MOUNT_OPTIONS || return $?
|
|
|
|
}
|
2021-06-18 22:03:14 +02:00
|
|
|
|
2021-06-22 16:34:46 +02:00
|
|
|
mount_partitions || return $?
|
2021-06-18 22:03:14 +02:00
|
|
|
|
2021-11-13 13:56:47 +01:00
|
|
|
# in: BOOT_FIRMWARE, PACSTRAP_INTERACTIVE (optional)
|
2021-06-18 22:03:14 +02:00
|
|
|
run_pacstrap || return $?
|
|
|
|
# in: FS
|
|
|
|
run_genfstab || return $?
|
|
|
|
|
|
|
|
# in: HOSTNAME, FQDN (optional), STATIC_IP (optional), IPV6_CAPABLE (optional)
|
|
|
|
config_hostname_and_hosts || return $?
|
|
|
|
# in: USERNAME, USER_PWD, ROOT_PWD (optional)
|
|
|
|
user_and_pwd || return $?
|
|
|
|
|
|
|
|
sudo arch-chroot /mnt mkinitcpio -P || return $?
|
2021-11-13 13:56:47 +01:00
|
|
|
# in: TARGET_BLOCK_DEVICE, FDE, LUKS_PART_UUID
|
|
|
|
bootloader || return $?
|
2021-06-18 22:03:14 +02:00
|
|
|
|
2021-11-13 13:56:47 +01:00
|
|
|
if [ "${LEAVE_MOUNTED}" = 'true' ]; then
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Leaving partitions below /mnt mounted and '"${DATA_PART}"' opened.'
|
2021-06-18 22:03:14 +02:00
|
|
|
else
|
|
|
|
sudo umount -R /mnt || return $?
|
2021-11-13 13:56:47 +01:00
|
|
|
if [ "${FDE}" = 'true' ] ; then
|
|
|
|
sudo cryptsetup luksClose "$(basename "${DATA_PART}")" || return $?
|
|
|
|
fi
|
2021-06-18 22:03:14 +02:00
|
|
|
fi
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Finished installation without errors!'
|
2021-06-18 22:03:14 +02:00
|
|
|
}
|
2021-04-29 20:25:30 +02:00
|
|
|
|
|
|
|
function check_network() {
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Sending ping to wikipedia.de ...'
|
2021-05-13 20:39:25 +02:00
|
|
|
ping -c 1 wikipedia.de >/dev/null || {
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Pleas set up network access.'
|
2021-04-29 20:25:30 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 10:11:00 +02:00
|
|
|
function system_time() {
|
|
|
|
# Use timedatectl(1) to ensure the system clock is accurate
|
|
|
|
timedatectl set-ntp true
|
|
|
|
}
|
|
|
|
|
2021-04-29 20:25:30 +02:00
|
|
|
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:
|
2021-05-13 20:39:25 +02:00
|
|
|
findmnt /run/archiso/cowspace >/dev/null || {
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Not on live medium, did not increase cowspace!'
|
2021-04-29 20:25:30 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Increasing cowspace partition of live medium ...'
|
2021-05-03 17:38:10 +02:00
|
|
|
sudo mount -o remount,size=2G /run/archiso/cowspace || return $?
|
2021-04-29 20:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_user_input() {
|
2021-05-02 14:28:28 +02:00
|
|
|
# @post
|
2021-11-13 13:56:47 +01:00
|
|
|
# BOOT_FIRMWARE: 'uefi' | 'bios'
|
|
|
|
# FS: 'BTRFS' | 'EXT4' | 'F2FS'
|
|
|
|
# FS_BTRFS_SUBVOL_LAYOUT: 'root_only' | '@root@home'
|
2021-04-29 20:25:30 +02:00
|
|
|
# HOSTNAME
|
|
|
|
# USERNAME, USER_PWD
|
2021-11-13 13:56:47 +01:00
|
|
|
# FDE: 'true' | 'false'
|
|
|
|
# LUKS_PWD: only set if FDE='true'
|
2021-04-29 20:25:30 +02:00
|
|
|
|
|
|
|
get_block_devices_with_size || return $?
|
2021-06-22 14:02:25 +02:00
|
|
|
single_choice_if_empty TARGET_BLOCK_DEVICE 'Select target device for installation' BLOCK_DEVICE_SIZES || return $?
|
2021-04-29 20:25:30 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
if [ "${BOOT_FIRMWARE}" = 'autodetect' ]; then
|
2021-06-22 14:02:25 +02:00
|
|
|
# Detect boot firmware type: https://askubuntu.com/a/162573
|
2021-05-13 20:39:25 +02:00
|
|
|
|
|
|
|
# Check exit code; if 0 EFI, else BIOS.
|
|
|
|
# "-q": tell grep to output nothing
|
2021-06-22 13:52:41 +02:00
|
|
|
if dmesg | grep -q 'EFI v'; then
|
|
|
|
echo 'Detected EFI boot.'
|
|
|
|
BOOT_FIRMWARE='uefi'
|
2021-05-13 20:39:25 +02:00
|
|
|
else
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Detected BIOS boot'
|
|
|
|
BOOT_FIRMWARE='bios'
|
2021-05-13 20:39:25 +02:00
|
|
|
fi
|
|
|
|
|
2021-06-22 16:34:46 +02:00
|
|
|
else # If $BOOT_FIRMWARE is empty: Let user select BIOS type
|
|
|
|
TMP1=('uefi' 'Newer mainboards' \
|
|
|
|
'bios' 'Legacy BIOS on older mainboards')
|
2021-06-22 14:02:25 +02:00
|
|
|
single_choice_if_empty BOOT_FIRMWARE 'Select your bios type' TMP1 || return $?
|
2021-05-13 20:39:25 +02:00
|
|
|
fi
|
2021-04-29 20:25:30 +02:00
|
|
|
|
2021-06-22 16:34:46 +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-06-22 14:02:25 +02:00
|
|
|
single_choice_if_empty FS 'Select filesystem to use' TMP1 || return $?
|
2021-04-29 20:25:30 +02:00
|
|
|
|
2021-06-22 16:34:46 +02:00
|
|
|
if [ "${FS}" = 'BTRFS' ]; then
|
|
|
|
TMP1=('root_only' 'Just one subvolume for "/".' \
|
|
|
|
'@root@home' 'Two subvolumes @ and @home. This configuration allows usage of "Timeshift".')
|
|
|
|
single_choice_if_empty FS_BTRFS_SUBVOL_LAYOUT 'Select your preferred subvolume layout' TMP1 || return $?
|
|
|
|
fi
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
ask_user_if_empty HOSTNAME 'Enter hostname:' || return $?
|
|
|
|
ask_user_if_empty USERNAME 'Enter username:' || return $?
|
2021-04-29 20:25:30 +02:00
|
|
|
|
|
|
|
if [ -z "${USER_PWD}" ]; then
|
2021-06-22 13:52:41 +02:00
|
|
|
ask_user_if_empty USER_PWD 'Enter a user password:' || return $?
|
|
|
|
ask_user_if_empty USER_PWD2 'Please enter the password again:' || return $?
|
2021-06-22 17:13:52 +02:00
|
|
|
# shellcheck disable=SC2153
|
2021-04-29 20:25:30 +02:00
|
|
|
[[ "${USER_PWD}" == "${USER_PWD2}" ]] || {
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Passwords did not match';
|
2021-04-29 20:25:30 +02:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
fi
|
2021-11-13 13:56:47 +01:00
|
|
|
|
|
|
|
TMP1=('true' 'Yes' 'false' 'No')
|
|
|
|
single_choice_if_empty FDE 'Shall Full-Disk-Encryption be enabled?' TMP1 || return $?
|
|
|
|
|
|
|
|
if [ "${FDE}" = 'true' ] && [ -z "${LUKS_PWD}" ]; then
|
2021-06-22 13:52:41 +02:00
|
|
|
ask_user_if_empty LUKS_PWD 'Enter a disk encryption password:' || return $?
|
|
|
|
ask_user_if_empty LUKS_PWD2 'Please enter the password again:' || return $?
|
2021-06-22 17:13:52 +02:00
|
|
|
# shellcheck disable=SC2153
|
2021-04-29 20:25:30 +02:00
|
|
|
[[ "${LUKS_PWD}" == "${LUKS_PWD2}" ]] || {
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Passwords did not match';
|
2021-04-29 20:25:30 +02:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-30 21:42:12 +02:00
|
|
|
function get_default_mount_options() {
|
2021-05-02 14:28:28 +02:00
|
|
|
# @pre
|
|
|
|
# FS
|
|
|
|
# @post
|
2021-04-30 21:42:12 +02:00
|
|
|
# FS_DEFAULT_MOUNT_OPTIONS (array)
|
|
|
|
|
|
|
|
FS_DEFAULT_MOUNT_OPTIONS=()
|
|
|
|
|
|
|
|
case "${FS}" in
|
|
|
|
BTRFS)
|
2021-05-25 22:01:48 +02:00
|
|
|
# "compress=lzo": archwiki -> Btrfs#Compression
|
|
|
|
# "compress=zstd:1":
|
|
|
|
# -> https://btrfs.wiki.kernel.org/index.php/Compression#What_are_the_differences_between_compression_methods.3F
|
|
|
|
# -> https://fedoraproject.org/wiki/Changes/BtrfsTransparentCompression#Q:_Why_use_zstd:1_specifically.3F
|
|
|
|
#
|
2021-04-30 21:42:12 +02:00
|
|
|
# "Enable compression (better performance, longer flash lifespan)"
|
2021-05-25 22:01:48 +02:00
|
|
|
FS_DEFAULT_MOUNT_OPTIONS+=('compress=zstd:1')
|
2021-04-30 21:42:12 +02:00
|
|
|
;;
|
|
|
|
EXT4)
|
|
|
|
# https://wiki.archlinux.org/index.php/Ext4#Enabling_metadata_checksums
|
2021-05-03 16:24:25 +02:00
|
|
|
# If the CPU supports SSE 4.2, make sure the crc32c_intel kernel module is loaded
|
2021-04-30 21:42:12 +02:00
|
|
|
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')
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 16:34:46 +02:00
|
|
|
echo 'Filesystem '"${FS}"' not yet supported!'
|
2021-04-30 21:42:12 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
function get_additional_mount_options() {
|
2021-05-02 14:28:28 +02:00
|
|
|
# @pre
|
|
|
|
# FS
|
|
|
|
# @post
|
2021-06-22 13:52:41 +02:00
|
|
|
# FS_ADDITIONAL_MOUNT_OPTIONS (array)
|
2021-04-30 21:42:12 +02:00
|
|
|
|
|
|
|
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-06-22 13:52:41 +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-06-22 13:52:41 +02:00
|
|
|
TMP1=('noatime' 'Don'\''t write file/folder access times' 'on')
|
2021-04-30 21:42:12 +02:00
|
|
|
;;
|
|
|
|
F2FS)
|
2021-06-22 13:52:41 +02:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
TMP1=('noatime' 'Don'\''t write file/folder access times' 'on')
|
2021-04-30 21:42:12 +02:00
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 16:34:46 +02:00
|
|
|
echo 'Filesystem '"${FS}"' not yet supported!'
|
2021-04-30 21:42:12 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-22 14:02:25 +02:00
|
|
|
multi_choice_if_empty FS_ADDITIONAL_MOUNT_OPTIONS 'Select mount options' TMP1 || return $?
|
2021-04-30 21:42:12 +02:00
|
|
|
}
|
|
|
|
|
2021-06-22 16:34:46 +02:00
|
|
|
function mount_partitions() {
|
|
|
|
# @pre
|
|
|
|
# FS, FS_BTRFS_SUBVOL_LAYOUT, FS_MOUNT_OPTIONS, DATA_PART, BOOT_PART
|
|
|
|
|
|
|
|
if [ "${FS}" = 'BTRFS' ]; then
|
|
|
|
case "${FS_BTRFS_SUBVOL_LAYOUT}" in
|
|
|
|
'root_only')
|
|
|
|
# Nothing special; same steps as for a regular FS
|
|
|
|
echo 'Mounting data partition with options: '"${FS_MOUNT_OPTIONS}"
|
|
|
|
sudo mount -o "${FS_MOUNT_OPTIONS}" "${DATA_PART}" /mnt || return $?
|
|
|
|
;;
|
|
|
|
'@root@home')
|
|
|
|
# Timeshift BTRFS subvol layout:
|
|
|
|
# https://github.com/teejee2008/timeshift#supported-system-configurations
|
|
|
|
|
|
|
|
# Mount top level subvolume
|
|
|
|
sudo mount -o subvolid=5 "${DATA_PART}" /mnt || return $?
|
|
|
|
# Create subvolumes @ and @home
|
|
|
|
sudo btrfs subvolume create /mnt/@ || return $?
|
|
|
|
sudo btrfs subvolume create /mnt/@home || return $?
|
|
|
|
# List the created subvolumes
|
|
|
|
sudo btrfs subvolume list /mnt || return $?
|
|
|
|
# Umount the top level subvolume
|
|
|
|
sudo umount -R /mnt || return $?
|
|
|
|
|
|
|
|
echo 'Mounting @ and @home subvolumes with options: '"${FS_MOUNT_OPTIONS}"
|
2021-06-22 17:13:52 +02:00
|
|
|
sudo mount -o 'subvol=@,'"${FS_MOUNT_OPTIONS}" "${DATA_PART}" /mnt || return $?
|
2021-06-22 16:34:46 +02:00
|
|
|
sudo mkdir /mnt/home || return $?
|
2021-06-22 17:13:52 +02:00
|
|
|
sudo mount -o 'subvol=@home,'"${FS_MOUNT_OPTIONS}" "${DATA_PART}" /mnt/home || return $?
|
2021-06-22 16:34:46 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'BTRFS subvolume layout '"${FS_BTRFS_SUBVOL_LAYOUT}"' not supported!'
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo 'Mounting data partition with options: '"${FS_MOUNT_OPTIONS}"
|
|
|
|
sudo mount -o "${FS_MOUNT_OPTIONS}" "${DATA_PART}" /mnt || return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo 'Mounting boot partition ...'
|
|
|
|
sudo mkdir /mnt/boot || return $?
|
|
|
|
sudo mount "${BOOT_PART}" /mnt/boot || return $?
|
|
|
|
}
|
|
|
|
|
2021-05-01 18:25:17 +02:00
|
|
|
function run_pacstrap() {
|
2021-05-02 14:28:28 +02:00
|
|
|
# @pre
|
2021-06-22 13:52:41 +02:00
|
|
|
# BOOT_FIRMWARE
|
2021-11-13 13:56:47 +01:00
|
|
|
# PACSTRAP_INTERACTIVE: optional, 'true'
|
2021-05-02 14:28:28 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Running pacstrap ...'
|
2021-05-05 12:11:09 +02:00
|
|
|
PKGS=("${ADDITIONAL_PKGS[@]}")
|
2021-05-02 15:08:20 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
case "${BOOT_FIRMWARE}" in
|
2021-05-01 18:25:17 +02:00
|
|
|
uefi)
|
2021-05-13 20:23:32 +02:00
|
|
|
PKGS+=('de-p1st-base')
|
2021-05-01 18:25:17 +02:00
|
|
|
;;
|
|
|
|
bios)
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Not yet implemented'
|
2021-05-01 18:25:17 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Not yet implemented!'
|
2021-05-01 18:25:17 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-05-02 15:08:20 +02:00
|
|
|
|
2021-05-13 20:12:57 +02:00
|
|
|
# If CPU_VENDOR is not empty, then
|
|
|
|
if [ -n "${CPU_VENDOR}" ]; then
|
|
|
|
case "${CPU_VENDOR}" in
|
|
|
|
amd)
|
|
|
|
PKGS+=('de-p1st-ucode-amd')
|
|
|
|
;;
|
|
|
|
intel)
|
|
|
|
PKGS+=('de-p1st-ucode-intel')
|
|
|
|
;;
|
|
|
|
none)
|
|
|
|
PKGS+=('de-p1st-ucode-placeholder')
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Invalid option: '"${CPU_VENDOR}"
|
2021-05-13 20:12:57 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2021-05-04 21:01:22 +02:00
|
|
|
local args=()
|
2021-11-13 13:56:47 +01:00
|
|
|
if [ "${PACSTRAP_INTERACTIVE}" = 'true' ]; then
|
2021-05-04 21:01:22 +02:00
|
|
|
args+=('-i') # run interactively
|
|
|
|
fi
|
|
|
|
args+=('/mnt')
|
|
|
|
|
|
|
|
sudo pacstrap "${args[@]}" "${PKGS[@]}" || return $?
|
2021-05-01 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_genfstab() {
|
2021-05-02 14:28:28 +02:00
|
|
|
# @pre
|
|
|
|
# FS
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Generating fstab ...'
|
2021-05-01 18:25:17 +02:00
|
|
|
local fstab
|
|
|
|
fstab="$(genfstab -U /mnt)"
|
|
|
|
|
|
|
|
case "${FS}" in
|
|
|
|
BTRFS)
|
|
|
|
# Remove "subvolid=..." mount option but leave "subvol=..." mount option
|
2021-06-22 13:52:41 +02:00
|
|
|
fstab=$(printf '%s' "${fstab}" | sed 's/,subvolid=[^,\s]\+//') || return $?
|
2021-05-01 18:25:17 +02:00
|
|
|
# Check if fstab does still contain subvolid mount option
|
2021-06-22 13:52:41 +02:00
|
|
|
if printf '%s' "${fstab}" | grep -q 'subvolid='; then
|
|
|
|
echo 'This should not happen!'
|
2021-05-01 18:25:17 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
EXT4)
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
F2FS)
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 16:34:46 +02:00
|
|
|
echo 'Filesystem '"${FS}"' not yet supported!'
|
2021-05-01 18:25:17 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
printf '%s' "${fstab}" | sudo tee /mnt/etc/fstab >/dev/null || return $?
|
2021-05-01 18:25:17 +02:00
|
|
|
}
|
|
|
|
|
2021-05-02 16:13:39 +02:00
|
|
|
function config_hostname_and_hosts() {
|
|
|
|
# @pre
|
|
|
|
# HOSTNAME
|
2021-11-13 13:56:47 +01:00
|
|
|
# FQDN: optional, e.g. sub.domain.de
|
|
|
|
# STATIC_IP: optional, e.g. 93.133.433.133
|
|
|
|
# IPV6_CAPABLE: optional, 'true'
|
2021-05-02 16:13:39 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Set hostname ...'
|
2021-05-03 17:38:10 +02:00
|
|
|
echo "${HOSTNAME}" | sudo tee /mnt/etc/hostname >/dev/null || return $?
|
2021-05-02 16:13:39 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Create hosts file ...'
|
2021-05-02 16:13:39 +02:00
|
|
|
# If the system has a permanent IP address, it should be used instead of 127.0.1.1.
|
|
|
|
# * https://wiki.archlinux.org/index.php/Installation_guide#Network_configuration
|
|
|
|
|
|
|
|
# Desirable entries IPv4/IPv6:
|
|
|
|
# * https://man.archlinux.org/man/hosts.5#EXAMPLES
|
|
|
|
|
|
|
|
# If FQDN not given, use $HOSTNAME.localdomain instead
|
|
|
|
FQDN="${FQDN:="${HOSTNAME}.localdomain"}"
|
|
|
|
# If STATIC_IP not given, use 127.0.1.1 instead
|
2021-11-11 19:01:19 +01:00
|
|
|
STATIC_IP="${STATIC_IP:=127.0.1.1}"
|
2021-05-02 16:13:39 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo '# The following lines are desirable for IPv4 capable hosts
|
2021-05-02 16:13:39 +02:00
|
|
|
127.0.0.1 localhost
|
|
|
|
# 127.0.1.1 is often used for the FQDN of the machine
|
2021-06-22 13:52:41 +02:00
|
|
|
'"${STATIC_IP} ${FQDN} ${HOSTNAME}" | sudo tee /mnt/etc/hosts >/dev/null || return $?
|
2021-05-02 16:13:39 +02:00
|
|
|
|
2021-11-13 13:56:47 +01:00
|
|
|
if [ "${IPV6_CAPABLE}" = 'true' ]; then
|
2021-06-22 13:52:41 +02:00
|
|
|
echo '
|
2021-05-02 16:13:39 +02:00
|
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
|
|
ff02::1 ip6-allnodes
|
2021-06-22 13:52:41 +02:00
|
|
|
ff02::2 ip6-allrouters' | sudo tee -a /mnt/etc/hosts >/dev/null || return $?
|
2021-05-02 16:13:39 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-02 21:43:50 +02:00
|
|
|
function user_and_pwd() {
|
2021-05-03 13:26:54 +02:00
|
|
|
# @pre
|
|
|
|
# USERNAME
|
|
|
|
# USER_PWD
|
|
|
|
# ROOT_PWD (optional)
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Adding user and changing shell to /bin/zsh ...'
|
2021-05-02 21:43:50 +02:00
|
|
|
# -m: create home
|
|
|
|
# -U: Create a group with the same name as the user, and add the user to this group.
|
2021-05-03 17:38:10 +02:00
|
|
|
sudo arch-chroot /mnt useradd -m -s /usr/bin/zsh -g wheel "${USERNAME}" || return $?
|
|
|
|
sudo arch-chroot /mnt chsh -s /usr/bin/zsh || return $?
|
2021-05-02 21:43:50 +02:00
|
|
|
|
|
|
|
# If ROOT_PWD is not given, the use USER_PWD for root user
|
|
|
|
ROOT_PWD="${ROOT_PWD:="${USER_PWD}"}"
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
printf '%s:%s' "${USERNAME}" "${USER_PWD}" | sudo chpasswd --root /mnt || return $?
|
|
|
|
printf '%s:%s' "root" "${ROOT_PWD}" | sudo chpasswd --root /mnt || return $?
|
2021-05-02 21:43:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:12:27 +02:00
|
|
|
function bootloader() {
|
|
|
|
# @pre
|
|
|
|
# TARGET_BLOCK_DEVICE
|
2021-11-13 13:56:47 +01:00
|
|
|
# FDE: 'true' | 'false'
|
|
|
|
# LUKS_PART_UUID: required if FDE='true'
|
2021-05-03 16:12:27 +02:00
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Installing grub ...'
|
|
|
|
case "${BOOT_FIRMWARE}" in
|
2021-05-03 16:12:27 +02:00
|
|
|
uefi)
|
|
|
|
# portable fallback efi name for grub:
|
|
|
|
# * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming
|
|
|
|
# * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi
|
2021-05-03 17:38:10 +02:00
|
|
|
sudo arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable || return $?
|
2021-05-03 16:12:27 +02:00
|
|
|
;;
|
|
|
|
bios)
|
2021-05-03 17:38:10 +02:00
|
|
|
sudo arch-chroot /mnt grub-install --target=i386-pc "${TARGET_BLOCK_DEVICE}" || return $?
|
2021-05-03 16:12:27 +02:00
|
|
|
;;
|
|
|
|
*)
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Not yet implemented!'
|
2021-05-03 16:12:27 +02:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-22 13:52:41 +02:00
|
|
|
echo 'Generating /boot/grub/grub.cfg ...'
|
2021-06-18 17:51:45 +02:00
|
|
|
{
|
2021-11-13 13:56:47 +01:00
|
|
|
case "${FDE}" in
|
|
|
|
true)
|
|
|
|
# /etc/default/grub is managed by Holo. Therefore we should not manually modify it.
|
|
|
|
# Instead, we create a holosript which writes $LUKS_PART_UUID into GRUB_CMDLINE_LINUX of /etc/default/grub
|
|
|
|
{
|
|
|
|
# Assert
|
|
|
|
grep --quiet '^GRUB_CMDLINE_LINUX=""$' < /mnt/etc/default/grub || return
|
|
|
|
|
|
|
|
# Use filename .../20- for the holoscript so that it gets executed after the one from de-p1st-grub
|
|
|
|
local holoScriptDir=/mnt/usr/share/holo/files/20-de-p1st-installer/etc/default/
|
|
|
|
# The holoscript shall contain one 'sed "..."' command
|
|
|
|
sudo mkdir -p "${holoScriptDir}" || return $?
|
|
|
|
sudo echo '#!/bin/sh
|
2021-07-05 11:36:19 +02:00
|
|
|
sed "s|^GRUB_CMDLINE_LINUX=\"\"\$|GRUB_CMDLINE_LINUX=\"cryptdevice=/dev/disk/by-uuid/'"${LUKS_PART_UUID}"':crypt\"|"' \
|
2021-11-13 13:56:47 +01:00
|
|
|
| sudo tee "${holoScriptDir}"/grub.holoscript || return $?
|
|
|
|
sudo chmod 0544 "${holoScriptDir}"/grub.holoscript || return $?
|
|
|
|
}
|
|
|
|
# Then we apply the holoscript
|
|
|
|
sudo arch-chroot /mnt holo apply --force file:/etc/default/grub || return $?
|
|
|
|
;;
|
|
|
|
false)
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'Invalid option: '"${FDE}"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-18 17:51:45 +02:00
|
|
|
# And finally run grub-mkconfig
|
|
|
|
sudo arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg || return $?
|
|
|
|
}
|
2021-05-03 13:26:54 +02:00
|
|
|
}
|
|
|
|
|
2021-04-29 20:25:30 +02:00
|
|
|
main "$@"
|