-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu-install-cuda.sh
executable file
·83 lines (71 loc) · 1.64 KB
/
ubuntu-install-cuda.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
#!/bin/bash
# Install CUDA driver on Ubuntu 16.04
driver=cuda-9-1
function usage {
echo "Usage: $0 [8|9|10|purge]"
echo " install $driver by default"
echo " 8 - install cuda-8-0"
echo " 9 - install cuda-9-0"
echo " 10 - install cuda-9-0"
echo " purge - uninstall cuda driver"
exit 64
}
function install_driver {
cuda_pkg="$1"
nvidia_key=https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
cuda_repo_url=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.1.105-1_amd64.deb
cuda_repo_pkg=${cuda_repo_url##*/}
wget -qO - "$nvidia_key" | apt-key add -
curl -O "$cuda_repo_url" && dpkg -i "$cuda_repo_pkg" && apt-get update && apt-get install -y nvidia-418 "$cuda_pkg"
if [[ "$?" -eq 0 ]]; then
echo "Installing CUDA toolkit (${cuda_pkg}): Succeded !"
else
echo "Installing CUDA toolkit (${cuda_pkg}): Failed !"
exit 1
fi
}
function purge_driver {
apt-get --purge remove \*cuda\*
apt-get --purge remove \*nvidia\*
exit
}
function check_root {
if [[ $EUID -ne 0 ]]; then
echo "Error: need to be run as root"
exit 1
fi
}
function check_gpu {
lspci | grep -q NVIDIA
if [[ $? -ne 0 ]]; then
echo "Error: no NVIDIA GPU on this machine"
exit 1
fi
}
# Main
check_root
check_gpu
if [[ $# -ne 0 ]]; then
case "$1" in
10)
driver=cuda-10-0
;;
9)
driver=cuda-9-0
;;
8)
driver=cuda-8-0
;;
purge)
echo "Removing CUDA toolkit, it should take about 10 min ..."
purge_driver
exit 1
;;
*)
usage
;;
esac
fi
echo "Installing CUDA toolkit ($driver), it should take about 10 min ..."
install_driver $driver
exit 0