-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup_environment.sh
executable file
·170 lines (137 loc) · 5.09 KB
/
setup_environment.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
#!/bin/bash
### Color logger function
singal='\033[0;93m'
clear='\033[0m'
function log () {
# check if message
test -n "$1" || {
echo;
return;
}
printf "${singal}$1${clear}\n"
}
# set -x
#############################################################
### L4T_VERSION retrieve logic
### Copied from https://github.com/dusty-nv/jetson-containers/blob/master/jetson_containers/l4t_version.sh
###vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv###
ARCH=$(uname -i)
log "ARCH: $ARCH"
if [ $ARCH = "aarch64" ]; then
L4T_VERSION_STRING=$(head -n 1 /etc/nv_tegra_release)
if [ -z "$L4T_VERSION_STRING" ]; then
#echo "reading L4T version from \"dpkg-query --show nvidia-l4t-core\""
L4T_VERSION_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core)
L4T_VERSION_ARRAY=(${L4T_VERSION_STRING//./ })
#echo ${L4T_VERSION_ARRAY[@]}
#echo ${#L4T_VERSION_ARRAY[@]}
L4T_RELEASE=${L4T_VERSION_ARRAY[0]}
L4T_REVISION=${L4T_VERSION_ARRAY[1]}
else
#echo "reading L4T version from /etc/nv_tegra_release"
L4T_RELEASE=$(echo $L4T_VERSION_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+')
L4T_REVISION=$(echo $L4T_VERSION_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+')
fi
L4T_REVISION_MAJOR=${L4T_REVISION:0:1}
L4T_REVISION_MINOR=${L4T_REVISION:2:1}
L4T_VERSION="$L4T_RELEASE.$L4T_REVISION"
log "L4T_VERSION: $L4T_VERSION"
elif [ $ARCH != "x86_64" ]; then
log "unsupported architecture: $ARCH"
exit 1
fi
###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
### L4T_VERSION retrieve logic done
#############################################################
###
### Install Chromium if in Desktop/GUI environment (or forced)
###
flag_install_chromium=false
echo "" | zenity --progress --text "Display test" --auto-close 2> /dev/null
if [ $? -eq 0 ]; then
log "Invoked in GUI/Desktop environmnet." -c "bright_blue"
flag_install_chromium=true
else
if [[ " $* " == *" --force-install-chromium "* ]]; then
log "[WARN] Force install chromium specified" -c "yellow"
flag_install_chromium=true
fi
log "[INFO] Not going to install Chromium as there is no display attached"
fi
if [ "$flag_install_chromium" = true ]; then
if [ -x "$(command -v chromium)" ]; then
log "[WARN] Chromium is already installed: $(chromium --version)" -c "yellow"
else
log "Installing Chromium app from Snap Store ..."
sudo snap install chromium
fi
fi
###
### Docker install and setup
###
flag_install_docker=false
DOCKER_DAEMON_CONFIG="/etc/docker/daemon.json"
if [ -x "$(command -v docker)" ]; then
log "[WARN] Docker is already installed: $(docker --version)"
log "---- $DOCKER_DAEMON_CONFIG contents ----"
cat $DOCKER_DAEMON_CONFIG
log "\n------------------------------------------"
if [[ " $* " == *" --force-install-docker "* ]]; then
log "[WARN] Force (re)install docker specified"
flag_install_docker=true
### Uninstall Docker Engine
### https://docs.docker.com/engine/install/debian/#uninstall-docker-engine
log "[INFO] Uninstalling Docker Engine and related packages ..."
sudo apt-get -y purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
fi
else
flag_install_docker=true
fi
if [ "$flag_install_docker" = true ]; then
log "Installing Docker and setting up ..."
sudo apt update
log "Installing nvidia-container package ..."
sudo apt install -y nvidia-container
verions_numbers=(${L4T_VERSION//./ })
L4T_VERSION_MAJOR=${verions_numbers[0]}
if [ "$L4T_VERSION_MAJOR" == "35" ]; then
log "JetPack 5.x :"
elif [ "$L4T_VERSION_MAJOR" == "36" ]; then
log "JetPack 6.x :"
## Starting from JetPack 6.0 DP, the `nvidia-container`` package stop automatically installing Docker.
## Following the official Docker installation flow.
sudo apt install -y curl
log "Installing Docker Engine ..."
curl https://get.docker.com | sh && sudo systemctl --now enable docker
sudo nvidia-ctk runtime configure --runtime=docker
else
log "[ERROR] unsupported architecture: $ARCH"
exit 1
fi
# Restart the Docker service and add your user to the docker group
sudo systemctl restart docker
sudo usermod -aG docker $USER
#newgrp docker
# Insert the `default-runtime` line
if grep -q "\"default-runtime\": \"nvidia\"" "$DOCKER_DAEMON_CONFIG"; then
log "[INFO] Defulat-runtime nvidia is already added"
else
log "---- $DOCKER_DAEMON_CONFIG contents (before) ----"
cat $DOCKER_DAEMON_CONFIG
log "\n-------------------------------------------------"
sudo sed 's|^{|{\n "default-runtime": "nvidia",|' -i /etc/docker/daemon.json
log "---- $DOCKER_DAEMON_CONFIG contents (after) ----"
cat $DOCKER_DAEMON_CONFIG
log "\n-------------------------------------------------"
fi
# Restart Docker
sudo systemctl daemon-reload && sudo systemctl restart docker
fi
if id -nG "$USER" | grep -qw docker; then
log "[INFO] User '$USER' is already in 'docker' group."
else
log "[WARN] User '$USER' is not in 'docker' group. Going to register in the group."
# Execute newgrp command at last as it resets the bash session
log "[WARN] newgrp command is executed, and your bash session is reset."
newgrp docker
fi