Commit 1f67e310 authored by Ophélie Gagnard's avatar Ophélie Gagnard

test.sh: Initial commit. Function to retrieve the partition names and UUIDs.

parent 497dafb8
#!/bin/bash
get_partition () {
# Return the path of the desired partition.
# Exit and display an error if it finds 0 or several results.
#
# This function should be called with exactly one argument: the desired partition type.
# Its behavior is undefined otherwise.
#echo argument = $1 # DEBUG 100
desired_partitions=$(fdisk -l | grep "$1")
#echo desired_partitions = # DEBUG 100
#echo $desired_partitions # DEBUG 100
desired_partition_count=$(echo -e "$desired_partitions" | wc | awk '{print $1}')
#echo desired_partition_count = # DEBUG 100
#echo $desired_partition_count # DEBUG 100
if [ -z "$desired_partitions" ]; then
echo -e "No partition of type $1 (should be 1)".
exit
elif [ "$desired_partition_count" -ne 1 ] ; then
echo -e "$desired_partition_count partitions of type $1 (should be 1)."
exit
else
#desired_partition_path=$(echo -e "$desired_partitions" | awk '{print $1}')
echo -e "$desired_partitions" | awk '{print $1}'
fi
}
root_partition_path=$(get_partition "Linux filesystem")
efi_partition_path=$(get_partition "EFI System")
root_partition_id=$(findmnt -fn -o UUID $root_partition_path)
efi_partition_id=$(findmnt -fn -o UUID $efi_partition_path)
echo root_partition_path = $root_partition_path
echo efi_partition_path = $efi_partition_path
echo root_partition_id = $root_partition_id
echo efi_partition_id = $efi_partition_id
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment