2024-04-15 21:45:57 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2025-01-16 00:27:16 +00:00
|
|
|
|
# Function to print a header with a description
|
|
|
|
|
print_header() {
|
|
|
|
|
echo "------------------------------------------------------------"
|
|
|
|
|
echo $1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Check if pv is installed, and install it if necessary
|
|
|
|
|
check_and_install_pv() {
|
|
|
|
|
if ! command -v pv &> /dev/null; then
|
|
|
|
|
print_header "Installing Pipe Viewer (pv)"
|
|
|
|
|
sudo apt-get update -y
|
|
|
|
|
sudo apt-get install -y pv
|
|
|
|
|
else
|
|
|
|
|
print_header "Pipe Viewer (pv) is already installed"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to run a command with progress bar if `pv` is available
|
|
|
|
|
run_with_progress() {
|
|
|
|
|
local cmd="$1"
|
|
|
|
|
if command -v pv &> /dev/null; then
|
|
|
|
|
echo "$cmd | pv -l -p -t -e -r"
|
|
|
|
|
else
|
|
|
|
|
echo "Running: $cmd"
|
|
|
|
|
eval "$cmd"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Install required packages for Docker
|
|
|
|
|
print_header "Installing required packages..."
|
|
|
|
|
sudo apt-get update -y
|
|
|
|
|
sudo apt-get install -y \
|
|
|
|
|
apt-transport-https \
|
|
|
|
|
ca-certificates \
|
|
|
|
|
curl \
|
|
|
|
|
gnupg-agent \
|
|
|
|
|
software-properties-common
|
|
|
|
|
|
|
|
|
|
# Add Docker’s official GPG key with progress bar
|
|
|
|
|
check_and_install_pv
|
|
|
|
|
print_header "Adding Docker's official GPG key..."
|
|
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
|
|
|
|
|
|
|
|
# Set up the stable repository for Docker
|
|
|
|
|
print_header "Setting up Docker repository..."
|
|
|
|
|
echo \
|
|
|
|
|
"deb [arch=amd64 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
|
|
|
|
|
|
|
|
|
|
# Update the package list again with progress bar
|
|
|
|
|
run_with_progress "sudo apt-get update"
|
|
|
|
|
|
|
|
|
|
# Install Docker CE (Community Edition)
|
|
|
|
|
print_header "Installing Docker CE..."
|
|
|
|
|
run_with_progress "sudo apt-get install -y docker-ce docker-ce-cli containerd.io"
|
|
|
|
|
|
|
|
|
|
# Verify that Docker is installed correctly
|
|
|
|
|
print_header "Starting and enabling Docker service..."
|
|
|
|
|
sudo systemctl start docker
|
|
|
|
|
sudo systemctl enable docker
|
|
|
|
|
|
|
|
|
|
# Download Docker Compose with progress bar
|
|
|
|
|
check_and_install_pv
|
|
|
|
|
print_header "Downloading and installing Docker Compose..."
|
|
|
|
|
sudo curl -L --output /tmp/docker-compose.tar.gz https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)
|
|
|
|
|
run_with_progress "pv -p -t -e -r /tmp/docker-compose.tar.gz | tar -xzf - -C /usr/local/bin"
|
|
|
|
|
|
|
|
|
|
# Verify that Docker Compose is installed correctly
|
|
|
|
|
print_header "Checking installation of Docker Compose..."
|
|
|
|
|
sudo ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
|
|
|
|
|
|
|
|
|
|
# Install Portainer and start it
|
|
|
|
|
print_header "Installing and starting Portainer..."
|
|
|
|
|
run_with_progress "curl -fL https://portainer.io/portainer.tar.gz | sudo tar xz -C /"
|
|
|
|
|
sudo mv /portainer/portainer /usr/local/bin/portainer
|
|
|
|
|
rm -rf /portainer
|
|
|
|
|
sudo chmod +x /usr/local/bin/portainer
|
|
|
|
|
|
|
|
|
|
# Run Portainer in detached mode
|
|
|
|
|
print_header "Starting Portainer..."
|
|
|
|
|
run_with_progress "sudo /usr/local/bin/portainer --log-level=info --tls"
|
|
|
|
|
|
|
|
|
|
# Print a message indicating that Portainer is running and accessible on the default URL
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Portainer has been installed and started. You can access it at:"
|
|
|
|
|
echo "https://<your-server-ip>:9000"
|