mirror of
https://github.com/Snigdha-OS/snigdhaos-system-config.git
synced 2025-09-05 20:26:40 +02:00
⚡️ perf(_blank): more consistent variable names and making sure they're properly scoped within functions
This commit is contained in:
@@ -1,59 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Reinstalling GRUB with online check and local fallback mechanism.
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Reinstalling Grub..."
|
echo "Reinstalling Grub..."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
# Define the working directory for storing temporary files (ensure it's set).
|
||||||
|
workdir="${workdir:-/tmp}" # Default to /tmp if $workdir is not set.
|
||||||
|
|
||||||
Online=0
|
Online=0
|
||||||
file_boolean=0
|
file_boolean=0
|
||||||
|
|
||||||
function check_connectivity() {
|
# Function to check if the system has network connectivity
|
||||||
local test_ip
|
check_connectivity() {
|
||||||
local test_count
|
local test_ip="8.8.8.8"
|
||||||
|
local test_count=1
|
||||||
|
|
||||||
test_ip="8.8.8.8"
|
if ping -c "$test_count" "$test_ip" > /dev/null 2>&1; then
|
||||||
test_count=1
|
echo "System is Online."
|
||||||
|
Online=1
|
||||||
if ping -c ${test_count} ${test_ip} > /dev/null; then
|
|
||||||
echo "System Online."
|
|
||||||
Online=1
|
|
||||||
else
|
else
|
||||||
echo "System Offline!"
|
echo "System is Offline!"
|
||||||
Online=0
|
Online=0
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
function check_file() {
|
|
||||||
file="/usr/local/share/snigdhaos/grub/grub"
|
|
||||||
if [[ -f $file ]];then
|
|
||||||
echo $file " exists"
|
|
||||||
file_boolean=1
|
|
||||||
else
|
|
||||||
echo $file " doesn't exist"
|
|
||||||
file_boolean=0
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to check if the required file exists locally
|
||||||
|
check_file() {
|
||||||
|
local file="/usr/local/share/snigdhaos/grub/grub"
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
echo "$file exists."
|
||||||
|
file_boolean=1
|
||||||
|
else
|
||||||
|
echo "$file doesn't exist."
|
||||||
|
file_boolean=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check system connectivity and file existence
|
||||||
check_connectivity
|
check_connectivity
|
||||||
check_file
|
check_file
|
||||||
|
|
||||||
if [ $Online -eq 1 ] ; then
|
# Handle online situation: download the default grub config if online
|
||||||
echo "Downloading Default Grub..."
|
if [ "$Online" -eq 1 ]; then
|
||||||
# shellcheck disable=SC2154
|
echo "Downloading Default Grub..."
|
||||||
sudo wget https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-updater/master/grub -O "$workdir"/etc/default/grub
|
if ! sudo wget -q https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-updater/master/grub -O "$workdir/etc/default/grub"; then
|
||||||
|
echo "Failed to download the default grub file!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $Online -eq 0 ] && [ $file_boolean -eq 1 ] ; then
|
# Handle offline situation: use local grub file if available
|
||||||
sudo cp /usr/local/share/snigdhaos/grub/grub /etc/default/grub
|
if [ "$Online" -eq 0 ] && [ "$file_boolean" -eq 1 ]; then
|
||||||
echo "Copied Grub Locally!"
|
echo "Copying local Grub config..."
|
||||||
|
if ! sudo cp /usr/local/share/snigdhaos/grub/grub /etc/default/grub; then
|
||||||
|
echo "Failed to copy the local grub file!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Local Grub config copied!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $Online -eq 0 ] && [ $file_boolean -eq 0 ] ; then
|
# Handle offline situation with missing local file: notify user
|
||||||
echo "Run this script once you are back online"
|
if [ "$Online" -eq 0 ] && [ "$file_boolean" -eq 0 ]; then
|
||||||
|
echo "Run this script once you are back online."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo grub-mkconfig -o /boot/grub/grub.cfg
|
# Regenerate the grub configuration
|
||||||
|
echo "Regenerating Grub configuration..."
|
||||||
|
if ! sudo grub-mkconfig -o /boot/grub/grub.cfg; then
|
||||||
|
echo "Failed to regenerate Grub configuration!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Task Completed!"
|
echo "Task Completed!"
|
||||||
echo
|
echo
|
||||||
|
Reference in New Issue
Block a user