2023-12-28 21:37:18 +02:00
|
|
|
#!/bin/bash
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if [ -z $BANAN_ARCH ]; then
|
2024-04-02 12:48:35 +03:00
|
|
|
echo "You must set the BANAN_ARCH environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if [ -z $BANAN_DISK_IMAGE_PATH ]; then
|
2023-11-20 13:55:01 +02:00
|
|
|
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if [ -z $BANAN_BUILD_DIR ]; then
|
2023-11-20 13:55:01 +02:00
|
|
|
echo "You must set the BANAN_BUILD_DIR environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if [[ -z $BANAN_UEFI_BOOT ]]; then
|
|
|
|
echo "You must set the BANAN_UEFI_BOOT environment variable" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z $BANAN_ROOT_DIR ]; then
|
2023-11-20 13:55:01 +02:00
|
|
|
echo "You must set the BANAN_ROOT_DIR environment variable" >&2
|
|
|
|
exit 1
|
2023-12-28 19:13:27 +02:00
|
|
|
fi
|
|
|
|
|
2024-05-20 16:19:29 +03:00
|
|
|
if [ -z $BANAN_CMAKE ]; then
|
|
|
|
echo "You must set the BANAN_CMAKE environment variable" >&2
|
2023-12-28 19:13:27 +02:00
|
|
|
exit 1
|
2024-01-24 14:43:46 +02:00
|
|
|
fi
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
set -u
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
mount_dir="$BANAN_BUILD_DIR/mount"
|
|
|
|
mkdir -p $mount_dir
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
install_grub_legacy() {
|
2024-11-21 20:37:42 +02:00
|
|
|
sudo mount $partition2 "$mount_dir"
|
2024-04-24 01:27:59 +03:00
|
|
|
sudo grub-install \
|
|
|
|
--no-floppy \
|
|
|
|
--target=i386-pc \
|
|
|
|
--modules="normal ext2 multiboot" \
|
2024-11-21 20:37:42 +02:00
|
|
|
--boot-directory="$mount_dir/boot" \
|
|
|
|
$loop_dev
|
|
|
|
sudo mkdir -p "$mount_dir/boot/grub"
|
|
|
|
sudo cp "$BANAN_BUILD_DIR/grub-legacy-boot.cfg" "$mount_dir/boot/grub/grub.cfg"
|
|
|
|
sudo umount "$mount_dir"
|
2024-04-24 01:27:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
install_grub_uefi() {
|
2024-11-21 20:37:42 +02:00
|
|
|
sudo mkfs.fat $partition1 > /dev/null
|
|
|
|
sudo mount $partition1 "$mount_dir"
|
|
|
|
sudo mkdir -p "$mount_dir/EFI/BOOT"
|
|
|
|
sudo "$BANAN_TOOLCHAIN_PREFIX/bin/grub-mkstandalone" -O "$BANAN_ARCH-efi" -o "$mount_dir/EFI/BOOT/BOOTX64.EFI" "boot/grub/grub.cfg=$BANAN_BUILD_DIR/grub-memdisk.cfg"
|
|
|
|
sudo umount "$mount_dir"
|
|
|
|
|
|
|
|
sudo mount $partition2 "$mount_dir"
|
|
|
|
sudo mkdir -p "$mount_dir/boot/grub"
|
|
|
|
sudo cp "$BANAN_BUILD_DIR/grub-uefi.cfg" "$mount_dir/boot/grub/grub.cfg"
|
|
|
|
sudo umount "$mount_dir"
|
2024-04-24 01:27:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
install_banan_legacy() {
|
2024-11-21 20:37:42 +02:00
|
|
|
root_disk_info=$(fdisk -x "$BANAN_DISK_IMAGE_PATH" | tr -s ' ')
|
|
|
|
root_part_guid=$(echo "$root_disk_info" | grep "^$BANAN_DISK_IMAGE_PATH" | head -2 | tail -1 | cut -d' ' -f6)
|
2024-04-24 01:27:59 +03:00
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
installer_build_dir=$BANAN_ROOT_DIR/bootloader/installer/build/$BANAN_ARCH
|
|
|
|
bootloader_elf=$BANAN_BUILD_DIR/bootloader/bios/bootloader
|
2024-04-24 01:27:59 +03:00
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
if [ ! -f $bootloader_elf ]; then
|
2024-04-24 01:27:59 +03:00
|
|
|
echo "You must build the bootloader first" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
if [ ! -d $installer_build_dir ]; then
|
|
|
|
mkdir -p $installer_build_dir
|
|
|
|
cd $installer_build_dir
|
2024-05-20 16:19:29 +03:00
|
|
|
$BANAN_CMAKE -G Ninja ../..
|
2024-04-24 01:27:59 +03:00
|
|
|
fi
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
cd $installer_build_dir
|
2024-04-24 01:27:59 +03:00
|
|
|
ninja
|
|
|
|
|
|
|
|
echo installing bootloader
|
2024-11-21 20:37:42 +02:00
|
|
|
$installer_build_dir/banan_os-bootloader-installer "$bootloader_elf" "$BANAN_DISK_IMAGE_PATH" "$root_part_guid"
|
2024-04-24 01:27:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
install_banan_uefi() {
|
|
|
|
echo "UEFI boot is not supported by the BANAN bootloader" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2023-11-20 13:55:01 +02:00
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if [ $BANAN_BOOTLOADER = "GRUB" ]; then
|
2024-11-21 20:37:42 +02:00
|
|
|
loop_dev=$(sudo losetup --show -fP $BANAN_DISK_IMAGE_PATH || exit 1)
|
|
|
|
partition1=${loop_dev}p1
|
|
|
|
partition2=${loop_dev}p2
|
|
|
|
if [ ! -b $partition1 ] || [ ! -b $partition2 ]; then
|
2024-04-24 01:27:59 +03:00
|
|
|
echo "Failed to probe partitions for banan disk image." >&2
|
2024-11-21 20:37:42 +02:00
|
|
|
sudo losetup -d $loop_dev
|
2024-04-24 01:27:59 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
root_part_info=$(sudo blkid $partition2)
|
|
|
|
|
|
|
|
root_fs_uuid=$(grep -Pwo 'UUID=".*?"' <<< "$root_part_info")
|
|
|
|
root_fs_uuid=${root_fs_uuid:6:36}
|
|
|
|
|
|
|
|
root_part_uuid=$(grep -Pwo 'PARTUUID=".*?"' <<< "$root_part_info")
|
|
|
|
root_part_uuid=${root_part_uuid:10:36}
|
|
|
|
|
|
|
|
cp "$BANAN_TOOLCHAIN_DIR"/grub-*.cfg "$BANAN_BUILD_DIR/"
|
2024-11-21 20:38:50 +02:00
|
|
|
sed -i "s/<ROOT>/PARTUUID=$root_part_uuid/" "$BANAN_BUILD_DIR"/grub-*.cfg
|
2024-11-21 20:37:42 +02:00
|
|
|
sed -i "s/<ROOT_FS>/$root_fs_uuid/" "$BANAN_BUILD_DIR"/grub-*.cfg
|
|
|
|
|
2024-04-24 01:27:59 +03:00
|
|
|
if (($BANAN_UEFI_BOOT)); then
|
|
|
|
install_grub_uefi
|
|
|
|
else
|
|
|
|
install_grub_legacy
|
|
|
|
fi
|
|
|
|
|
2024-11-21 20:37:42 +02:00
|
|
|
sudo losetup -d $loop_dev
|
2024-04-24 01:27:59 +03:00
|
|
|
|
|
|
|
elif [ $BANAN_BOOTLOADER = "BANAN" ]; then
|
|
|
|
if (($BANAN_UEFI_BOOT)); then
|
|
|
|
install_banan_uefi
|
|
|
|
else
|
|
|
|
install_banan_legacy
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Unknown bootloader $BANAN_BOOTLOADER" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|