V8.00.000.2025.06.17
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
108
.archive/func/0000_partitioning.sh
Normal file
108
.archive/func/0000_partitioning.sh
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
# SPDX-Version: 3.0
|
||||
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
|
||||
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
|
||||
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-FileType: SOURCE
|
||||
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
|
||||
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
|
||||
# SPDX-PackageName: CISS.debian.installer
|
||||
# SPDX-Security-Contact: security@coresecret.eu
|
||||
|
||||
#######################################
|
||||
# Function that generates each partition on each device according to the chosen recipe string.
|
||||
# Globals:
|
||||
# ERR_PARTITIONTBL
|
||||
# HMP_RECIPE_DEV_PARTITIONS
|
||||
# HMP_UUID_PARTITION
|
||||
# RECIPE_STRING
|
||||
# RECIPE_TABLE
|
||||
# VAR_RECIPE_TABLE
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
partitioning() {
|
||||
### REMINDER
|
||||
# HashMap : "${!HMP_RECIPE_DEV_PARTITIONS[@]}"
|
||||
# ${DEVICE}: "${HMP_RECIPE_DEV_PARTITIONS[$DEVICE]}"
|
||||
|
||||
declare var_dev var_partition var_partition_number
|
||||
|
||||
### Iterate through each device.
|
||||
for var_dev in "${!HMP_RECIPE_DEV_PARTITIONS[@]}"; do
|
||||
var_partition_number=${HMP_RECIPE_DEV_PARTITIONS[${var_dev}]}
|
||||
|
||||
### All current data for the respective device will be deleted.
|
||||
blkdiscard /dev/"${var_dev}"
|
||||
do_log "info" "false" "Partition table of '/dev/${var_dev}' discarded."
|
||||
|
||||
if [[ ${VAR_RECIPE_TABLE} == "gpt" ]]; then
|
||||
|
||||
parted -s /dev/"${var_dev}" mklabel gpt
|
||||
do_log "info" "false" "Partition table '${VAR_RECIPE_TABLE}' of '/dev/${var_dev}' generated."
|
||||
|
||||
elif [[ ${VAR_RECIPE_TABLE} == "mbr" ]]; then
|
||||
|
||||
parted -s /dev/"${var_dev}" mklabel mbr
|
||||
do_log "info" "false" "Partition table '${VAR_RECIPE_TABLE}' of '/dev/${var_dev}' generated."
|
||||
|
||||
else
|
||||
|
||||
do_log "fatal" "false" "No valid partition table chosen. String was '${VAR_RECIPE_TABLE}'. Exiting setup."
|
||||
exit "${ERR_PARTITIONTBL}"
|
||||
|
||||
fi
|
||||
|
||||
### Iterate through each partition on the current device.
|
||||
for (( var_partition=1; var_partition<=var_partition_number; var_partition++ )); do
|
||||
#for var_partition in $(seq 1 "${var_partition_number}"); do
|
||||
|
||||
### Generate variables for the current partition.
|
||||
declare begin_var="recipe_${RECIPE_STRING}_dev_${var_dev}_${var_partition}_begin"
|
||||
declare end_var="recipe_${RECIPE_STRING}_dev_${var_dev}_${var_partition}_end"
|
||||
declare bootable_var="recipe_${RECIPE_STRING}_dev_${var_dev}_${var_partition}_bootable"
|
||||
declare primary_var="recipe_${RECIPE_STRING}_dev_${var_dev}_${var_partition}_primary"
|
||||
declare filesystem_var="recipe_${RECIPE_STRING}_dev_${var_dev}_${var_partition}_filesystem_version"
|
||||
|
||||
### Initialise variables.
|
||||
declare BEGIN=${!begin_var}
|
||||
declare END=${!end_var}
|
||||
declare BOOTABLE=${!bootable_var}
|
||||
declare PRIMARY=${!primary_var}
|
||||
declare FILESYSTEM=${!filesystem_var}
|
||||
|
||||
### Generate partition.
|
||||
if [[ ${END} == "-1" ]]; then
|
||||
|
||||
parted -s /dev/"${var_dev}" mkpart "${PRIMARY}" "${FILESYSTEM}" "${BEGIN}" 100%
|
||||
do_log "info" "false" "Partition generated: '${var_partition}' | on device '/dev/${var_dev}' | begin: '${BEGIN}' | end: 100 % of remaining disk."
|
||||
|
||||
else
|
||||
|
||||
parted -s /dev/"${var_dev}" mkpart "${PRIMARY}" "${FILESYSTEM}" "${BEGIN}" "${END}"
|
||||
do_log "info" "false" "Partition generated: '${var_partition}' | on device '/dev/${var_dev}' | begin: '${BEGIN}' | end: '${END}'."
|
||||
|
||||
fi
|
||||
|
||||
### Set the bootable flag if necessary.
|
||||
if [[ "${BOOTABLE,,}" == true ]]; then
|
||||
parted -s "/dev/${var_dev}" set "${var_partition}" boot on
|
||||
do_log "info" "false" "Partition: '/dev/${var_dev}${var_partition}' marked as bootable."
|
||||
fi
|
||||
|
||||
if [[ "${PRIMARY,,}" == logical ]]; then
|
||||
parted -s "/dev/${var_dev}" set "${var_partition}" "${FILESYSTEM}" on
|
||||
fi
|
||||
|
||||
### Save UUID of the generated partition
|
||||
# shellcheck disable=SC2155
|
||||
declare UUID=$(blkid -s UUID -o value "/dev/${var_dev}${var_partition}")
|
||||
HMP_UUID_PARTITION["UUID_${var_dev}${var_partition}"]="${UUID}"
|
||||
do_log "info" "false" "Saved in HashMap HMP_UUID_PARTITION: 'UUID_${var_dev}${var_partition}' -> '${HMP_UUID_PARTITION["UUID_${var_dev}${var_partition}"]}'"
|
||||
|
||||
done
|
||||
|
||||
done
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
Reference in New Issue
Block a user