-
Notifications
You must be signed in to change notification settings - Fork 0
/
io-net.sh
278 lines (255 loc) · 14.9 KB
/
io-net.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
set -euxo pipefail
export DEBIAN_FRONTEND=noninteractive
sudo dpkg --set-selections <<< "cloud-init install" || true
# Set Gloabal Variables
# Detect OS
OS="$(uname)"
case $OS in
"Linux")
# Detect Linux Distro
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
VERSION=$VERSION_ID
else
echo "Your Linux distribution is not supported."
exit 1
fi
;;
esac
# Detect if an Nvidia GPU is present
NVIDIA_PRESENT=$(lspci | grep -i nvidia || true)
# Only proceed with Nvidia-specific steps if an Nvidia device is detected
if [[ -z "$NVIDIA_PRESENT" ]]; then
echo "No NVIDIA device detected on this system."
else
# Check if nvidia-smi is available and working
if command -v nvidia-smi &>/dev/null; then
echo "CUDA drivers already installed as nvidia-smi works."
else
# Depending on Distro
case $DISTRO in
"ubuntu")
case $VERSION in
"20.04")
# Commands specific to Ubuntu 20.04
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
sudo apt install linux-headers-$(uname -r) -y
sudo apt del 7fa2af80
sudo apt install build-essential cmake gpg unzip pkg-config software-properties-common ubuntu-drivers-common -y
sudo apt install libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev -y || true
sudo apt install libjpeg-dev libpng-dev libtiff-dev -y || true
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y || true
sudo apt install libxvidcore-dev libx264-dev -y || true
sudo apt install libopenblas-dev libatlas-base-dev liblapack-dev gfortran -y || true
sudo apt install libhdf5-serial-dev -y || true
sudo apt install python3-dev python3-tk python-imaging-tk curl cuda-keyring gnupg-agent dirmngr alsa-utils -y || true
sudo apt install libgtk-3-dev -y || true
sudo apt update
sudo dirmngr </dev/null
if sudo apt-add-repository -y ppa:graphics-drivers/ppa && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C; then
echo "Alternative method succeeded."
else
echo "Alternative method failed. Trying the original method..."
sudo dirmngr </dev/null
sudo apt-add-repository -y ppa:graphics-drivers/ppa
sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/graphics-drivers.gpg --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
sudo chmod 644 /etc/apt/trusted.gpg.d/graphics-drivers.gpg
fi
sudo ubuntu-drivers autoinstall
sudo apt update
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt -y install cuda-toolkit
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
sudo apt-get update
;;
"22.04")
# Commands specific to Ubuntu 22.04
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
sudo apt install linux-headers-$(uname -r) -y
sudo apt-key del 7fa2af80
sudo apt install build-essential cmake gpg unzip pkg-config software-properties-common ubuntu-drivers-common -y
sudo apt install libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev -y
sudo apt install libjpeg-dev libpng-dev libtiff-dev -y
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt install libxvidcore-dev libx264-dev -y
sudo apt install libopenblas-dev libatlas-base-dev liblapack-dev gfortran -y
sudo apt install libhdf5-serial-dev -y
sudo apt install python3-dev python3-tk curl gnupg-agent dirmngr alsa-utils -y
sudo apt install libgtk-3-dev -y
sudo apt update
sudo dirmngr </dev/null
if sudo apt-add-repository -y ppa:graphics-drivers/ppa && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C; then
echo "Alternative method succeeded."
else
echo "Alternative method failed. Trying the original method..."
sudo dirmngr </dev/null
sudo apt-add-repository -y ppa:graphics-drivers/ppa
sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/graphics-drivers.gpg --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
sudo chmod 644 /etc/apt/trusted.gpg.d/graphics-drivers.gpg
fi
sudo ubuntu-drivers autoinstall
sudo apt update
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt -y install cuda-toolkit
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
sudo apt update
;;
"18.04")
# Commands specific to Ubuntu 18.04
sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
sudo apt-get install linux-headers-$(uname -r) -y
sudo apt-key del 7fa2af80
sudo apt install build-essential cmake gpg unzip pkg-config software-properties-common ubuntu-drivers-common alsa-utils -y
sudo apt install libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev -y || true
sudo apt install libjpeg-dev libpng-dev libtiff-dev -y || true
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y || true
sudo apt install libxvidcore-dev libx264-dev -y || true
sudo apt install libopenblas-dev libatlas-base-dev liblapack-dev gfortran -y || true
sudo apt install libhdf5-serial-dev -y || true
sudo apt install python3-dev python3-tk python-imaging-tk curl cuda-keyring -y || true
sudo apt install libgtk-3-dev -y || true
sudo apt update
sudo ubuntu-drivers install
sudo apt update
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt -y install cuda-toolkit
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
sudo apt update
;;
*)
echo "This version of Ubuntu is not supported in this script."
exit 1
;;
esac
;;
"debian")
case $VERSION in
"10"|"11")
# Commands specific to Debian 10 & 11
sudo -- sh -c 'apt update; apt upgrade -y; apt autoremove -y; apt autoclean -y'
sudo apt install linux-headers-$(uname -r) -y
sudo apt update
sudo apt install nvidia-driver firmware-misc-nonfree
wget https://developer.download.nvidia.com/compute/cuda/repos/debian${VERSION}/x86_64/cuda-keyring_1.1-1_all.deb
sudo apt install nvidia-cuda-dev nvidia-cuda-toolkit
sudo apt update
;;
*)
echo "This version of Debian is not supported in this script."
exit 1
;;
esac
;;
*)
echo "Your Linux distribution is not supported."
exit 1
;;
"Windows_NT")
# For Windows Subsystem for Linux (WSL) with Ubuntu
if grep -q Microsoft /proc/version; then
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
else
echo "This bash script can't be executed on Windows directly unless using WSL with Ubuntu. For other scenarios, consider using a PowerShell script or manual installation."
exit 1
fi
;;
*)
echo "Your OS is not supported."
exit 1
;;
esac
echo "System will now reboot !!! Please re-run this script after restart to complete installation !"
sleep 5s
sudo reboot
fi
fi
# For testing purposes, this should output NVIDIA's driver version
if [[ ! -z "$NVIDIA_PRESENT" ]]; then
nvidia-smi
fi
# Check if Docker is installed
if command -v docker &>/dev/null; then
echo "Docker is already installed."
else
echo "Docker is not installed. Proceeding with installations..."
# Install Docker-ce keyring
sudo apt update
sudo apt install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add Docker-ce repository to Apt sources and install
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/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 docker-ce
fi
# Check if docker-compose is installed
if command -v docker-compose &>/dev/null; then
echo "Docker-compoose is already installed."
else
echo "Docker-compose is not installed. Proceeding with installations..."
# Install docker-compose subcommand
sudo apt install docker-compose-plugin
sudo ln -sv /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose
docker-compose --version
# Test / Install nvidia-docker
if [[ ! -z "$NVIDIA_PRESENT" ]]; then
if sudo docker run --gpus all nvidia/cuda:12.0.0-base-ubuntu$VERSION_ID nvidia-smi &>/dev/null; then
echo "nvidia-docker is enabled and working. Exiting script."
else
echo "nvidia-docker does not seem to be enabled. Proceeding with installations..."
# Refer to install guide: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#installing-with-apt
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# The nvidia-ctk command modifies the /etc/docker/daemon.json file on the host.
# The file is updated so that Docker can use the NVIDIA Container Runtime.
sudo nvidia-ctk runtime configure --runtime=docker
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
# Install/Test Docker NVIDIA Image for Active Distro
case $DISTRO in
"ubuntu")
case $VERSION in
"22.04")
sudo docker run --gpus all nvidia/cuda:12.0.0-base-ubuntu22.04 nvidia-smi
echo "Installation successful !"
;;
esac
;;
"20.04")
sudo docker run --gpus all nvidia/cuda:12.0.0-base-ubuntu20.04 nvidia-smi
echo "Installation successful !"
;;
"18.04")
sudo docker run --gpus all nvidia/cuda:12.0.0-base-ubuntu18.04 nvidia-smi
echo "Installation successful !"
;;
*)
echo "Your OS is not supported"
exit 1
;;
esac
fi
fi
# Add docker group and user to group docker
sudo groupadd docker || true
sudo usermod -aG docker $USER || true
newgrp docker || true