-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
72 lines (62 loc) · 2.24 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Function to ask for user confirmation
confirm() {
while true; do
read -rp "$1 [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
*) echo "Please answer yes or no." ;;
esac
done
}
# Check if Docker is installed via Snap
if snap list docker &> /dev/null; then
echo "Docker is installed via Snap."
if confirm "Do you want to uninstall the Snap version of Docker?"; then
echo "Uninstalling Docker from Snap..."
sudo snap remove docker
else
echo "Skipping Docker uninstallation from Snap."
fi
else
echo "Docker is not installed via Snap, or Snap is not installed."
fi
# Update package database
echo "Updating package database..."
sudo apt-get update
# Install prerequisites
echo "Installing prerequisites..."
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
# Add Docker's official GPG key
echo "Adding 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 the stable repository
echo "Setting up Docker repository..."
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
CODENAME=$(lsb_release -cs)
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$DISTRO \
$CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
echo "Installing Docker Engine..."
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Verify Docker installation
echo "Verifying Docker installation..."
sudo docker run hello-world
# Ask if the user wants to install Docker Compose
if confirm "Do you want to install Docker Compose?"; then
echo "Installing Docker Compose..."
sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
echo "Docker Compose installed successfully."
else
echo "Skipping Docker Compose installation."
fi
echo "Docker installation completed successfully!"