This commit is contained in:
hhftechnologies 2024-11-27 18:23:16 +05:30
parent 0016219ca6
commit 7e8a24f699

View file

@ -88,15 +88,58 @@ check_os_version() {
# Function to install dependencies
install_dependencies() {
sudo apt-get update > /dev/null 2>&1
sudo apt-get install -y ca-certificates curl gnupg > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "Dependencies installed $CHECK_MARK"
return 0
else
echo -e "Failed to install dependencies $CROSS_MARK"
local install_output
local update_output
# Update package lists with error handling
echo "Updating package lists..."
update_output=$(sudo apt-get update 2>&1)
if [ $? -ne 0 ]; then
echo -e "Failed to update package lists $CROSS_MARK"
echo "Error output: $update_output"
return 1
fi
# Check if packages are already installed
local missing_packages=()
local packages=("ca-certificates" "curl" "gnupg" "apt-transport-https" "software-properties-common")
for pkg in "${packages[@]}"; do
if ! dpkg -l | grep -q "^ii $pkg "; then
missing_packages+=("$pkg")
fi
done
# If all packages are installed, return success
if [ ${#missing_packages[@]} -eq 0 ]; then
echo -e "All required packages are already installed $CHECK_MARK"
return 0
fi
# Install missing packages
echo "Installing missing packages: ${missing_packages[*]}"
install_output=$(sudo apt-get install -y "${missing_packages[@]}" 2>&1)
if [ $? -ne 0 ]; then
echo -e "Failed to install dependencies $CROSS_MARK"
echo "Error output: $install_output"
return 1
fi
# Verify installation
local failed_packages=()
for pkg in "${missing_packages[@]}"; do
if ! dpkg -l | grep -q "^ii $pkg "; then
failed_packages+=("$pkg")
fi
done
if [ ${#failed_packages[@]} -gt 0 ]; then
echo -e "Failed to install some packages: ${failed_packages[*]} $CROSS_MARK"
return 1
fi
echo -e "Dependencies installed successfully $CHECK_MARK"
return 0
}
# Function to setup Docker repository