archinstall/test.uefi

237 lines
9.2 KiB
Text
Raw Normal View History

#!/bin/bash
2023-07-26 00:19:33 +00:00
# Konstanten:
declare -A GUIDS=""
GUIDS=([ESP]="c12a7328-f81f-11d2-ba4b-00a0c93ec93b" [USR]="8484680c-9521-48c6-9c11-b0720656f69e" [USRHASH]="77ff5f63-e7b6-4633-acf4-1565b864c0e6" [ROOT]="4f68bce3-e8cd-4db1-96e7-fbcaf984b709")
# Variablen:
DRIVE="/dev/vda"
ESP="512M"
USR="10G"
ROOT_LABEL="root"
USR_LABEL="usr"
ESP_LABEL="EFI"
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Prüfen, ob Drive existiert
CHECK_PARTITION_EXISTENCE_OUTPUT=$(lsblk -pldo NAME | grep -ic "${DRIVE}")
if [[ ${CHECK_PARTITION_EXISTENCE_OUTPUT} -eq 0 ]]; then
echo "Platte existiert nicht, Abbruch!"
exit 1
else
echo "Platte existiert , Weitermachen."
fi
#----------------------------#
# Prüfen, ob Partitionen existieren ung ggf. erstellen
declare -A PARTITIONS_PRESENT=()
CHECK_PARTITIONS_OUTPUT=$(lsblk -plo NAME,PARTTYPE | grep -i "${DRIVE}[0-9]")
CHECK_ESP=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "${GUIDS[ESP]}")
PARTITIONS_PRESENT+=([ESP]="${CHECK_ESP}")
CHECK_USR=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "${GUIDS[USR]}")
PARTITIONS_PRESENT+=([USR]="${CHECK_USR}")
CHECK_USRHASH=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "${GUIDS[USRHASH]}")
PARTITIONS_PRESENT+=([USRHASH]="${CHECK_USRHASH}")
CHECK_ROOT=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "${GUIDS[ROOT]}")
PARTITIONS_PRESENT+=([ROOT]="${CHECK_ROOT}")
echo "ESP: ${CHECK_ESP}, USR: ${CHECK_USR}, USRHASH: ${CHECK_USRHASH}, ROOT: ${CHECK_ROOT}"
if [[ ${PARTITIONS_PRESENT[ROOT]} -eq 1 && ${PARTITIONS_PRESENT[USR]} -eq 1 && ${PARTITIONS_PRESENT[USRHASH]} -eq 1 && ${PARTITIONS_PRESENT[ESP]} -eq 1 ]]; then
echo "Alle Partitionen vorhanden."
elif [[ ${PARTITIONS_PRESENT[ROOT]} -eq 0 && ${PARTITIONS_PRESENT[USR]} -eq 0 && ${PARTITIONS_PRESENT[USRHASH]} -eq 0 && ${PARTITIONS_PRESENT[ESP]} -eq 0 ]]; then
echo "Keine Partition ist vorhanden."
echo "Partitionen werden erstellt."
echo sgdisk -og "${DRIVE}"
echo sgdisk -n 0:0:"+${ESP}" -t 0:"${GUIDS[ESP]}" -c 0:"EFI System Partition" "${DRIVE}"
echo sgdisk -n 0:0:"+${USR}" -t 0:"${GUIDS[USR]}" -c 0:"ArchOS_0.1" "${DRIVE}"
echo sgdisk -n 0:0:+512M -t 0:"${GUIDS[USRHASH]}" -c 0:"ArchOS_0.1" "${DRIVE}"
echo sgdisk -n 0:0:0 -t 0:"${GUIDS[ROOT]}" -c 0:"ArchOS Root" "${DRIVE}"
else
echo " ##################################################################################"
echo " ##################################################################################"
echo " ## _______ _ _ ___________ _ _ ___ _ ______ ##"
echo " ## /\ / ______ \| | | |___ _____| | | | \ | |/ ___ \ ##"
echo " ## / \ | | \/| |_____| | | | | | | | |\ \ | | / \_| ##"
echo " ## / /\ \ | | | | | | | | | | | \ \ | | | ___ ##"
echo " ## / /__\ \ | | | _____ | | | | | | | | \ \ | | | |_ | ##"
echo " ## / ______ \| |_____/\| | | | | | \ \____/ | | \ \| | \___| | ##"
echo " ## /_/ \_\________/|_| |_| |_| \________/|_| \___|\_______| ##"
echo " ## ##"
echo " ##################################################################################"
echo " ##################################################################################"
echo ""
echo " Partitionen teilweise vorhanden."
echo " Fehlende Partitionen:"
for part in "${!PARTITIONS_PRESENT[@]}"; do
2023-07-25 21:30:25 +00:00
if [[ ${PARTITIONS_PRESENT[$part]} -eq 0 ]]; then
case $part in
"ROOT" )
echo " - Root-Partition"
;;
"USR" )
echo " - /usr-Partition"
;;
"USRHASH" )
echo " - /usr-Verity-Partition"
;;
"ESP" )
echo " - ESP-Partition"
;;
esac
fi
done
echo ""
echo " =================================================================================="
echo ""
echo " Alle Partitionen werden neu erstellt!"
echo " Die gesammte Platte ${DRIVE//\/dev\/} wird verwendet!"
echo " =================================================================================="
echo ""
read -r -p " Partitionen trotz der Warnung neu erstellen? (j/N): " confirm_recreate_partitions
if [[ ${confirm_recreate_partitions} == [jJ] ]]; then
echo
echo "Recreate Partitions"
echo sgdisk -og "${DRIVE}"
echo sgdisk -n 0:0:"+${ESP}" -t 0:"${GUIDS[ESP]}" -c 0:"EFI System Partition" "${DRIVE}"
echo sgdisk -n 0:0:"+${USR}" -t 0:"${GUIDS[USR]}" -c 0:"ArchOS_0.1" "${DRIVE}"
echo sgdisk -n 0:0:+512M -t 0:"${GUIDS[USRHASH]}" -c 0:"ArchOS_0.1" "${DRIVE}"
echo sgdisk -n 0:0:0 -t 0:"${GUIDS[ROOT]}" -c 0:"ArchOS Root" "${DRIVE}"
else
echo "Do nothing (Partitions)"
2023-07-26 00:19:33 +00:00
echo "Bitte die fehlenden Partitionen erstellen, um das Script zu benutzen"
for part in "${!PARTITIONS_PRESENT[@]}"; do
if [[ ${PARTITIONS_PRESENT[$part]} -eq 0 ]]; then
case $part in
"ROOT" )
echo " - Root-Partition GUID code: c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
;;
"USR" )
echo " - /usr-Partition GUID code: 8484680c-9521-48c6-9c11-b0720656f69e"
;;
"USRHASH" )
echo " - /usr-Verity-Partition GUID code: 77ff5f63-e7b6-4633-acf4-1565b864c0e6"
;;
"ESP" )
echo " - ESP-Partition GUID code: c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
;;
esac
fi
done
exit 1
fi
fi
# _______ _ _ ___________ _ _ ___ _ ______
# /\ / ______ \| | | |___ _____| | | | \ | |/ ___ \
# / \ | | \/| |_____| | | | | | | | |\ \ | | / \_|
# / /\ \ | | | | | | | | | | | \ \ | | | ___
# / /__\ \ | | | _____ | | | | | | | | \ \ | | | |_ |
# / ______ \| |_____/\| | | | | | \ \____/ | | \ \| | \___| |
#/_/ \_\________/|_| |_| |_| \________/|_| \___|\_______|
#----------------------------#
2023-07-26 01:27:33 +00:00
declare -A INFO_ESP=""
declare -A INFO_USR=""
declare -A INFO_USRHASH=""
declare -A INFO_ROOT=""
INFO_ESP+=([PRESENT]="0")
INFO_USR+=([PRESENT]="0")
INFO_USRHASH+=([PRESENT]="0")
INFO_ROOT+=([PRESENT]="0")
# Check if GUIDS existieren
2023-07-26 11:00:02 +00:00
GUIDS_OUTPUT=$(lsblk -plo PARTN,PARTUUID,PARTTYPE,NAME | grep -i "${DRIVE}" | sed 's/[[:blank:]]\+/ /g')
2023-07-26 01:27:33 +00:00
for guid in "${!GUIDS[@]}"; do
CHECK=$(echo "${GUIDS_OUTPUT}" | grep -ic "${GUIDS[$guid]}")
if [[ ${CHECK} -eq 1 ]]; then
echo "1 Partition existiert."
case $guid in
"ROOT" )
INFO_ROOT+=([PRESENT]="1")
2023-07-26 11:00:02 +00:00
INFO_ROOT+=([PARTUUID]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 2))
INFO_ROOT+=([PARTNUM]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 1))
2023-07-26 01:27:33 +00:00
echo "ROOT: " "${INFO_ROOT[@]}"
;;
"USR" )
INFO_USR+=([PRESENT]="1")
2023-07-26 11:00:02 +00:00
INFO_USR+=([PARTUUID]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 2))
INFO_USR+=([PARTNUM]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 1))
2023-07-26 01:27:33 +00:00
echo "USR: " "${INFO_USR[@]}"
;;
"USRHASH" )
INFO_USRHASH+=([PRESENT]="1")
2023-07-26 11:00:02 +00:00
INFO_USRHASH+=([PARTUUID]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 2))
INFO_USRHASH+=([PARTNUM]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 1))
2023-07-26 01:27:33 +00:00
echo "USRHASH: " "${INFO_USRHASH[@]}"
;;
"ESP" )
INFO_ESP+=([PRESENT]="1")
2023-07-26 11:00:02 +00:00
INFO_ESP+=([PARTUUID]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 2))
INFO_ESP+=([PARTNUM]=$(echo "${GUIDS_OUTPUT}" | grep -i "${GUIDS[$guid]}" | cut -d ' ' -f 1))
2023-07-26 01:27:33 +00:00
echo "ESP: " "${INFO_ESP[@]}"
;;
esac
elif [[ ${CHECK} -gt 1 ]]; then
2023-07-26 11:00:02 +00:00
echo "Mehrere" "${guid}" "Partitionen existieren."
2023-07-26 01:27:33 +00:00
echo "Partition auswählen:"
2023-07-26 11:00:02 +00:00
echo "${GUIDS_OUTPUT}" | sed 's/\([0-9]\)\s\(.{32}\)/\1) \2/g'
2023-07-26 01:27:33 +00:00
else
echo "${guid}" "GUID nicht gefunden."
echo "Abbrechen"
exit 1
fi
done
#----------------------------#
CHECK_FS_EXISTENCE_OUTPUT=$(lsblk -plo NAME,PARTUUID,PARTTYPE,FSTYPE,FSVER | grep -i "${DRIVE}[0-9]")
declare -A INFO_ESP=""
declare -A INFO_USR=""
declare -A INFO_USRHASH=""
declare -A INFO_ROOT=""
CHECK_FS_ESP=$(echo "${CHECK_FS_EXISTENCE_OUTPUT}" | grep -i "${GUIDS[ESP]}" | grep -i "vfat" | grep -ic "fast32")
CHECK_FS_USR=$(echo "${CHECK_FS_EXISTENCE_OUTPUT}" | grep -i "${GUIDS[USR]}" | grep -ic "ext4")
CHECK_FS_USRHASH=$(echo "${CHECK_FS_EXISTENCE_OUTPUT}" | grep -i "${GUIDS[USRHASH]}" | grep -ic "dm_verity_hash")
CHECK_FS_ROOT=$(echo "${CHECK_FS_EXISTENCE_OUTPUT}" | grep -i "${GUIDS[ROOT]}" | grep -ic "ext4")
if [[ ${CHECK_FS_ESP} -eq 0 ]]; then
echo "ESP-Dateisystem existiert nicht."
2023-07-26 00:19:33 +00:00
echo mkfs.vfat -F 32 -n EFI /dev/disk/
else
echo "ESP-Dateisystem existiert."
fi
if [[ ${CHECK_FS_USR} -eq 0 ]]; then
echo "/usr-Dateisystem existiert nicht."
else
echo "/usr-Dateisystem existiert."
fi
if [[ ${CHECK_FS_USRHASH} -eq 0 ]]; then
echo "Dateisystem existiert nicht."
else
echo "Dateisystem existiert."
fi
if [[ ${CHECK_FS_ROOT} -eq 0 ]]; then
echo "Root-Dateisystem existiert nicht."
else
echo "Root-Dateisystem existiert."
fi