forked from LondheShubham153/Shell-Scripting-For-DevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-install.sh
More file actions
149 lines (137 loc) · 4.31 KB
/
Copy pathdocker-install.sh
File metadata and controls
149 lines (137 loc) · 4.31 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# Function to check the OS type and print the message
checkAndPrintOSType() {
if [ -f /etc/os-release ]; then
source /etc/os-release
if [ "$ID" == "ubuntu" ]; then
if [ "$VERSION_ID" == "20.04" ]; then
echo "Installed OS is Ubuntu 20.04."
elif [ "$VERSION_ID" == "22.04" ]; then
echo "Installed OS is Ubuntu 22.04."
else
echo "Installed OS is Ubuntu, but version is not 20.04 or 22.04."
fi
elif [ "$ID" == "debian" ]; then
echo "Installed OS is Debian."
elif [ "$ID" == "centos" ]; then
echo "Installed OS is CentOS."
elif [ "$ID" == "fedora" ]; then
echo "Installed OS is Fedora."
elif [ "$ID" == "amzn" ] || [ "$ID" == "amzn2" ]; then
echo "Installed OS is Amazon Linux."
elif [ "$ID" == "opensuse" ]; then
echo "Installed OS is OpenSUSE."
else
echo "Unknown OS."
fi
else
echo "OS release file not found."
fi
}
checkDockerInstalled() {
if ! command -v docker &>/dev/null; then
echo "Docker is not installed."
return 1
else
echo "Docker is already installed."
return 0
fi
}
# Function to install Docker
installDocker(){
if ! checkDockerInstalled; then
echo "##############################################################################################################################"
echo "Docker is an open platform for developing, shipping, and running applications."
echo "It enables you to separate your applications from your infrastructure so you can deliver software quickly."
echo ""
echo "Please select your operating system/distribution to install Docker:"
echo "##############################################################################################################################"
echo ""
PS3="Select your OS/Distribution: "
select os_option in \
"Ubuntu 20.04 or 22.04" \
"Debian" \
"CentOS" \
"Fedora" \
"Amazon Linux" \
"OpenSUSE" \
"Quit"
do
case $REPLY in
1) installDockerUbuntu ;;
2) installDockerDebian ;;
3) installDockerCentOS ;;
4) installDockerFedora ;;
5) installDockerAmazonLinux ;;
6) installDockerOpenSUSE ;;
7) exit ;;
*) echo "Invalid selection, please try again..." ;;
esac
done
else
echo "Docker is already installed."
exit 0
fi
}
# Function to install Docker on Ubuntu
installDockerUbuntu() {
clear
echo "Installing Docker on Ubuntu..."
sudo apt update
sudo apt install -y docker.io
echo "Docker installed successfully!"
exit 0
}
# Function to install Docker on Debian
installDockerDebian() {
clear
echo "Installing Docker on Debian..."
sudo apt update
sudo apt install -y docker.io
echo "Docker installed successfully!"
exit 0
}
# Function to install Docker on CentOS
installDockerCentOS() {
clear
echo "Installing Docker on CentOS..."
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker installed successfully!"
exit 0
}
# Function to install Docker on Fedora
installDockerFedora() {
clear
echo "Installing Docker on Fedora..."
sudo dnf install -y docker
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker installed successfully!"
exit 0
}
# Function to install Docker on Amazon Linux
installDockerAmazonLinux() {
clear
echo "Installing Docker on Amazon Linux..."
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker installed successfully!"
exit 0
}
# Function to install Docker on OpenSUSE
installDockerOpenSUSE() {
clear
echo "Installing Docker on OpenSUSE..."
sudo zypper install -y docker
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker installed successfully!"
exit 0
}
# Call the function to check and print the OS type
checkAndPrintOSType
# Call the function to install Docker
installDocker