-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·169 lines (149 loc) · 6.16 KB
/
install.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
#!/bin/bash
# Copyright (C) 2021, Raffaello Bonghi <raffaello@rnext.it>
# All rights reserved
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bold=`tput bold`
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`
PLATFORM="$(uname -m)"
usage()
{
if [ "$1" != "" ]; then
echo "${red}$1${reset}" >&2
fi
local name=$(basename ${0})
echo "nanosaur-jetson-runner installer." >&2
echo "" >&2
echo "Options:" >&2
echo " -h|--help | This help" >&2
echo " -y | Run this script silent" >&2
}
install_jetson()
{
echo "Install on ${bold}${green}NVIDIA${reset} ${green}Jetson platform${reset}"
# Check if is installed docker-compose
if ! command -v docker-compose &> /dev/null ; then
echo " - ${bold}${green}Install docker-compose${reset}"
sudo apt-get install -y libffi-dev python-openssl libssl-dev
sudo -H pip3 install -U pip
sudo pip3 install -U docker-compose
fi
local PATH_HOST_FILES4CONTAINER="/etc/nvidia-container-runtime/host-files-for-container.d"
echo "${green} - Enable dockers to build jetson_multimedia api folder${reset}"
sudo cp docker-config/jetson_multimedia_api.csv $PATH_HOST_FILES4CONTAINER/jetson_multimedia_api.csv
}
install_x86()
{
# Check if is running on NVIDIA Jetson platform
echo "Install on ${bold}${green}Desktop${reset} ${green}platform${reset}"
# Check if GPU is installed
if type nvidia-smi &>/dev/null; then
GPU_ATTACHED=(`nvidia-smi -a | grep "Attached GPUs"`)
if [ ! -z $GPU_ATTACHED ]; then
echo "${bold}${green}GPU attached!${reset}"
else
echo "${red}Install NVIDIA grafic card drivers and rerun!${reset}"
exit 33
fi
fi
# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html
# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html
# https://stackoverflow.com/questions/1298066/how-can-i-check-if-a-package-is-installed-and-install-it-if-not
REQUIRED_PKG="nvidia-docker2"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
echo Checking for $REQUIRED_PKG: $PKG_OK
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG."
# Add distribution
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& 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/$distribution/libnvidia-container.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
# Install nvidia-docker2
sudo apt-get install -y nvidia-docker2
fi
}
main()
{
local SILENT=false
# Decode all information from startup
while [ -n "$1" ]; do
case "$1" in
-h|--help) # Load help
usage
exit 0
;;
-y)
SILENT=true
;;
*)
usage "[ERROR] Unknown option: $1" >&2
exit 1
;;
esac
shift 1
done
while ! $SILENT; do
read -p "Do you wish to install nanosaur-runner? [Y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
# Setup enviroment
if [ ! -f .env ] ; then
touch .env
echo "GITHUB_ACTIONS_RUNNER_NAME=$HOSTNAME" >> .env
read -p "Enter GitHub Action token: " TOKEN
echo "GITHUB_ACTIONS_ACCESS_TOKEN=$TOKEN" >> .env
echo "HOME=$HOME" >> .env
fi
sudo -v
# Check if is running on NVIDIA Jetson platform
if [[ $PLATFORM = "aarch64" ]]; then
install_jetson
else
install_x86
fi
if ! getent group docker | grep -q "\b$USER\b" ; then
echo " - Add docker permissions to ${bold}${green}user=$USER${reset}"
sudo usermod -aG docker $USER
fi
# Make sure the nvidia docker runtime will be used for builds
DEFAULT_RUNTIME=$(docker info | grep "Default Runtime: nvidia" ; true)
if [[ -z "$DEFAULT_RUNTIME" ]]; then
echo "${yellow} - Set runtime nvidia on /etc/docker/daemon.json${reset}"
sudo mv /etc/docker/daemon.json /etc/docker/daemon.json.bkp
sudo cp docker-config/daemon.json /etc/docker/daemon.json
fi
echo "${yellow} - Restart docker server${reset}"
sudo systemctl restart docker.service
}
main $@
exit 0
#EOF