Extract the helpers shared by both install paths
The free-space and full-disk paths each carried verbatim copies of the T2 Mac kernel detection, the credentials JSON heredoc, the identity/ encryption answer files, the dry-run print-and-cleanup block, and the udev settle loops. Pull those into detect_kernel, write_user_files, print_dry_run_files, and wait_for_device, which also removes a subtle rm vs rm -f drift between the two dry-run cleanups. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f79578f2db
commit
4583a0e5e6
1 file changed
+81
-111
@@ -315,6 +315,77 @@ to_gb() {
|
||||
awk -v bytes="$1" 'BEGIN {printf "%.1fGB", bytes/1024/1024/1024}'
|
||||
}
|
||||
|
||||
# T2 Macs need their own kernel for keyboard/wifi drivers.
|
||||
detect_kernel() {
|
||||
if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then
|
||||
echo "linux-t2"
|
||||
else
|
||||
echo "linux"
|
||||
fi
|
||||
}
|
||||
|
||||
# Give udev a moment to create a device node after partitioning.
|
||||
wait_for_device() {
|
||||
local i
|
||||
for i in 1 2 3 4 5; do
|
||||
[[ -b "$1" ]] && return 0
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
# Save the configurator answers the installer consumes: git identity and
|
||||
# encryption choice as plain files, account details as archinstall credentials.
|
||||
write_user_files() {
|
||||
echo "$full_name" >user_full_name.txt
|
||||
echo "$email_address" >user_email_address.txt
|
||||
printf '%s\n' "$encrypt_installation" >user_encrypt_installation.txt
|
||||
|
||||
local password_escaped password_hash_escaped username_escaped
|
||||
password_escaped=$(echo -n "$password" | jq -Rsa)
|
||||
password_hash_escaped=$(echo -n "$password_hash" | jq -Rsa)
|
||||
username_escaped=$(echo -n "$username" | jq -Rsa)
|
||||
|
||||
local credentials_encryption_line=""
|
||||
if [[ $encrypt_installation == true ]]; then
|
||||
credentials_encryption_line=" \"encryption_password\": $password_escaped,"
|
||||
fi
|
||||
|
||||
cat <<-_EOF_ >user_credentials.json
|
||||
{
|
||||
$credentials_encryption_line
|
||||
"root_enc_password": $password_hash_escaped,
|
||||
"users": [
|
||||
{
|
||||
"enc_password": $password_hash_escaped,
|
||||
"groups": [],
|
||||
"sudo": true,
|
||||
"username": $username_escaped
|
||||
}
|
||||
]
|
||||
}
|
||||
_EOF_
|
||||
}
|
||||
|
||||
# Show what a dry run would have written, then leave no trace behind.
|
||||
print_dry_run_files() {
|
||||
echo -e "User Configuration:"
|
||||
cat user_configuration.json
|
||||
|
||||
echo -e "\n\nUser Credentials:"
|
||||
cat user_credentials.json
|
||||
|
||||
echo -e "\n\nUser Full Name:"
|
||||
cat user_full_name.txt
|
||||
|
||||
echo -e "\nUser Email Address:"
|
||||
cat user_email_address.txt
|
||||
|
||||
echo -e "\nDisk Encryption:"
|
||||
cat user_encrypt_installation.txt
|
||||
|
||||
rm -f user_configuration.json user_credentials.json user_full_name.txt user_email_address.txt user_encrypt_installation.txt
|
||||
}
|
||||
|
||||
# Shared error screen for every "can't fit Omarchy here" outcome of the
|
||||
# partition install. Offers the partition tool as the meaningful second
|
||||
# action so users have a way to actually fix the situation.
|
||||
@@ -480,12 +551,7 @@ run_partition_install() {
|
||||
esp_mount_in_target=/efi
|
||||
fi
|
||||
|
||||
# Detect T2 Mac and set appropriate kernel
|
||||
if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then
|
||||
kernel_choice="linux-t2"
|
||||
else
|
||||
kernel_choice="linux"
|
||||
fi
|
||||
kernel_choice=$(detect_kernel)
|
||||
|
||||
local last_part efi_part_num root_part_num
|
||||
last_part=$(lsblk -n -o PARTN "$disk" 2>/dev/null | grep -E '^[0-9]+$' | sort -n | tail -1)
|
||||
@@ -522,13 +588,8 @@ run_partition_install() {
|
||||
sync
|
||||
sleep 2
|
||||
|
||||
local i
|
||||
for i in 1 2 3 4 5; do
|
||||
if [[ -b "$root_partition_device" && -b "$efi_dev" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
wait_for_device "$efi_dev"
|
||||
wait_for_device "$root_partition_device"
|
||||
|
||||
if [[ "$encrypt_installation" == "true" ]]; then
|
||||
step "Setting up LUKS2 on $root_partition_device"
|
||||
@@ -542,10 +603,7 @@ run_partition_install() {
|
||||
|
||||
step "Creating Btrfs filesystem and subvolumes"
|
||||
mkfs.btrfs -f -L OMARCHY "$root_mapper"
|
||||
for i in 1 2 3 4 5; do
|
||||
[[ -b "$root_mapper" ]] && break
|
||||
sleep 1
|
||||
done
|
||||
wait_for_device "$root_mapper"
|
||||
|
||||
mkdir -p /mnt/btrfs-root
|
||||
mount "$root_mapper" /mnt/btrfs-root
|
||||
@@ -568,34 +626,7 @@ run_partition_install() {
|
||||
|
||||
clear
|
||||
|
||||
echo "$full_name" >user_full_name.txt
|
||||
echo "$email_address" >user_email_address.txt
|
||||
printf '%s\n' "$encrypt_installation" >user_encrypt_installation.txt
|
||||
|
||||
local password_escaped password_hash_escaped username_escaped
|
||||
password_escaped=$(echo -n "$password" | jq -Rsa)
|
||||
password_hash_escaped=$(echo -n "$password_hash" | jq -Rsa)
|
||||
username_escaped=$(echo -n "$username" | jq -Rsa)
|
||||
|
||||
local credentials_encryption_line=""
|
||||
if [[ "$encrypt_installation" == "true" ]]; then
|
||||
credentials_encryption_line=" \"encryption_password\": $password_escaped,"
|
||||
fi
|
||||
|
||||
cat <<-_EOF_ >user_credentials.json
|
||||
{
|
||||
$credentials_encryption_line
|
||||
"root_enc_password": $password_hash_escaped,
|
||||
"users": [
|
||||
{
|
||||
"enc_password": $password_hash_escaped,
|
||||
"groups": [],
|
||||
"sudo": true,
|
||||
"username": $username_escaped
|
||||
}
|
||||
]
|
||||
}
|
||||
_EOF_
|
||||
write_user_files
|
||||
|
||||
local luks_uuid_json="null" luks_uuid
|
||||
if [[ "$encrypt_installation" == "true" ]]; then
|
||||
@@ -677,17 +708,7 @@ _EOF_
|
||||
_EOF_
|
||||
|
||||
if $dry; then
|
||||
echo -e "User Configuration:"
|
||||
cat user_configuration.json
|
||||
echo -e "\n\nUser Credentials:"
|
||||
cat user_credentials.json
|
||||
echo -e "\n\nUser Full Name:"
|
||||
cat user_full_name.txt
|
||||
echo -e "\nUser Email Address:"
|
||||
cat user_email_address.txt
|
||||
echo -e "\nDisk Encryption:"
|
||||
cat user_encrypt_installation.txt
|
||||
rm -f user_configuration.json user_credentials.json user_full_name.txt user_email_address.txt user_encrypt_installation.txt
|
||||
print_dry_run_files
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -853,38 +874,7 @@ select_installation "$@"
|
||||
|
||||
clear
|
||||
|
||||
# Save user full name and email address, so the autostart can
|
||||
# set them as OMARCHY_USER_NAME and OMARCHY_USER_EMAIL
|
||||
echo "$full_name" >user_full_name.txt
|
||||
echo "$email_address" >user_email_address.txt
|
||||
|
||||
# Escape username and password for safe inclusion
|
||||
password_escaped=$(echo -n "$password" | jq -Rsa)
|
||||
password_hash_escaped=$(echo -n "$password_hash" | jq -Rsa)
|
||||
username_escaped=$(echo -n "$username" | jq -Rsa)
|
||||
|
||||
if [[ $encrypt_installation == true ]]; then
|
||||
credentials_encryption_line=" \"encryption_password\": $password_escaped,"
|
||||
else
|
||||
credentials_encryption_line=""
|
||||
fi
|
||||
|
||||
cat <<-_EOF_ >user_credentials.json
|
||||
{
|
||||
$credentials_encryption_line
|
||||
"root_enc_password": $password_hash_escaped,
|
||||
"users": [
|
||||
{
|
||||
"enc_password": $password_hash_escaped,
|
||||
"groups": [],
|
||||
"sudo": true,
|
||||
"username": $username_escaped
|
||||
}
|
||||
]
|
||||
}
|
||||
_EOF_
|
||||
|
||||
printf '%s\n' "$encrypt_installation" >user_encrypt_installation.txt
|
||||
write_user_files
|
||||
|
||||
# Setup partition layout
|
||||
disk_size=$(lsblk -bdno SIZE "$disk")
|
||||
@@ -899,12 +889,7 @@ boot_partition_size=$((2 * gib))
|
||||
main_partition_start=$((boot_partition_size + boot_partition_start))
|
||||
main_partition_size=$((disk_size_in_mib - main_partition_start - gpt_backup_reserve))
|
||||
|
||||
# Detect T2 Mac and set appropriate kernel
|
||||
if lspci -nn 2>/dev/null | grep -q "106b:180[12]"; then
|
||||
kernel_choice="linux-t2"
|
||||
else
|
||||
kernel_choice="linux"
|
||||
fi
|
||||
kernel_choice=$(detect_kernel)
|
||||
|
||||
if [[ $encrypt_installation == true ]]; then
|
||||
disk_encryption_config=$(cat <<-_EOF_
|
||||
@@ -914,7 +899,7 @@ if [[ $encrypt_installation == true ]]; then
|
||||
"lvm_volumes": [],
|
||||
"iter_time": 2000,
|
||||
"partitions": [ "8c2c2b92-1070-455d-b76a-56263bab24aa" ],
|
||||
"encryption_password": $password_escaped
|
||||
"encryption_password": $(echo -n "$password" | jq -Rsa)
|
||||
}
|
||||
_EOF_
|
||||
)
|
||||
@@ -1042,20 +1027,5 @@ cat <<-_EOF_ >user_configuration.json
|
||||
_EOF_
|
||||
|
||||
if [[ $1 == "dry" ]]; then
|
||||
echo -e "User Configuration:"
|
||||
cat user_configuration.json
|
||||
|
||||
echo -e "\n\nUser Credentials:"
|
||||
cat user_credentials.json
|
||||
|
||||
echo -e "\n\nUser Full Name:"
|
||||
cat user_full_name.txt
|
||||
|
||||
echo -e "\nUser Email Address:"
|
||||
cat user_email_address.txt
|
||||
|
||||
echo -e "\nDisk Encryption:"
|
||||
cat user_encrypt_installation.txt
|
||||
|
||||
rm user_configuration.json user_credentials.json user_full_name.txt user_email_address.txt user_encrypt_installation.txt
|
||||
print_dry_run_files
|
||||
fi
|
||||
Reference in new issue
Block a user