From 01e8063774b013c1f0d5075618750ae4961b972e Mon Sep 17 00:00:00 2001 From: eshanized Date: Thu, 9 Jan 2025 15:36:35 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20perf:=20add=20exit=20statu?= =?UTF-8?q?s=20checker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/local/bin/snigdhaos-systemd-test | 38 ++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/usr/local/bin/snigdhaos-systemd-test b/usr/local/bin/snigdhaos-systemd-test index 647567d..858484a 100755 --- a/usr/local/bin/snigdhaos-systemd-test +++ b/usr/local/bin/snigdhaos-systemd-test @@ -1,30 +1,48 @@ #!/bin/bash +# Check if bootctl is available +if ! command -v bootctl &>/dev/null; then + echo "Error: bootctl command not found. Unable to determine the current bootloader." + exit 1 +fi + # Get the current bootloader from bootctl status -boot=$(bootctl status | grep -i 'Product' | awk '{printf($2)}') +bootloader=$(bootctl status 2>/dev/null | grep -i 'Product' | awk '{print $2}') -# Check if the bootloader is GRUB -echo "The system is using $boot to boot." +# Provide feedback on the detected bootloader +if [[ -z "$bootloader" ]]; then + echo "Error: Unable to detect the bootloader using bootctl. Please check the system configuration." + exit 1 +fi -# Check if the bootloader is GRUB and install it if necessary -if [[ "$boot" == "GRUB" ]]; then +echo "The system is using $bootloader as the bootloader." + +# Check if the bootloader is GRUB and proceed with installation if necessary +if [[ "$bootloader" == "GRUB" ]]; then echo "GRUB bootloader detected. Installing or reconfiguring GRUB..." # Ensure grub-install exists and is executable - if ! command -v /usr/bin/grub-install &> /dev/null; then + if ! command -v grub-install &>/dev/null; then echo "Error: grub-install command not found. Please install GRUB." exit 1 fi - # Execute the grub-install command - sudo /usr/bin/grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=snigdhaos --disable-shim-lock --removable + # Execute the grub-install command with necessary parameters + sudo grub-install --target=x86_64-efi \ + --efi-directory=/boot/efi \ + --bootloader-id=snigdhaos \ + --disable-shim-lock \ + --removable + # Check the result of the grub-install command if [[ $? -eq 0 ]]; then echo "GRUB installation successful." else - echo "Error: GRUB installation failed." + echo "Error: GRUB installation failed. Please check the logs for more details." exit 1 fi else - echo "The system is not using GRUB as the bootloader. No action taken." + echo "The system is not using GRUB as the bootloader. No action will be taken." fi + +exit 0