mirror of
https://github.com/Snigdha-OS/snigdhaos-system-config.git
synced 2025-09-21 20:14:58 +02:00
⚡️ perf(_blank): Avoid Redundant Checks
This commit is contained in:
@@ -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!"
|
||||||
@@ -23,46 +23,77 @@ function check_connectivity() {
|
|||||||
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, download the latest grub file
|
||||||
if [ $Online -eq 1 ]; then
|
if [ $Online -eq 1 ]; then
|
||||||
echo "getting latest /etc/default/grub from github"
|
echo "Getting latest /etc/default/grub from GitHub..."
|
||||||
# shellcheck disable=SC2086
|
# Ensure the workdir exists
|
||||||
# shellcheck disable=SC2154
|
mkdir -p "$workdir/etc"
|
||||||
sudo wget https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-updater/master/grub -O $workdir/etc/default/grub
|
# 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 offline, copy the local GRUB file
|
||||||
if [ $Online -eq 0 ] && [ $file_boolean -eq 1 ]; then
|
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 offline and the file doesn't exist, exit with a message
|
||||||
if [ $Online -eq 0 ] && [ $file_boolean -eq 0 ]; then
|
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."
|
||||||
|
Reference in New Issue
Block a user