️ perf(_blank): Avoid Redundant Checks

This commit is contained in:
Eshan Roy
2024-11-19 09:49:27 +05:30
parent c5e493c577
commit e4f46751d0

View File

@@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
echo echo
echo "Reinstalling Grub..." echo "Reinstalling GRUB..."
echo echo
# Initializing variables
Online=0 Online=0
file_boolean=0 file_boolean=0
workdir="/tmp"
# Check system connectivity
function check_connectivity() { function check_connectivity() {
local test_ip local test_ip="8.8.8.8"
local test_count local test_count=1
test_ip="8.8.8.8"
test_count=1
if ping -c ${test_count} ${test_ip} > /dev/null; then if ping -c ${test_count} ${test_ip} > /dev/null; then
echo "System Online!" echo "System Online!"
@@ -21,48 +21,79 @@ function check_connectivity() {
echo "System Offline!" echo "System Offline!"
Online=0 Online=0
fi fi
} }
# Check if the custom GRUB file exists
function check_file() { function check_file() {
file="/usr/local/share/snigdhaos/grub/grub" local file="/usr/local/share/snigdhaos/grub/grub"
if [[ -f $file ]];then if [[ -f "$file" ]]; then
echo $file " Found." echo "$file Found."
file_boolean=1 file_boolean=1
else else
echo $file " Not Found!" echo "$file Not Found!"
file_boolean=0 file_boolean=0
fi fi
} }
# Check connectivity and file existence
check_connectivity check_connectivity
check_file check_file
if [ $Online -eq 1 ] ; then # If online, download the latest grub file
echo "getting latest /etc/default/grub from github" if [ $Online -eq 1 ]; then
# shellcheck disable=SC2086 echo "Getting latest /etc/default/grub from GitHub..."
# shellcheck disable=SC2154 # Ensure the workdir exists
sudo wget https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-updater/master/grub -O $workdir/etc/default/grub mkdir -p "$workdir/etc"
# Download the GRUB config
sudo wget -q https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-updater/master/grub -O "$workdir/etc/default/grub"
if [[ $? -ne 0 ]]; then
echo "Error: Failed to download the GRUB configuration."
exit 1
fi
fi fi
if [ $Online -eq 0 ] && [ $file_boolean -eq 1 ] ; then # If offline, copy the local GRUB file
if [ $Online -eq 0 ] && [ $file_boolean -eq 1 ]; then
sudo cp /usr/local/share/snigdhaos/grub/grub /etc/default/grub sudo cp /usr/local/share/snigdhaos/grub/grub /etc/default/grub
echo "Copied Grub From System!" echo "Copied GRUB configuration from the system!"
fi fi
if [ $Online -eq 0 ] && [ $file_boolean -eq 0 ] ; then # If offline and the file doesn't exist, exit with a message
if [ $Online -eq 0 ] && [ $file_boolean -eq 0 ]; then
echo "Run this script once you are back online" echo "Run this script once you are back online"
exit 1
fi fi
# Remove the old kernel install package (if needed)
echo
echo "Removing old kernel-install-mkinitcpio..."
sudo pacman -R --noconfirm kernel-install-mkinitcpio sudo pacman -R --noconfirm kernel-install-mkinitcpio
echo # Ensure that /boot/efi is mounted (required for GRUB installation)
echo "Updating your /boot/grub/grub.cfg to apply the grub default file..." if ! mount | grep -q "/boot/efi"; then
echo echo "Error: /boot/efi is not mounted. Please mount it and try again."
exit 1
fi
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=snigdhaos # Reinstall GRUB bootloader
echo
echo "Reinstalling GRUB bootloader..."
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=snigdhaos --removable
if [[ $? -ne 0 ]]; then
echo "Error: GRUB installation failed."
exit 1
fi
# Update GRUB configuration
echo
echo "Updating /boot/grub/grub.cfg..."
sudo grub-mkconfig -o /boot/grub/grub.cfg sudo grub-mkconfig -o /boot/grub/grub.cfg
if [[ $? -ne 0 ]]; then
echo "Error: Failed to update grub.cfg."
exit 1
fi
# Final message
echo echo
echo "Make sure you installed snigdhaos-grub-theme" echo "GRUB reinstallation complete!"
echo echo "Make sure you have installed snigdhaos-grub-theme."