forked from gbristow/VRC-2021-Phase-II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·231 lines (191 loc) · 12.7 KB
/
setup.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
#!/bin/bash
# exit when any command fails
set -e
bar () {
# prints a bar equal to the current terminal width
printf '=%.0s' $(seq 1 "$(tput cols)") && printf "\n"
}
# colors
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
LIGHTGREEN='\033[1;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
VRC_DIR=~/Documents/VRC-2021-Phase-II
# see if sudo is installed
# mainly for testing with Docker, that doesn't have sudo
s=""
if [ -n "$(which sudo)" ]; then
s="sudo"
fi
# check to make sure code has already been cloned
if [[ ! -d $VRC_DIR ]]; then
echo "VRC repository has not been cloned to $VRC_DIR"
echo "Do this with '$s apt update && $s apt install -y git && git clone https://github.com/bellflight/VRC-2021-Phase-II $VRC_DIR'"
exit 1
fi
echo -e "${RED}"
echo "██████████████████████████████████████████████████████████████████████████"
echo -e "█████████████████████████████████████████████████████████████████████${NC}TM${RED}███"
echo "███████▌ ▀████ ████ ██████████ ███████████"
echo "█████████▄▄▄ ▄▄▄▄ ▐███ ▄▄▄▄▄▄▄▄████ ██████████ ███████████"
echo "██████████▀ █████ ████ ▀▀▀▀▀▀▀▀████ ██████████ ███████████"
echo "██████████ ▀████ ████ ██████████ ███████████"
echo "██████████ ▄▄▄▄▄ ███ ████████████ ██████████ ███████████"
echo "██████████ ████▀ ███ ▀▀▀▀▀▀▀▀████ ▀▀▀▀▀▀▀███ ▀▀▀▀▀▀▀▀███"
echo "██████████ ▄███ ████ ███ ███"
echo "██████████▄▄▄▄▄▄▄▄▄▄▄██████▄▄▄▄▄▄▄▄▄▄▄▄████▄▄▄▄▄▄▄▄▄▄▄▄███▄▄▄▄▄▄▄▄▄▄▄▄▄███"
echo "██████████████████████████████████████████████████████████████████████████"
echo " "
echo "██████████████████████████████▄▄ ▄▄██████████████████████████████"
echo "██████████████████████████████████▄ ▄██████████████████████████████████"
echo "████████████████████████████████████ ████████████████████████████████████"
echo "███▀▀▀▀▀██████████████████████████▀ ▀██████████████████████████▀▀▀▀▀███"
echo "████▄▄ ▀▀▀▀█████████████ █████████████▀▀▀▀ ▄▄████"
echo "████████▄▄▄ ▀▀▀▀▀██████████▀▀▀▀▀ ▄▄▄████████"
echo "█████████████▄▄ ▀████▀ ▄▄█████████████"
echo "█████████████████▄ ██ ▄█████████████████"
echo "██████████████████████████████▀ ██ ▀██████████████████████████████"
echo "███████████████████████▀▀ ██ ▀▀███████████████████████"
echo "████████████████▀▀▀ ██ ▀▀▀████████████████"
echo "█████████▀▀ ▄████▄ ▀▀█████████"
echo "████▀▀ ▄███▀ ▀███▄ ▀▀████"
echo " ████▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█████▀ ▀█████▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄████ "
echo " ▀███████████████████████████████▄ ▄███████████████████████████████▀ "
echo " ▀████████████████████████████████ ████████████████████████████████▀ "
echo " ██████████████████████████████▀ ▀██████████████████████████████ "
echo " ▀████████████████████████████▄ ▄████████████████████████████▀ "
echo " ▀███████████████████████████ ███████████████████████████▀ "
echo " ▀█████████████████████████ █████████████████████████▀ "
echo " ▀███████████████████████ ███████████████████████▀ "
echo " ▀█████████████████████ █████████████████████▀ "
echo " ▀███████████████████ ███████████████████▀ "
echo " ▀█████████████████ █████████████████▀ "
echo " ▀██████████████ ██████████████▀ "
echo " ▀████████████ ████████████▀ "
echo " ▀██████████ ██████████▀ "
echo " ▀███████ ███████▀ "
echo " ▀▀████ ████▀▀ "
echo " ▀███ ███▀ "
echo " ▀█▄▄█▀ "
echo -e "${NC}"
bar
echo -e "${CYAN}Updating package index${NC}"
bar
$s apt update
bar
echo -e "${CYAN}Updating system packages${NC}"
bar
export DEBIAN_FRONTEND=noninteractive
# upgrade existing packages
$s DEBIAN_FRONTEND=noninteractive apt upgrade -y
bar
echo -e "${CYAN}Installing prerequisites${NC}"
bar
# install some useful prereqs
$s apt install -y git apt-transport-https ca-certificates apt-utils software-properties-common gnupg lsb-release unzip curl rsync htop nano python3 python3-wheel python3-pip jq
$s -H python3 -m pip install pip wheel --upgrade
$s -H python3 -m pip install -U jetson-stats --upgrade
# set to high-power 10W mode. 1 is 5W mode
$s nvpmodel -m 0
cd $VRC_DIR
# cache the git credentials (mainly during development)
git config --global credential.helper cache
# update repo
git pull
# switch to main branch
git checkout main
bar
echo -e "${CYAN}Installing and configuring librealsense${NC}"
bar
# this is (possibly) needed to setup the udev rules on the host
$s apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
$s add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo bionic main" -u
$s apt install -y librealsense2-udev-rules librealsense2-utils librealsense2-dev
bar
echo -e "${CYAN}Installing and configuring Docker${NC}"
bar
# # replacing the installed system Docker with the latest version breaks stuff
# # remove old docker installation
# $s apt remove -y docker || true
# $s apt remove -y docker-engine|| true
# $s apt remove -y docker.io || true
# $s apt remove -y containerd || true
# $s apt remove -y runc || true
# # add docker GPG key
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | $s gpg --batch --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# # add docker repository
# echo \
# "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
# $(lsb_release -cs) stable" | $s tee /etc/apt/sources.list.d/docker.list > /dev/null
# # install docker
# $s apt update
# $s apt install -y docker-ce:arm64 docker-ce-cli:arm64 containerd.io:arm64 docker-compose:arm64
# # install nvidia-docker
# distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
# && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | $s apt-key add - \
# && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | $s tee /etc/apt/sources.list.d/nvidia-docker.list
# $s apt update
# $s apt install -y --allow-downgrades \
# jq \
# nvidia-docker2:arm64=2.5.0-1 \
# libnvidia-container-tools:arm64=1.3.3-1 \
# nvidia-container-runtime:arm64=3.4.2-1 \
# libnvidia-container1:arm64=1.3.3-1 \
# nvidia-container-toolkit:arm64=1.4.2-1
# upgrade compose
$s -H python3 -m pip install docker-compose --upgrade
# set the nvidia runtime to be default
# https://lukeyeager.github.io/2018/01/22/setting-the-default-docker-runtime-to-nvidia.html
pushd "$(mktemp -d)"
($s cat /etc/docker/daemon.json 2>/dev/null || echo '{}') | jq '. + {"default-runtime": "nvidia"}' | tee tmp.json
$s mv tmp.json /etc/docker/daemon.json
popd
# needed so that the shared libs are included in the docker container creation from the host
$s cp vmc/apriltag_module/linux/vrc.csv /etc/nvidia-container-runtime/host-files-for-container.d/
$s service docker stop
$s service docker start
# set up group rights for docker
# had issues with the script suddenly exiting, commented out
# set +e
# $s groupadd docker
# $s usermod -aG docker "$USER"
# newgrp docker
# set -e
bar
echo -e "${CYAN}Preparing VRC software${NC}"
bar
cd $VRC_DIR
$s docker-compose pull
$s docker-compose build
bar
echo -e "${CYAN}Cleaning up${NC}"
bar
$s apt autoremove -y
bar
echo -e "${CYAN}Performing self-test${NC}"
bar
# make sure jtop got installed
echo -n "Making sure 'jtop' works... "
if [ -n "$(which jtop)" ]; then
echo -e "${LIGHTGREEN}Passed!${NC}"
else
echo -e "${LIGHTRED}Failed!${NC}"
exit 1
fi
# make sure rs-enumerate-devices
echo -n "Making sure 'rs-enumerate-devices' works... "
if [ -n "$(which rs-enumerate-devices)" ]; then
echo -e "${LIGHTGREEN}Passed!${NC}"
else
echo -e "${LIGHTRED}Failed!${NC}"
exit 1
fi
# ensure the container runtime works
echo -n "Testing Nvidia container runtime... "
($s docker run --rm --gpus all --env NVIDIA_DISABLE_REQUIRE=1 nvcr.io/nvidia/cuda:11.4.1-base-ubuntu18.04 echo -e "${LIGHTGREEN}Passed!${NC}") || echo -e "${LIGHTRED}Failed!${NC}"
bar
echo -e "${GREEN}VRC Phase 2 finished setting up!${NC}"
echo -e "${GREEN}Please reboot your VMC now.${NC}"
bar