First Commit

This commit is contained in:
Daniel Pätzold
2026-01-02 11:24:52 +01:00
commit f48c656997
18 changed files with 999 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
# Fedora Install Pre- Script
#
# SPDX-FileCopyrightText: Daniel Pätzold
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This script is meant to be executed from Fedora install ks.cfg in the pre-section
# It should reside on the Partition named OEMDRV formated as BTRFS or EXT4
# The Location inside the OEMDRV- Partition should be /ks_base_profiles/basic_pre_script.inc
# When running from ks.cfg pre-section, the OEMDRV should be mountet by Anaconda to /mnt/tmp
# It will be run as root and will use sh to execute, the pre-section should look somewhat like this:
# %pre
# /bin/sh /mnt/tmp/ks_base_profiles/basic_pre_script.inc
# %end
# The Script will search for the drive with the Partition OEMDRV on it and
# REMOVE ANY OTHER PARTITIONS ON THAT DRIVE
# As Anacondas scripts are non interactive, it will do so without asking or stopping.
# We need to be root
if [ "$EUID" -ne 0 ]
then echo "* Error: Please run as root"
exit 1
fi
# Usually, the pre section is run in the sh- shell, the OEMDRV will be mountet at /mnt/tmp
# So we need to check if this is the case
FQFILENAME="/mnt/tmp/ks_base_profiles/basic_pre_script.inc"
if [ ! -f ${FQFILENAME} ]; then
echo "* Error finding the expeted Directory/File structure: Missing File"
echo "${FQFILENAME}"
echo "* Please check to run from Kickstart- Installation, or mount the OEMDRV with this File in /mnt/tmp before."
exit 1
fi
# Check if there is a Partition OEMDRV and on which Drive
source /mnt/tmp/system_setup/setup_system.conf
OEMDRVINFO=$(blkid | grep 'LABEL="OEMDRV"')
if [ "${OEMDRVINFO}." == "." ] ; then
echo "* Error: Required partition with label 'OEMDRV' is not found."
echo "It seems like this PC has never been setup to this Domain before."
echo "Please Check your Documentation at"
echo "${INSTALLDOCS}"
echo "on how to create a new setup on this PC"
exit 1
fi
OEMDRVPART=$(echo "${OEMDRVINFO}" | cut -d ':' -f 1)
echo "Found Label OEMDRV on ${OEMDRVPART}"
#Checking which is the Drive that the Partition is on
SYSDRIVE=$(lsblk -l | grep ":0" | while IFS= read -r SYSDRIVETMP; do
SYSDRIVE='/dev/'$(echo "${SYSDRIVETMP}" | cut -d ' ' -f 1)
# echo "Check ${SYSDRIVE}"
if echo "${OEMDRVPART}" | grep -q "${SYSDRIVE}"; then
echo ${SYSDRIVE}
break;
fi
done)
echo "Found Disk for Installation: ${SYSDRIVE} with Partition ${OEMDRVPART}"
#Check if the Drive has a GPT
if [ "$(fdisk -l ${SYSDRIVE} | grep 'type: gpt')." == "." ]; then
echo "* Error: The Drive ${SYSDRIVE} does not look like it has a GPT. Installation cannot proceed."
exit 1
else
echo "The Drive ${SYSDRIVE} contains a GPT."
fi
OEMDRVPARTSHORT=${OEMDRVPART:5}
ALLPARTS=$(lsblk -n -l -o NAME "${SYSDRIVE}" -Q 'TYPE=="part"')
REMPARTS=$(echo "$ALLPARTS" | grep -v "${OEMDRVPARTSHORT}")
if [ "${REMPARTS}." != "." ]; then
echo
echo "The Following Partitions were found and are now going to be deleted:"
# echo "${REMPARTS}"
echo "${REMPARTS}" | while IFS= read -r REMPART; do
# Find the Last Number
PARTNR=""
for (( i=0; i<${#REMPART}; i++ )); do
CHAR="${REMPART:$i:1}"
if [[ "${CHAR}" =~ [0-9] ]]; then
PARTNR+="${CHAR}" # Append if it's a digit
else
PARTNR="" # Reset if a non-digit is encountered
fi
done
echo "${SYSDRIVE}: Part ${PARTNR}"
blkid /dev/${REMPART}
if [ $? -eq 0 ]; then
parted ${SYSDRIVE} rm ${PARTNR}
fi
done
fi
sync