️ perf(improve): more robust, handle errors better, and provide clearer feedback to the user

This commit is contained in:
Eshan Roy
2024-11-19 09:38:56 +05:30
parent 73f558aa45
commit 154b6977ee

View File

@@ -1,72 +1,70 @@
#!/bin/bash #!/bin/bash
Online=0 # Function to check internet connectivity
function check_connectivity() { 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" # Try to ping a known IP address to check if the system is online
test_count=1 if ping -c "$test_count" "$test_ip" > /dev/null 2>&1; then
echo -e "\nSystem is Online!\n"
if ping -c ${test_count} ${test_ip} > /dev/null; then Online=1
echo
echo "System Online!"
echo
Online=1
else else
echo echo -e "\nSystem is Offline! Unable to download snigdhaos-keyring.\n"
echo "System Offline! Unable To Download snigdhaos-keyring!" Online=0
echo
Online=0
fi fi
} }
# Run the connectivity check
check_connectivity check_connectivity
if [ $Online -eq 1 ] ; then # Install snigdhaos-keyring if the system is online
echo if [ "$Online" -eq 1 ]; then
echo "Installing snigdhaos-keyring..." echo -e "\nInstalling snigdhaos-keyring...\n"
echo if ! sudo pacman -Sy snigdhaos-keyring --noconfirm; then
sudo pacman -Sy snigdhaos-keyring --noconfirm echo -e "\nError: Failed to install snigdhaos-keyring.\n"
echo exit 1
fi
fi fi
echo # Clean up previous pacman sync databases
echo "Removing prevoius pacman databases at /var/lib/pacman/sync/*" echo -e "\nRemoving previous pacman databases at /var/lib/pacman/sync/*\n"
echo if ! sudo rm -rf /var/lib/pacman/sync/*; then
sudo rm /var/lib/pacman/sync/* echo -e "\nError: Failed to remove pacman sync databases.\n"
echo exit 1
fi
echo # Remove previous GNUPG folder
echo "Removing prevoius /etc/pacman.d/gnupg folder" echo -e "\nRemoving previous /etc/pacman.d/gnupg folder\n"
echo if ! sudo rm -rf /etc/pacman.d/gnupg/*; then
sudo rm -rf /etc/pacman.d/gnupg/* echo -e "\nError: Failed to remove pacman gnupg folder.\n"
echo exit 1
fi
echo # Initialize pacman keys
echo "Initializing pacman keys..." echo -e "\nInitializing pacman keys...\n"
echo if ! sudo pacman-key --init; then
sudo pacman-key --init echo -e "\nError: Failed to initialize pacman keys.\n"
echo exit 1
fi
echo # Populate the keyring
echo "Populating keyring..." echo -e "\nPopulating keyring...\n"
echo if ! sudo pacman-key --populate archlinux; then
sudo pacman-key --populate echo -e "\nError: Failed to populate the keyring.\n"
echo exit 1
fi
echo # Add the Ubuntu keyserver for extra key fetching
echo "Adding Ubuntu keyserver..." echo -e "\nAdding Ubuntu keyserver...\n"
echo echo "keyserver hkp://keyserver.ubuntu.com:80" | sudo tee --append /etc/pacman.d/gnupg/gpg.conf > /dev/null
echo "
keyserver hkp://keyserver.ubuntu.com:80" | sudo tee --append /etc/pacman.d/gnupg/gpg.conf
echo # Synchronize the database
echo "Synchronizing Database..." echo -e "\nSynchronizing Database...\n"
echo if ! sudo pacman -Sy; then
sudo pacman -Sy echo -e "\nError: Failed to synchronize pacman database.\n"
echo exit 1
fi
echo # Completion message
echo "Task Completed!" echo -e "\nTask Completed!\n"
echo