diff --git a/script.uefi b/script.uefi index 35a0d73..7abb3dc 100755 --- a/script.uefi +++ b/script.uefi @@ -1,7 +1,8 @@ #!/bin/bash ### Konstanten ### -RED=$() +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" [SWAP]="0657fd6d-a4ab-43c4-84e5-0933c84b4f4f") ### DEFAULTS ### @@ -63,9 +64,11 @@ erase () { fi } -# create +# create create () { - case $1 in + local TYPE="$1" + local DEVICE="$2" + case ${TYPE} in "USR") echo "sgdisk -n 0:0:+${USR_SIZE} -t 0:${GUIDS[USR]} -c 0:${USR_LABEL} ${DEVICE}" #sgdisk -n 0:0:+"${USR_SIZE}" -t 0:"${GUIDS[USR]}" -c 0:"${USR_LABEL}" "${DEVICE}" @@ -100,10 +103,8 @@ create () { existing_partitions () { local DEVICE="$1" local TYPE="$2" - echo "1: $1,2: $2" >> temp.log if [[ $# -eq 1 ]] # Genereller test auf Partitionen then - echo "Path 1" >> temp.log ANZAHL_PARTITIONEN_VORHANDEN=$(lsblk -pl "${DEVICE}" | grep -ic "${DEVICE}[0-9]") if [[ ${ANZAHL_PARTITIONEN_VORHANDEN} != 0 ]] then @@ -113,28 +114,8 @@ existing_partitions () { fi elif [[ $# -eq 2 ]] # Test auf eine bestimmte Partition then - echo "Path 2" >> temp.log - case ${TYPE} in - "ESP") - PARTUUID="${GUIDS[ESP]}" - ;; - "ROOT") - PARTUUID="${GUIDS[ROOT]}" - ;; - "USR") - PARTUUID="${GUIDS[USR]}" - ;; - "USRHASH") - PARTUUID="${GUIDS[USRHASH]}" - ;; - "SWAP") - PARTUUID="${GUIDS[SWAP]}" - ;; - *) - die 1 "Unbekannter Partitionstype" - ;; - esac - echo "UUID: ${PARTUUID}" >> temp.log + local PARTUUID="${GUIDS[${TYPE}]}" # Hier ist ein Problem + echo "PARTUUID: ${PARTUUID}" >> temp.log SPEZIFISCHE_PARTITION_VORHANDEN=$(lsblk -o PARTTYPE "${DEVICE}" | grep -ic "${PARTUUID}") if [[ "${SPEZIFISCHE_PARTITION_VORHANDEN}" == 1 ]] then @@ -147,8 +128,41 @@ existing_partitions () { fi } -# format +# find_uuid_for_partition +find_uuid_for_partition () { + local DEVICE="$1" + local TYPE="$2" + if [[ "$(existing_partitions "${DEVICE}" "${TYPE}")" == "yes" ]] + then + uuid=$() + echo "uuid" + else + echo "null" + fi +} + +# partitions_analyse +partitions_analyse () { + local DEVICE="$1" + local RESULT="" + declare -i index="" + index=0 + for type in "${!GUIDS[@]}" + do + index+=1 + uuid=$(find_uuid_for_partition "${DEVICE}" "${type}") + RESULT+="${type}=${uuid}" + if [[ "$index" != "${#GUIDS[@]}" ]] + then + RESULT+=" " + fi + done + echo "${RESULT}" +} + +# format format () { + local DEVICE="$1" if [[ "${FORCE}" == "yes" ]] then erase "${DEVICE}" @@ -157,31 +171,33 @@ format () { EXISTING_PARTITIONS=$(existing_partitions "${DEVICE}") if [[ "${EXISTING_PARTITIONS}" == "no" ]] then - create "TABLE" - create "ESP" - create "USR" - create "ROOT" - create "USRHASH" - create "SWAP" + create "TABLE" "${DEVICE}" + create "ESP" "${DEVICE}" + create "USR" "${DEVICE}" + create "ROOT" "${DEVICE}" + create "USRHASH" "${DEVICE}" + create "SWAP" "${DEVICE}" else read -r -p "Partitionen überschreiben? [N/y]: " ask_overwrite ask_overwrite=${ask_overwrite:="n"} if [[ ${ask_overwrite} == [Nn] ]] then - die 10 "Noch nicht implementiert" - EXISTING_ESP=$(existing_partitions "${DEVICE}" "ESP") - if [[ "${EXISTING_ESP}" == "no" ]] - then - create "ESP" - fi + #die 10 "Noch nicht implementiert" + temp=$(partitions_analyse "${DEVICE}") + echo "${temp}" + #EXISTING_ESP=$(existing_partitions "${DEVICE}" "ESP") + #if [[ "${EXISTING_ESP}" == "no" ]] + #then + # create "ESP" + #fi else erase "${DEVICE}" - create "TABLE" - create "ESP" - create "USR" - create "ROOT" - create "USRHASH" - create "SWAP" + create "TABLE" "${DEVICE}" + create "ESP" "${DEVICE}" + create "USR" "${DEVICE}" + create "ROOT" "${DEVICE}" + create "USRHASH" "${DEVICE}" + create "SWAP" "${DEVICE}" fi fi } @@ -242,8 +258,7 @@ USRHASH_LABEL="${NAME}_${VERSION}" #--------------------------------------# -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" [SWAP]="0657fd6d-a4ab-43c4-84e5-0933c84b4f4f") + #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# @@ -282,4 +297,4 @@ fi # Prüfen, ob das Script mit Root-Rechten ausgeführt wird #(( EUID == 0)) || die 3 "Dieses Script muss mit Root-Privilegien aufgerufen werden" -format \ No newline at end of file +format "${DEVICE}" \ No newline at end of file