-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·226 lines (190 loc) · 6.1 KB
/
install.sh
File metadata and controls
executable file
·226 lines (190 loc) · 6.1 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
# Gettting arguments
MODE="INSTALL"
while getopts "iu" opt; do
case $opt in
i)
MODE="INSTALL"
;;
u)
MODE="UNINSTALL"
;;
\?)
echo "Invalid option -$OPTARG" >&2
;;
esac
done
function get_os {
case "$OSTYPE" in
linux*) echo "linux" ;;
darwin*) echo "mac" ;;
win*) echo "windows" ;;
msys*) echo "windows" ;;
cygwin*) echo "windows" ;;
bsd*) echo "bsd" ;;
solaris*) echo "solaris" ;;
*) echo "unknown" ;;
esac
}
function get_linux_distro {
DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO"
}
function get_linux_distro_version {
DISTRO_VERSION=$(lsb_release -sr | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO_VERSION"
}
function get_linux_distro_codename {
DISTRO_CODENAME=$(lsb_release -sc | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo "$DISTRO_CODENAME"
}
function enable_amd64_architecture {
sudo dpkg --add-architecture amd64
sudo apt-get update
}
function disable_amd64_architecture {
sudo dpkg --remove-architecture amd64
sudo apt-get update
}
function enable_amd64_sources_2204 {
echo "Enabling amd64 sources for Ubuntu 22.04"
sudo sed -i 's/^deb http/deb [arch=arm64] http/' /etc/apt/sources.list
sudo sed -i 's/^deb-src http/deb-src [arch=arm64] http/' /etc/apt/sources.list
cmd1="deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ $(get_linux_distro_codename) main restricted universe multiverse"
cmd2="deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ $(get_linux_distro_codename)-updates main restricted universe multiverse"
cmd3="deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ $(get_linux_distro_codename)-backports main restricted universe multiverse"
cmd4="deb [arch=amd64] http://security.ubuntu.com/ubuntu/ $(get_linux_distro_codename)-security main restricted universe multiverse"
{
sudo echo "$cmd1"
sudo echo "$cmd2"
sudo echo "$cmd3"
sudo echo "$cmd4"
} >>/etc/apt/sources.list
}
function disable_amd64_sources_2204 {
echo "Disabling amd64 sources for Ubuntu 22.04"
sudo sed -i 's/deb \[arch=arm64\] http/deb http/' /etc/apt/sources.list
sudo sed -i 's/deb-src \[arch=arm64\] http/deb-src http/' /etc/apt/sources.list
sudo sed -i '/^deb \[arch=amd64\]/d' /etc/apt/sources.list
}
function enable_amd64_sources_2404 {
echo "Enabling amd64 sources for Ubuntu 24.04"
CONTENT=$(
cat <<EOF
Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Architectures: arm64
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-security
Components: main restricted universe multiverse
Architectures: arm64
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Architectures: amd64
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Architectures: amd64
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
)
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
sudo echo "$CONTENT" >/etc/apt/sources.list.d/ubuntu.sources
}
function disable_amd64_sources_2404 {
echo "Disabling amd64 sources for Ubuntu 24.04"
sudo rm /etc/apt/sources.list.d/ubuntu.sources
sudo mv /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources
}
function install_docker {
echo "Installing Docker"
apt-get update
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor --yes -o /usr/share/keyrings/docker.gpg
chmod a+r /usr/share/keyrings/docker.gpg
echo \
"deb [signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
echo "Docker has been installed"
}
function uninstall_docker {
echo "Uninstalling Docker"
sudo apt purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo apt autoremove -y
echo "Docker has been uninstalled"
}
function install_dependencies {
echo "Installing dependencies"
sudo apt update
sudo apt install -y curl wget git jq ca-certificates apt-transport-https
echo "Dependencies have been installed"
}
function uninstall_dependencies {
echo "Uninstalling dependencies"
sudo apt purge -y curl git jq
sudo apt autoremove -y
echo "Dependencies have been uninstalled"
}
function install {
echo "- Detected OS: $OS"
DISTRO="$(get_linux_distro)"
echo "- Detected Disto: $DISTRO"
if [ "$DISTRO" != "ubuntu" ]; then
echo "This script is only compatible with Ubuntu, exiting"
exit 1
fi
VERSION="$(get_linux_distro_version)"
echo "- Detected Ubuntu version: $VERSION"
if [ "$VERSION" == "24.04" ]; then
enable_amd64_sources_2404
enable_amd64_architecture
elif [ "$VERSION" == "22.04" ]; then
enable_amd64_sources_2204
enable_amd64_architecture
else
echo "This script is only compatible with Ubuntu 20.04 and 22.04, exiting"
exit 1
fi
echo "Installing a new cluster"
install_dependencies
install_docker
}
function uninstall {
echo "Detected OS: $OS"
VERSION="$(get_linux_distro_version)"
echo "Detected Ubuntu version: $VERSION"
uninstall_docker
if [ "$VERSION" == "24.04" ]; then
disable_amd64_sources_2404
disable_amd64_architecture
elif [ "$VERSION" == "22.04" ]; then
disable_amd64_sources_2204
disable_amd64_architecture
fi
}
OS=$(get_os)
if [ "$OS" != "linux" ]; then
echo "This script is only compatible with Linux, exiting"
exit 1
fi
if [ -z "$MODE" ]; then
echo "Choose either install or uninstall mode"
exit 1
fi
if [ "$MODE" == "INSTALL" ]; then
install
fi
if [ "$MODE" == "UNINSTALL" ]; then
uninstall
fi