Compare commits

..

No commits in common. "9668f9d7616e071a43d7382856860ce2a54dd207" and "9b6fef22eb51a2060b972d2a7b8156235d59de4d" have entirely different histories.

View file

@ -50,8 +50,7 @@ PRINT=(cups)
# Development # Development
DEV=(base-devel "${KERNEL}-headers") DEV=(base-devel "${KERNEL}-headers")
# Netzwerk # Netzwerk
WIFI_BACKEND=(wpa_supplicant) # iwd NET=(iptables-nft firewalld inetutils avahi networkmanager networkmanager-openconnect networkmanager-openvpn networkmanager-pptp networkmanager-vpnc modemmanager) #iwd bind(dig,host,nslookup)
NET=(iptables-nft firewalld inetutils avahi networkmanager networkmanager-openconnect networkmanager-openvpn networkmanager-pptp networkmanager-vpnc "${WIFI_BACKEND[@]}" modemmanager) # bind(dig,host,nslookup)
# Sontiges # Sontiges
BASE=(base) # -sudo BASE=(base) # -sudo
INITRD=(mkinitcpio) # dracut INITRD=(mkinitcpio) # dracut
@ -70,10 +69,7 @@ fi
DRIVE="/dev/vda" DRIVE="/dev/vda"
# disklayout: ESP (512MiB), usr (15GiB), Root (100% - [512MiB + 15GiB]) # disklayout: ESP (512MiB), usr (15GiB), Root (100% - [512MiB + 15GiB])
ESP="512M" ESP="512M"
USR="10G" USR="15G"
ROOT_LABEL="root"
USR_LABEL="usr"
ESP_LABEL="EFI"
#--------------------------# #--------------------------#
@ -87,203 +83,92 @@ ESP_LABEL="EFI"
# /usr /dev/vda2 # /usr /dev/vda2
# (usr-hash) /dev/vda3 # (usr-hash) /dev/vda3
# /(root) /dev/vda4 # /(root) /dev/vda4
#LSBLK_OPTIONEN="NAME,PARTUUID,UUID,PARTTYPE,PARTN,LABEL,MOUNTPOINTS"
# Prüfen ob die Platte existiert
#declare -i CHECK_EXISTENCE_OUTPUT=""
CHECK_EXISTENCE_OUTPUT=$(lsblk -o NAME | grep -c "^${DRIVE//\/dev\/}")
if [[ ${CHECK_EXISTENCE_OUTPUT} -lt 1 ]]; then
echo "Platte existiert nicht, breche ab."
exit 0
fi
RECREATE_PARTITIONS="1"
# Prüfe ob die Platte schon formatiert wurde und die Partitionen da sind
CHECK_PARTITIONS_OUTPUT=$(lsblk -o NAME,PARTTYPE | grep "${DRIVE//\/dev\/}" | grep "\(c12a7328-f81f-11d2-ba4b-00a0c93ec93b\|8484680c-9521-48c6-9c11-b0720656f69e\|77ff5f63-e7b6-4633-acf4-1565b864c0e6\|4f68bce3-e8cd-4db1-96e7-fbcaf984b709\)")
CHECK_ROOT=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "4f68bce3-e8cd-4db1-96e7-fbcaf984b709")
CHECK_ESP=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "c12a7328-f81f-11d2-ba4b-00a0c93ec93b")
CHECK_USR=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "8484680c-9521-48c6-9c11-b0720656f69e")
CHECK_USRHASH=$(echo "${CHECK_PARTITIONS_OUTPUT}" | grep -c "77ff5f63-e7b6-4633-acf4-1565b864c0e6")
if [[ ${CHECK_ESP} -eq 1 && ${CHECK_USR} -eq 1 && ${CHECK_USRHASH} -eq 1 && ${CHECK_ROOT} -eq 1 ]]; then
read -r "Alle Partitionen sind vorhanden. Trotzdem neu erstellen? (j/N): " confirm
if [[ "${confirm}" == [jJ] ]];then
echo "Partitionen werden neu erstellt"
RECREATE_PARTITIONS="1"
else
echo "Partitionen werden nicht neu erstellt"
RECREATE_PARTITIONS="0"
fi
fi
if [[ ${RECREATE_PARTITIONS} -eq 1 ]]; then
# Reset Partition Table # Reset Partition Table
sgdisk -og "${DRIVE}" sgdisk -og "${DRIVE}"
# EFI System Partition erstellen # Create EFI System Partition
sgdisk -n 0:0:+"${ESP}" -t 0:c12a7328-f81f-11d2-ba4b-00a0c93ec93b -c 0:"EFI System Partition" "${DRIVE}" sgdisk -n 0:0:+"${ESP}" -t 0:c12a7328-f81f-11d2-ba4b-00a0c93ec93b -c 0:"EFI System Partition" "${DRIVE}"
#sgdisk -n 0:0:+512M -t 0:ef00 -c 0:ESP "${DRIVE}" #sgdisk -n 0:0:+512M -t 0:ef00 -c 0:ESP "${DRIVE}"
# usr-Partition erstellen # Create usr-Partition
sgdisk -n 0:0:+"${USR}" -t 0:8484680c-9521-48c6-9c11-b0720656f69e -c 0:"ArchOS_0.1" "${DRIVE}" sgdisk -n 0:0:+"${USR}" -t 0:8484680c-9521-48c6-9c11-b0720656f69e -c 0:"Usr-Partition" "${DRIVE}"
# usrhash-Partition erstellen # Create usrhash-Partition
sgdisk -n 0:0:+512M -t 0:77ff5f63-e7b6-4633-acf4-1565b864c0e6 -c 0:"ArchOS_0.1" "${DRIVE}" sgdisk -n 0:0:+512M -t 0:77ff5f63-e7b6-4633-acf4-1565b864c0e6 -c 0:"usrhash-Partition" "${DRIVE}"
# Root-Partition erstellen # Create Root-Partition
sgdisk -n 0:0:0 -t 0:4f68bce3-e8cd-4db1-96e7-fbcaf984b709 -c 0:"ArchOS Root" "${DRIVE}" sgdisk -n 0:0:0 -t 0:4f68bce3-e8cd-4db1-96e7-fbcaf984b709 -c 0:"System Root" "${DRIVE}"
# UUIDs finden
UUID_ESP=""
UUID_ROOT=""
UUID_USR=""
UUID_USRHASH=""
# Anzahl der Partitionen ermitteln
DRIVE_NAME=${DRIVE//\/dev\/}
declare -i NUMBER_OF_PARTITIONS;
NUMBER_OF_PARTITIONS=$(lsblk | grep -c "${DRIVE_NAME}[0-9]")
declare -i UNKNOWN_PARTITIONS
NOCASEMATCH_UNSET=$(shopt -u | grep -c nocasematch)
if [[ $NOCASEMATCH_UNSET ]]; then
shopt -s nocasematch
fi fi
# # UUIDs finden for (( i=NUMBER_OF_PARTITIONS; i > 0 ; i=i-1 )) ; do
# UUID_ESP="" OUTPUT=$(sgdisk -i "${i}" "${DRIVE}")
# UUID_ROOT="" PARTITION_EXISTS=$(echo "${OUTPUT}" | grep -c "GUID")
# UUID_USR="" if [[ "${PARTITION_EXISTS}" != "0" ]]; then
# UUID_USRHASH="" GUID_CODE=$(echo "${OUTPUT}" | grep "GUID code:" | cut -d ' ' -f 4)
UUID=$(echo "${OUTPUT}" | grep "unique GUID:" | cut -d ' ' -f 4)
# # Anzahl der Partitionen ermitteln case $GUID_CODE in
# DRIVE_NAME=${DRIVE//\/dev\/}
# declare -i NUMBER_OF_PARTITIONS;
# NUMBER_OF_PARTITIONS=$(lsblk | grep -c "${DRIVE_NAME}[0-9]")
# declare -i UNKNOWN_PARTITIONS
# NOCASEMATCH_UNSET=$(shopt -u | grep -c nocasematch)
# if [[ $NOCASEMATCH_UNSET ]]; then
# shopt -s nocasematch
# fi
# for (( i=NUMBER_OF_PARTITIONS; i > 0 ; i=i-1 )) ; do
# OUTPUT=$(sgdisk -i "${i}" "${DRIVE}")
# PARTITION_EXISTS=$(echo "${OUTPUT}" | grep -c "GUID")
# if [[ "${PARTITION_EXISTS}" != "0" ]]; then
# GUID_CODE=$(echo "${OUTPUT}" | grep "GUID code:" | cut -d ' ' -f 4)
# UUID=$(echo "${OUTPUT}" | grep "unique GUID:" | cut -d ' ' -f 4)
# case $GUID_CODE in
# "8484680c-9521-48c6-9c11-b0720656f69e" )
# echo "USR-Partition, UUID: ${UUID}"
# UUID_USR=${UUID}
# ;;
# "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" )
# echo "ESP-Partition, UUID: ${UUID}"
# UUID_ESP=${UUID}
# ;;
# "4f68bce3-e8cd-4db1-96e7-fbcaf984b709" )
# echo "Root-Partition, UUID: ${UUID}"
# UUID_ROOT=${UUID}
# ;;
# "77ff5f63-e7b6-4633-acf4-1565b864c0e6" )
# echo "Usrhash-Partition, UUID: ${UUID}"
# UUID_USRHASH=${UUID}
# ;;
# * )
# echo "Unbekannte Partition"
# UNKNOWN_PARTITIONS="${UNKNOWN_PARTITIONS}+1"
# ;;
# esac
# else
# echo "no partition found"
# fi
# NUMBER_OF_PARTITIONS="${NUMBER_OF_PARTITIONS}-1"
# done
# if [[ $NOCASEMATCH_UNSET ]]; then
# shopt -u nocasematch
# fi
# if [[ "${UNKNOWN_PARTITIONS}" -gt "0" ]]; then
# if [[ "${UNKNOWN_PARTITIONS}" -gt "1" ]]; then
# read -r -p "Mehrere Partitionen unbekannt. Trotzdem fortfahren? (j/N): " confirm
# [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
# else
# read -r -p "Eine Partition unbekannt. Trotzdem fortfahren? (j/N): " confirm
# [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
# fi
# fi
# # Großbuchstaben in UUIDs zu kleinbuchstaben umwandeln
# UUID_ESP="${UUID_ESP@L}"
# UUID_ROOT="${UUID_ROOT@L}"
# UUID_USR="${UUID_USR@L}"
# UUID_USRHASH="${UUID_USRHASH@L}"
# Informationen aus den Partitionen auslesen
PARTITIONEN_OUTPUT=$(lsblk -o NAME,PARTTYPE,PARTUUID,UUID,PARTN,LABEL,MOUNTPOINTS | grep "${DRIVE//\/dev\/}[0-9]" | sed 's/[[:blank:]]\+/ /g')
echo "PARTITIONEN_OUTPUT:"
echo "${PARTITIONEN_OUTPUT}"
PARTITION_NUMBERS=$(echo "${PARTITIONEN_OUTPUT}" | cut -d ' ' -f 5)
echo "Partition-Numbers:"
echo "${PARTITION_NUMBERS}"
declare -A ROOT_PARTITION=()
declare -A ESP_PARTITION=()
declare -A USR_PARTITION=()
declare -A USRHASH_PARTITION=()
for i in ${PARTITION_NUMBERS}; do
PARTN=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 5)
PARTUUID=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 3)
PARTTYPE=$(echo "${PARTITIONEN_OUTPUT}" | grep "${DRIVE//\/dev\/}${i}" | cut -d ' ' -f 2)
case $PARTTYPE in
"c12a7328-f81f-11d2-ba4b-00a0c93ec93b" )
echo "ESP"
ESP_PARTITION+=([PARTUUID]="${PARTUUID}")
ESP_PARTITION+=([PARTTYPE]="${PARTTYPE}")
ESP_PARTITION+=([PARTNUMBER]="${PARTN}")
;;
"8484680c-9521-48c6-9c11-b0720656f69e" ) "8484680c-9521-48c6-9c11-b0720656f69e" )
echo "USR" echo "USR-Partition, UUID: ${UUID}"
USR_PARTITION+=([PARTUUID]="${PARTUUID}") UUID_USR=${UUID}
USR_PARTITION+=([PARTTYPE]="${PARTTYPE}")
USR_PARTITION+=([PARTNUMBER]="${PARTN}")
;; ;;
"77ff5f63-e7b6-4633-acf4-1565b864c0e6") "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" )
echo "USRHASH" echo "ESP-Partition, UUID: ${UUID}"
USRHASH_PARTITION+=([PARTUUID]="${PARTUUID}") UUID_ESP=${UUID}
USRHASH_PARTITION+=([PARTTYPE]="${PARTTYPE}")
USRHASH_PARTITION+=([PARTNUMBER]="${PARTN}")
;; ;;
"4f68bce3-e8cd-4db1-96e7-fbcaf984b709" ) "4f68bce3-e8cd-4db1-96e7-fbcaf984b709" )
echo "ROOT" echo "Root-Partition, UUID: ${UUID}"
ROOT_PARTITION+=([PARTUUID]="${PARTUUID}") UUID_ROOT=${UUID}
ROOT_PARTITION+=([PARTTYPE]="${PARTTYPE}") ;;
ROOT_PARTITION+=([PARTNUMBER]="${PARTN}") "77ff5f63-e7b6-4633-acf4-1565b864c0e6" )
echo "Usrhash-Partition, UUID: ${UUID}"
UUID_USRHASH=${UUID}
;; ;;
* ) * )
echo "Unknown" echo "Unbekannte Partition"
UNKNOWN_PARTITIONS="${UNKNOWN_PARTITIONS}+1"
;; ;;
esac esac
else
echo "no partition found"
fi
NUMBER_OF_PARTITIONS="${NUMBER_OF_PARTITIONS}-1"
done done
# Prüfen,ob die Dateisysteme schon korrekt sind if [[ $NOCASEMATCH_UNSET ]]; then
FILESYSTEM_OUTPUT=$(lsblk -o NAME,FSTYPE,FSVER,PARTUUID | grep "${DRIVE//\/dev\/}[0-9]") shopt -u nocasematch
CHECK_FS_ESP=$(echo "${FILESYSTEM_OUTPUT}" | grep "${ESP_PARTITION["PARTUUID"]}" | grep -i "vfat" | grep -i "fat32" | grep -c -i "${ESP_LABEL}") fi
CHECK_FS_USR=$(echo "${FILESYSTEM_OUTPUT}" | grep "${USR_PARTITION["PARTUUID"]}" | grep -i "ext4" | grep -c -i "${USR_LABEL}")
CHECK_FS_USRHASH=$(echo "${FILESYSTEM_OUTPUT}" | grep "${USRHASH_PARTITION["PARTUUID"]}" | grep -c -i "dm_verity_hash")
CHECK_FS_ROOT=$(echo "${FILESYSTEM_OUTPUT}" | grep "${ROOT_PARTITION["PARTUUID"]}" | grep -i "ext4" | grep -c -i "${ROOT_LABEL}")
RECREATE_FILESYSTEMS="0" if [[ "${UNKNOWN_PARTITIONS}" > "0" ]]; then
if [[ ${CHECK_FS_ESP} -eq 1 && ${CHECK_FS_USR} -eq 1 && ${CHECK_FS_USRHASH} -eq 1 && ${CHECK_FS_ROOT} -eq 1 ]]; then if [[ "${UNKNOWN_PARTITIONS}" > "1" ]]; then
echo "Alles vorhanden" read -r -p "Mehrere Partitionen unbekannt. Trotzdem fortfahren? (j/N): " confirm
read -r "Alle Dateisysteme vorhanden. Trotzdem neu erstellen? (j/N): " confirm [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
if [[ ${confirm} == [jJ] ]]; then
echo "Dateisysteme werden neuerstellt."
RECREATE_FILESYSTEMS="1"
else else
echo "Dateisysteme werden nicht neu erstellt." read -r -p "Eine Partition unbekannt. Trotzdem fortfahren? (j/N): " confirm
RECREATE_FILESYSTEMS="0" [[ "${confirm}" == [jJ] ]] || echo "Abbrechen" && exit 0
fi fi
fi fi
if [[ (${CHECK_ESP} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${ESP_PARTITION["PARTUUID"]} ]]; then # Großbuchstaben in UUIDs zu kleinbuchstaben umwandeln
echo "Erstelle ESP" UUID_ESP="${UUID_ESP@L}"
mkfs.vfat -n "${ESP_LABEL}" -F 32 "/dev/disk/by-partuuid/${ESP_PARTITION["PARTUUID"]}" UUID_ROOT="${UUID_ROOT@L}"
fi UUID_USR="${UUID_USR@L}"
UUID_USRHASH="${UUID_USRHASH@L}"
if [[ (${CHECK_USR} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${USR_PARTITION["PARTUUID"]} ]]; then mkfs.vfat -n EFI -F 32 "/dev/disk/by-partuuid/${UUID_ESP}"
echo "Erstelle USR" mkfs.ext4 -L usr "/dev/disk/by-partuuid/${UUID_USR}"
mkfs.ext4 -L "${USR_LABEL}" "/dev/disk/by-partuuid/${USR_PARTITION["PARTUUID"]}" mkfs.ext4 -L root "/dev/disk/by-partuuid/${UUID_ROOT}"
fi
if [[ (${CHECK_ROOT} -eq 0 || ${RECREATE_FILESYSTEMS} -eq 1) && -n ${ROOT_PARTITION["PARTUUID"]} ]]; then
echo "Erstelle ROOT"
mkfs.ext4 -L "${ROOT_LABEL}" "/dev/disk/by-partuuid/${ROOT_PARTITION["PARTUUID"]}"
fi
mount /dev/disk/by-label/root /mnt mount /dev/disk/by-label/root /mnt
mkdir -p /mnt/{boot,usr} mkdir -p /mnt/{boot,usr}
@ -433,23 +318,6 @@ initrd /initramfs-${KERNEL}.img
options quiet splash rw options quiet splash rw
EOF EOF
#--------------------------#
###############
# Veritysetup #
###############
echo "veritysetup"
OUTPUT_VERITYSETUP=$(veritysetup format /dev/vda2 /dev/vda3)
ROOT_HASH=$(echo "${OUTPUT_VERITYSETUP}" | grep "Root hash" | sed 's/[[:blank:]]\+/ /g' | cut -d ' ' -f 3)
ROOTHASH_TEIL="${ROOT_HASH:0:32}"
lsblk
#sgdisk -u (partnum /USR):(64 char roothash)(UUID_USRHASH)
#--------------------------# #--------------------------#
################## ##################