-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-prerequisite.sh
More file actions
executable file
·161 lines (128 loc) · 3.79 KB
/
install-prerequisite.sh
File metadata and controls
executable file
·161 lines (128 loc) · 3.79 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
#!/bin/bash
function main() {
GPU=0
SCRIPT_DIR="$(cd `dirname $0` > /dev/null && pwd -P)"
if [ -z "$BASH" ]; then
print_error "Please run this script $0 with bash"
exit 1
fi
if [[ "$(id -u)" -ne 0 ]]; then
print_error "Please run this script with root privilege."
exit 1
fi
if [[ "$SCRIPT_DIR" != "$(pwd -P)" ]]; then
print_error "Please run this script in $(dirname $0)."
exit 1
fi
parse_arg "${@:1}"
install_packages
download_coco_imageset
install_docker
if [[ "$GPU" = "0" ]]; then
:
else
install_nvidia_driver
install_nvidia_docker
fi
update_grub
ask_reboot
}
function parse_arg() {
for arg in $@; do
case $arg in
--gpu=*)
GPU=${arg#*=}
;;
esac
done
}
function install_packages() {
apt-get update -y
apt-get install -y bc
apt-get install gawk
pip install sysv-ipc
}
function download_coco_imageset() {
wget http://images.cocodataset.org/zips/val2017.zip
mkdir -p ../resources/coco
unzip val2017.zip -d ../resources/coco
rm -f val2017.zip
}
# reboot required
function install_docker() {
apt-get update -y
# Download dependencies
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker's GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
# Install the Docker Repository
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce=5:20.10.8~3-0~ubuntu-bionic
# Post-installation steps
groupadd docker
usermod -aG docker $USER
systemctl enable docker.service
systemctl enable containerd.service
}
# reboot required
function install_nvidia_driver() {
apt-get install linux-headers-$(uname -r) -y
apt install ubuntu-drivers-common
ubuntu-drivers devices
ubuntu-drivers autoinstall
}
function install_nvidia_docker() {
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add - \
&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
apt-get update -y
apt-get install nvidia-docker2 -y
systemctl restart docker
# docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu nvidia-smi
}
function update_grub() {
sed -i 's/cgroup_enable=memory swapaccount=1//' /etc/default/grub
sed -i 's/GRUB_CMDLINE_LINUX="[^"]*/& cgroup_enable=memory swapaccount=1/' /etc/default/grub
update-grub
}
function ask_reboot() {
print_info "Prerequisite installation is complete and now the machine needs to reboot to run Pocket properly. Do you wish to reboot now?"
select yn in "Yes" "No"; do
case $yn in
Yes)
reboot
exit
;;
No)
print_info "Reboot is required for you to run Pocket properly."
exit
;;
esac
done
}
_BOLD="\e[1m"
_DIM="\e[2m"
_RED="\e[31m"
_LYELLOW="\e[93m"
_LGREEN="\e[92m"
_LCYAN="\e[96m"
_LMAGENTA="\e[95m"
_RESET="\e[0m"
function print_error() {
local message=$1
echo -e "${_BOLD}${_RED}[ERROR]${_RESET} ${message}${_RESET}"
}
function print_warning() {
local message=$1
echo -e "${_BOLD}${_LYELLOW}[WARN]${_RESET} ${message}${_RESET}"
}
function print_info() {
local message=$1
echo -e "${_BOLD}${_LGREEN}[INFO]${_RESET} ${message}${_RESET}"
}
function print_debug() {
local message=$1
echo -e "${_BOLD}${_LCYAN}[DEBUG]${_RESET} ${message}${_RESET}"
}
main "$@"; exit