mirror of
https://codeberg.org/privacy1st/arch
synced 2024-12-23 01:16:04 +01:00
installer script: work in progress (5)
This commit is contained in:
parent
a7aa52184f
commit
c41ef5c9ce
@ -1,11 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# load config
|
# load config
|
||||||
source installer.cfg || { exit 1; }
|
source installer.cfg || { exit 1; }
|
||||||
|
|
||||||
# load functions
|
# load functions
|
||||||
source lib/util.sh || { exit 1; }
|
source lib/util.sh || { exit 1; }
|
||||||
source lib/user-input.sh || { exit 1; }
|
source lib/user-input.sh || { exit 1; }
|
||||||
|
source lib/block-device.sh || { exit 1; }
|
||||||
|
|
||||||
|
|
||||||
function check_network() {
|
function check_network() {
|
||||||
@ -159,6 +160,7 @@ function main() {
|
|||||||
get_default_mount_options || return $?
|
get_default_mount_options || return $?
|
||||||
choose_mount_options || return $?
|
choose_mount_options || return $?
|
||||||
|
|
||||||
|
partition "${TARGET_BLOCK_DEVICE}" "$BIOS_TYPE"
|
||||||
# TODO: use FS_DEFAULT_MOUNT_OPTIONS and FS_MOUNT_OPTIONS in combination
|
# TODO: use FS_DEFAULT_MOUNT_OPTIONS and FS_MOUNT_OPTIONS in combination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,10 @@ LUKS_PWD=test
|
|||||||
|
|
||||||
KERNEL=linux
|
KERNEL=linux
|
||||||
|
|
||||||
# TARGET_BLOCK_DEVICE=/dev/sda
|
TARGET_BLOCK_DEVICE=/dev/sda
|
||||||
|
BOOT_PART_SIZE=500 # MiB
|
||||||
FS=BTRFS
|
FS=BTRFS
|
||||||
|
FS_MOUNT_OPTIONS=('noatime')
|
||||||
|
|
||||||
CPU_VENDOR=none
|
CPU_VENDOR=none
|
||||||
BIOS_TYPE=uefi
|
BIOS_TYPE=uefi
|
||||||
# FS_MOUNT_OPTIONS=()
|
|
||||||
|
105
pkg/de-p1st-installer/lib/block-device.sh
Normal file
105
pkg/de-p1st-installer/lib/block-device.sh
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#
|
||||||
|
# lsblk
|
||||||
|
#
|
||||||
|
# -d, --nodeps Do not print holder devices or slaves.
|
||||||
|
# -p, --paths Print full device paths.
|
||||||
|
# -l, --list Produce output in the form of a list.
|
||||||
|
# -n, --noheadings
|
||||||
|
# -x, --sort column
|
||||||
|
|
||||||
|
function get_partitions(){
|
||||||
|
# $1 block-device
|
||||||
|
# return: the following variables:
|
||||||
|
# PARTITIONS (array with one partition per entry)
|
||||||
|
|
||||||
|
# Remove first line of output (which is just the block device $1 itself)
|
||||||
|
# with sed: sed 1d
|
||||||
|
PARTITIONS="$(lsblk -pln -o name "$1" | sed 1d)" || return $?
|
||||||
|
newline_separated_to_array
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_block_devices() {
|
||||||
|
# return: the following variables:
|
||||||
|
# BLOCK_DEVICES (array with one entry for each block device)
|
||||||
|
|
||||||
|
# Get list of devices, one per line
|
||||||
|
BLOCK_DEVICES="$(lsblk -dplnx size -o name | grep -Ev "boot|rpmb|loop" | tac)" || return $?
|
||||||
|
|
||||||
|
newline_separated_to_array BLOCK_DEVICES BLOCK_DEVICES || return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_block_devices_with_size() {
|
||||||
|
# return: the following variables:
|
||||||
|
# BLOCK_DEVICE_SIZES (array with two entries for each block device: device path and device size)
|
||||||
|
|
||||||
|
# Get list of devices and their sizes, one pair per line
|
||||||
|
# Use sed to remove multiple white spaces: sed 's|\s\s*| |'
|
||||||
|
BLOCK_DEVICE_SIZES="$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | sed 's|\s\s*| |' | tac)" || return $?
|
||||||
|
|
||||||
|
newline_to_space BLOCK_DEVICE_SIZES || return $?
|
||||||
|
space_separated_to_array BLOCK_DEVICE_SIZES BLOCK_DEVICE_SIZES || return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function partition() {
|
||||||
|
# $1: target block device
|
||||||
|
# $2: uefi or bios
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "partition requires two args!";
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
for i in "$@"; do
|
||||||
|
if [ -z "$i" ]; then
|
||||||
|
echo "partition: all given args must not be empty";
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# if BOOT_PART_SIZE not given, set to default value
|
||||||
|
"${BOOT_PART_SIZE:='261'}"
|
||||||
|
# if too small, print warning and exit
|
||||||
|
if [ "${BOOT_PART_SIZE}" -lt "261" ]; then
|
||||||
|
echo "BOOT_PART_SIZE should be larger than 260!";
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# As our data partition is encrypted,
|
||||||
|
# we need a separate boot partition!
|
||||||
|
case "$2" in
|
||||||
|
uefi)
|
||||||
|
# EFI boot partition
|
||||||
|
#
|
||||||
|
# Create a partition with fat32 as the file system type and set the
|
||||||
|
# esp flag on it.
|
||||||
|
parted --script "$1" -- mklabel gpt \
|
||||||
|
mkpart ESP fat32 2Mib "${BOOT_PART_SIZE}MiB" \
|
||||||
|
set 1 esp on \
|
||||||
|
mkpart primary "${BOOT_PART_SIZE}MiB" 100% || return $?
|
||||||
|
|
||||||
|
get_partitions "$1" || return $?
|
||||||
|
BOOT_PART="${PARTITIONS[0]}"
|
||||||
|
LUKS_PART="${PARTITIONS[1]}"
|
||||||
|
;;
|
||||||
|
bios)
|
||||||
|
# > On a BIOS/GPT configuration, a BIOS boot partition is required. GRUB embeds its `core.img`
|
||||||
|
# > into this partition.
|
||||||
|
# > For parted set/activate the flag bios_grub on the partition.
|
||||||
|
#
|
||||||
|
# archwiki -> GRUB#GUID_Partition_Table_(GPT)_specific_instructions
|
||||||
|
# https://www.gnu.org/software/grub/manual/grub/html_node/BIOS-installation.html#BIOS-installation
|
||||||
|
parted --script "$1" -- mklabel gpt \
|
||||||
|
mkpart primary 1MiB 2MiB \
|
||||||
|
set 1 bios_grub on \
|
||||||
|
mkpart primary 2MiB "${BOOT_PART_SIZE}MiB" \
|
||||||
|
mkpart primary "${BOOT_PART_SIZE}MiB" 100% || return $?
|
||||||
|
|
||||||
|
get_partitions "$1" || return $?
|
||||||
|
BOOT_PART="${PARTITIONS[2]}"
|
||||||
|
LUKS_PART="${PARTITIONS[3]}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Expected uefi or bios but got $2 instead!"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
@ -36,34 +36,3 @@ function space_separated_to_array() {
|
|||||||
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
|
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
|
||||||
readarray -d " " -t ptr2 < <(printf '%s' "$ptr")
|
readarray -d " " -t ptr2 < <(printf '%s' "$ptr")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function get_block_devices() {
|
|
||||||
# return: the following variables:
|
|
||||||
# BLOCK_DEVICES (array with one entry for each block device)
|
|
||||||
|
|
||||||
# Get list of devices, one per line
|
|
||||||
BLOCK_DEVICES=$(lsblk -dplnx size -o name | grep -Ev "boot|rpmb|loop" | tac)
|
|
||||||
|
|
||||||
newline_separated_to_array BLOCK_DEVICES BLOCK_DEVICES
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_block_devices_with_size() {
|
|
||||||
# return: the following variables:
|
|
||||||
# BLOCK_DEVICE_SIZES (array with two entries for each block device: device path and device size)
|
|
||||||
|
|
||||||
# Get list of devices and their sizes, one pair per line
|
|
||||||
# Use sed to remove multiple white spaces: sed 's|\s\s*| |'
|
|
||||||
BLOCK_DEVICE_SIZES="$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | sed 's|\s\s*| |' | tac)"
|
|
||||||
|
|
||||||
newline_to_space BLOCK_DEVICE_SIZES
|
|
||||||
space_separated_to_array BLOCK_DEVICE_SIZES BLOCK_DEVICE_SIZES
|
|
||||||
|
|
||||||
# # DEBUG
|
|
||||||
# for i in "${BLOCK_DEVICE_SIZES[@]}"; do
|
|
||||||
# echo "<$i>"
|
|
||||||
# done
|
|
||||||
# exit
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user