2023-07-12 20:37:31 +00:00
|
|
|
#!/bin/bash
|
2023-04-01 00:41:07 +00:00
|
|
|
pushd "${BASH_SOURCE%/*}" > /dev/null;
|
|
|
|
|
2024-03-23 16:29:25 +00:00
|
|
|
source "../Scripts/hooks.sh";
|
2023-11-24 12:59:58 +00:00
|
|
|
source "../Scripts/is-truthy.sh";
|
|
|
|
source "../Scripts/choose-disk.sh";
|
2023-11-28 00:22:48 +00:00
|
|
|
OS_MOUNT_ROOT="${OS_ROOT:-"/mnt"}";
|
2023-11-24 12:59:58 +00:00
|
|
|
OS_DISK="${OS_DISK}";
|
2023-11-28 00:15:53 +00:00
|
|
|
BOOT_LABEL="${BOOT_LABEL:-Boot}";
|
|
|
|
OS_LABEL="${OS_LABEL:-Linux}";
|
|
|
|
SWAP_LABEL="${SWAP_LABEL:-Swap}";
|
2023-12-01 14:59:48 +00:00
|
|
|
BOOT_MOUNTPOINT="${BOOT_MOUNTPOINT:-"/boot"}";
|
2023-07-12 21:30:00 +00:00
|
|
|
SKIP_FORMAT_EFI="${SKIP_FORMAT_EFI}";
|
2023-04-01 00:41:07 +00:00
|
|
|
memory="$(cat /proc/meminfo | awk -F " " '/^MemTotal/ { print $2 }')";
|
2023-08-07 18:33:51 +00:00
|
|
|
swapSize="$(echo "$memory" | awk '{ print int((($1 / 1024 / 1024) * 0.75) + 0.5)}')";
|
2023-04-01 00:41:07 +00:00
|
|
|
|
2023-11-24 12:59:58 +00:00
|
|
|
if [ ! -z "$OS_DISK" ] && [ ! -e "$OS_DISK" ]
|
2023-04-07 16:25:21 +00:00
|
|
|
then
|
2023-11-24 12:59:58 +00:00
|
|
|
OS_DISK="/dev/${OS_DISK}"
|
2023-04-07 16:25:21 +00:00
|
|
|
fi;
|
|
|
|
|
2023-11-24 12:59:58 +00:00
|
|
|
if [ -z "$OS_DISK" ] || [ ! -e "$OS_DISK" ]
|
2023-04-01 11:40:52 +00:00
|
|
|
then
|
2023-11-24 12:59:58 +00:00
|
|
|
chooseDisk OS_DISK "Which disk do you wish to format for installing the OS?";
|
2023-04-01 11:40:52 +00:00
|
|
|
fi;
|
|
|
|
|
2024-03-23 16:29:25 +00:00
|
|
|
function partitionDisk() {
|
|
|
|
{
|
|
|
|
echo "g";
|
|
|
|
|
|
|
|
echo "n";
|
|
|
|
echo "";
|
|
|
|
echo "";
|
|
|
|
echo "+1G";
|
|
|
|
echo "y";
|
|
|
|
echo "t";
|
|
|
|
echo "1";
|
|
|
|
|
|
|
|
echo "n";
|
|
|
|
echo "";
|
|
|
|
echo "";
|
|
|
|
echo "+${SWAP_SIZE}G";
|
|
|
|
echo "y";
|
|
|
|
echo "t";
|
|
|
|
echo "";
|
|
|
|
echo "19";
|
|
|
|
|
|
|
|
echo "n";
|
|
|
|
echo "";
|
|
|
|
echo "";
|
|
|
|
echo "";
|
|
|
|
echo "y";
|
|
|
|
echo "t";
|
|
|
|
echo "";
|
|
|
|
echo "23";
|
|
|
|
|
|
|
|
echo "w";
|
|
|
|
} | fdisk "$OS_DISK";
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:59:58 +00:00
|
|
|
OS_DISK="${OS_DISK}" \
|
|
|
|
SWAP_SIZE="$swapSize" \
|
2024-03-23 16:29:25 +00:00
|
|
|
runHook initializePartitions \
|
|
|
|
partitionDisk;
|
2023-04-01 00:41:07 +00:00
|
|
|
|
2023-06-09 21:31:02 +00:00
|
|
|
while true
|
|
|
|
do
|
2023-11-24 12:59:58 +00:00
|
|
|
disks=($(bash -c "echo $OS_DISK*"));
|
2023-06-09 21:31:02 +00:00
|
|
|
[ "${#disks[@]}" -ge 4 ] && break;
|
|
|
|
done;
|
|
|
|
|
2023-07-12 20:54:50 +00:00
|
|
|
bootDisk="${BOOT_DISK:-"${disks[1]}"}";
|
|
|
|
swapDisk="${SWAP_DISK:-"${disks[2]}"}";
|
|
|
|
linuxDisk="${LINUX_DISK:-"${disks[3]}"}";
|
2023-11-28 00:39:30 +00:00
|
|
|
labels=("$SWAP_LABEL" "$OS_LABEL");
|
2023-04-01 01:30:58 +00:00
|
|
|
|
2023-07-12 21:30:00 +00:00
|
|
|
if ! isTruthy "$SKIP_FORMAT_EFI"
|
|
|
|
then
|
2023-11-28 00:15:53 +00:00
|
|
|
mkfs.fat -F 32 -n "$BOOT_LABEL" "$bootDisk";
|
2023-11-28 00:39:30 +00:00
|
|
|
labels+=("$BOOT_LABEL");
|
2023-07-12 21:30:00 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-28 00:15:53 +00:00
|
|
|
mkswap -L "$SWAP_LABEL" "$swapDisk";
|
|
|
|
mkfs.ext4 -L "$OS_LABEL" -F "$linuxDisk";
|
2023-04-01 01:30:58 +00:00
|
|
|
|
2023-11-28 00:39:30 +00:00
|
|
|
for label in ${labels[*]};
|
|
|
|
do
|
|
|
|
while true;
|
|
|
|
do
|
|
|
|
[ -b "/dev/disk/by-label/$label" ] && break;
|
|
|
|
done;
|
|
|
|
done
|
|
|
|
|
2023-11-28 00:22:48 +00:00
|
|
|
mount "/dev/disk/by-label/$OS_LABEL" "$OS_MOUNT_ROOT";
|
2023-11-28 00:39:30 +00:00
|
|
|
|
|
|
|
if ! isTruthy "$SKIP_FORMAT_EFI"
|
|
|
|
then
|
|
|
|
bootDisk="/dev/disk/by-label/$BOOT_LABEL";
|
|
|
|
fi
|
|
|
|
|
2023-12-01 14:59:48 +00:00
|
|
|
mount --mkdir "$bootDisk" "$OS_MOUNT_ROOT$BOOT_MOUNTPOINT";
|
2023-11-28 00:22:48 +00:00
|
|
|
swapon "/dev/disk/by-label/$SWAP_LABEL";
|
2023-04-01 01:15:32 +00:00
|
|
|
|
2023-08-07 18:29:24 +00:00
|
|
|
if command -v extraMounts
|
|
|
|
then
|
|
|
|
extraMounts;
|
|
|
|
fi;
|
|
|
|
|
2023-04-01 00:41:07 +00:00
|
|
|
popd > /dev/null;
|