106 lines
3.3 KiB
Bash
106 lines
3.3 KiB
Bash
#!/bin/bash
|
|
# Bash script to install dependencies on Linux
|
|
# Dependencies Installation Script
|
|
|
|
echo -e "\033[36mInstalling BGP Server Dependencies...\033[0m"
|
|
|
|
# Detect OS
|
|
if [ -f /etc/os-release ]; then
|
|
. /etc/os-release
|
|
OS=$NAME
|
|
VER=$VERSION_ID
|
|
else
|
|
echo -e "\033[31mCannot detect OS version\033[0m"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "\033[33mDetected OS: $OS $VER\033[0m"
|
|
|
|
# Function to install Docker
|
|
install_docker() {
|
|
echo -e "\033[33mInstalling Docker...\033[0m"
|
|
|
|
# Remove old versions
|
|
sudo apt-get remove docker docker-engine docker.io containerd runc 2>/dev/null || true
|
|
|
|
# Update package index
|
|
sudo apt-get update
|
|
|
|
# Install prerequisites
|
|
sudo apt-get install -y \
|
|
apt-transport-https \
|
|
ca-certificates \
|
|
curl \
|
|
gnupg \
|
|
lsb-release
|
|
|
|
# Add Docker's official GPG key
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
|
|
# Set up stable repository
|
|
echo \
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
|
|
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
# Install Docker Engine
|
|
sudo apt-get update
|
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
|
|
# Add user to docker group
|
|
sudo usermod -aG docker $USER
|
|
|
|
# Start and enable Docker
|
|
sudo systemctl start docker
|
|
sudo systemctl enable docker
|
|
|
|
echo -e "\033[32m✓ Docker installed successfully\033[0m"
|
|
echo -e "\033[33mNote: You may need to log out and back in for group changes to take effect\033[0m"
|
|
}
|
|
|
|
# Function to install Docker Compose
|
|
install_docker_compose() {
|
|
echo -e "\033[33mInstalling Docker Compose...\033[0m"
|
|
|
|
# Download Docker Compose
|
|
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
|
|
# Make it executable
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
|
|
# Create symbolic link
|
|
sudo ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
|
|
|
|
echo -e "\033[32m✓ Docker Compose installed successfully\033[0m"
|
|
}
|
|
|
|
# Check if Docker is installed
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "\033[31mDocker is not installed\033[0m"
|
|
install_docker
|
|
else
|
|
echo -e "\033[32m✓ Docker is already installed\033[0m"
|
|
fi
|
|
|
|
# Check if Docker Compose is installed
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
echo -e "\033[31mDocker Compose is not installed\033[0m"
|
|
install_docker_compose
|
|
else
|
|
echo -e "\033[32m✓ Docker Compose is already installed\033[0m"
|
|
fi
|
|
|
|
# Make scripts executable
|
|
echo -e "\033[33mMaking scripts executable...\033[0m"
|
|
chmod +x *.sh
|
|
|
|
# Test Docker installation
|
|
echo -e "\033[33mTesting Docker installation...\033[0m"
|
|
if sudo docker run hello-world >/dev/null 2>&1; then
|
|
echo -e "\033[32m✓ Docker is working correctly\033[0m"
|
|
else
|
|
echo -e "\033[31m✗ Docker test failed\033[0m"
|
|
echo -e "\033[33mYou may need to log out and back in, or restart the system\033[0m"
|
|
fi
|
|
|
|
echo -e "\n\033[32mDependencies installation completed!\033[0m"
|
|
echo -e "\033[33mTo start the BGP server, run: ./start-bgp-server.sh\033[0m" |