Skip to content

Commit 302296a

Browse files
authored
Merge pull request #1076 from luxonis/add_install_depthai.sh
Added back this script
2 parents 099dc46 + e6dd326 commit 302296a

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed

docs/install_depthai.sh

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
#!/bin/bash
2+
3+
APP_NAME="depthai"
4+
WORKING_DIR_NAME="Luxonis"
5+
WORKING_DIR="$HOME/$WORKING_DIR_NAME"
6+
mkdir "$WORKING_DIR"
7+
install_path=""
8+
path_correct="false"
9+
10+
trap 'RET=$? ; echo -e >&2 "\n\x1b[31mFailed installing dependencies. Could be a bug in the installer or unsupported platform. Open a bug report over at https://github.com/luxonis/depthai - exited with status $RET at line $LINENO \x1b[0m\n" ; exit $RET' ERR
11+
12+
while [ "$path_correct" = "false" ]
13+
do
14+
echo ""
15+
echo 'ENTER absolute installation path for depthai or leave empty and default path: $HOME will be used.'
16+
read -e install_path < /dev/tty
17+
echo ""
18+
19+
if [ "$install_path" = "" ]; then
20+
echo "Using default installation path: $WORKING_DIR"
21+
mkdir -p "$WORKING_DIR"
22+
else
23+
echo "Using given installation path: $install_path"
24+
WORKING_DIR="$install_path"
25+
fi
26+
27+
if [ -d "$WORKING_DIR" ]; then
28+
echo "Directory: $WORKING_DIR is OK"
29+
path_correct="true"
30+
else
31+
echo "Directory: $WORKING_DIR is not valid. Try again!"
32+
fi
33+
done
34+
35+
DEPTHAI_DIR="$WORKING_DIR/$APP_NAME"
36+
VENV_DIR="$WORKING_DIR/venv"
37+
ENTRYPOINT_DIR="$DEPTHAI_DIR/entrypoint"
38+
39+
# Get Python version or find out that python 3.10 must be installed
40+
python_executable=$(which python3)
41+
python_chosen="false"
42+
install_python="false"
43+
python_version=$(python3 --version)
44+
python_version_number=""
45+
if [[ "$python_version" != 'Python'* ]]; then
46+
python_version=""
47+
fi
48+
echo ""
49+
50+
# check default python version, offer it to the user or get another one
51+
while [ "$python_chosen" = "false" ]
52+
do
53+
if [[ "$python_version" == "" ]]; then
54+
echo "No python version found."
55+
echo "Input path for python binary, version 3.8 or higher, or leave empty and python 3.10 will be installed for you."
56+
echo "Press ENTER key to continue"
57+
read -e python_binary_path < /dev/tty
58+
# python not found and user wants to install python 3.10
59+
if [ "$python_binary_path" = "" ]; then
60+
install_python="true"
61+
python_chosen="true"
62+
fi
63+
else
64+
# E.g Python 3.10 -> nr_1=3, nr_2=10, for Python 3.7.5 -> nr_1=r, nr_2=7
65+
nr_1="${python_version:7:1}"
66+
nr_2=$(echo "${python_version:9:2}" | tr -d -c 0-9)
67+
echo "Python version: $python_version found."
68+
if [ "$nr_1" -gt 2 ] && [ "$nr_2" -gt 7 ]; then # first two digits of python version greater then 3.7 -> python version 3.8 or greater is allowed.
69+
echo "If you want to use it for installation, press ENTER key, otherwise input path to python binary."
70+
echo "Press ENTER key to continue"
71+
read -e python_binary_path < /dev/tty
72+
# user wants to use already installed python whose version is high enough
73+
if [ "$python_binary_path" = "" ]; then
74+
python_chosen="true"
75+
fi
76+
else
77+
echo "This python version is not supported by depthai. Enter path to python binary version et least 3.8, or leave empty and python 3.10 will be installed automatically."
78+
echo "Press ENTER key to continue"
79+
read -e python_binary_path < /dev/tty
80+
# python version is too low and user wants to install python 3.10
81+
if [ "$python_binary_path" = "" ]; then
82+
install_python="true"
83+
python_chosen="true"
84+
fi
85+
fi
86+
fi
87+
# User entered some path that should lead to python binary, save python --version output and the rest is dealt in the while loop logic.
88+
if [ "$python_binary_path" != "" ]; then
89+
python_executable="$python_binary_path"
90+
python_version=$($python_binary_path --version)
91+
if [[ "$python_version" != 'Python'* ]]; then
92+
python_version=""
93+
fi
94+
fi
95+
done
96+
97+
98+
write_in_file () {
99+
# just make sure only strings are appended which are not in there yet
100+
# first arg is text to write, second arg is the file path
101+
if ! grep -Fxq "$1" "$2"
102+
then
103+
echo "$1" >> "$2"
104+
fi
105+
}
106+
107+
COMMENT='# Entry point for Depthai demo app, enables to run <depthai_launcher> in terminal'
108+
BASHRC="$HOME/.bashrc"
109+
ZSHRC="$HOME/.zshrc"
110+
ADD_ENTRYPOINT_TO_PATH='export PATH=$PATH'":$ENTRYPOINT_DIR"
111+
112+
# add to .bashrc only if it is not in there already
113+
write_in_file "$COMMENT" "$BASHRC"
114+
write_in_file "$ADD_ENTRYPOINT_TO_PATH" "$BASHRC"
115+
116+
if [ -f "$ZSHRC" ]; then
117+
write_in_file "$COMMENT" "$ZSHRC"
118+
write_in_file "$ADD_ENTRYPOINT_TO_PATH" "$ZSHRC"
119+
fi
120+
121+
if [[ $(uname -s) == "Darwin" ]]; then
122+
echo _____________________________
123+
echo "Calling macOS_installer.sh"
124+
echo _____________________________
125+
echo "Running macOS installer."
126+
127+
echo "Installing global dependencies."
128+
bash -c "$(curl -fL https://docs.luxonis.com/install_dependencies.sh)"
129+
130+
echo "Upgrading brew."
131+
brew update
132+
133+
# clone depthai form git
134+
if [ -d "$DEPTHAI_DIR" ]; then
135+
echo "Demo app already downloaded. Checking out main and updating."
136+
else
137+
echo "Downloading demo app."
138+
git clone https://github.com/luxonis/depthai.git "$DEPTHAI_DIR"
139+
fi
140+
cd "$DEPTHAI_DIR"
141+
git fetch
142+
git checkout main
143+
git pull
144+
145+
# install python 3.10 and python dependencies
146+
brew update
147+
148+
if [ "$install_python" == "true" ]; then
149+
echo "installing python 3.10"
150+
brew install [email protected]
151+
python_executable=$(which python3.10)
152+
fi
153+
154+
# pip does not have pyqt5 for arm
155+
if [[ $(uname -m) == 'arm64' ]]; then
156+
echo "Installing pyqt5 with homebrew."
157+
brew install pyqt@5
158+
fi
159+
160+
# create python virtual environment
161+
echo "Creating python virtual environment in $VENV_DIR"
162+
echo "$python_executable"
163+
"$python_executable" -m venv "$VENV_DIR"
164+
# activate environment
165+
source "$VENV_DIR/bin/activate"
166+
python -m pip install --upgrade pip
167+
168+
# install launcher dependencies
169+
# only on mac silicon point PYTHONPATH to pyqt5 installation via homebrew, otherwise install pyqt5 with pip
170+
if [[ $(uname -m) == 'arm64' ]]; then
171+
if [[ ":$PYTHONPATH:" == *":/opt/homebrew/lib/python3.10/site-packages:"* ]]; then
172+
echo "/opt/homebrew/lib/python$nr_1.$nr_2/site-packages already in PYTHONPATH"
173+
else
174+
export "PYTHONPATH=/opt/homebrew/lib/python$nr_1.$nr_2/site-packages:"$PYTHONPATH
175+
echo "/opt/homebrew/lib/pythonv$nr_1.$nr_2/site-packages added to PYTHONPATH"
176+
fi
177+
else
178+
pip install pyqt5
179+
fi
180+
181+
pip install packaging
182+
183+
elif [[ $(uname -s) == "Linux" ]]; then
184+
echo _____________________________
185+
echo "Calling linux_installer.sh"
186+
echo _____________________________
187+
188+
echo "Updating sudo-apt."
189+
sudo apt-get update
190+
191+
echo "Installing global dependencies."
192+
sudo wget -qO- https://docs.luxonis.com/install_dependencies.sh | bash
193+
194+
echo -e '\nRunning Linux installer.'
195+
196+
# clone depthai form git
197+
if [ -d "$DEPTHAI_DIR" ]; then
198+
echo "Demo app already downloaded. Checking out main and updating."
199+
200+
else
201+
echo "Downloading demo app."
202+
git clone https://github.com/luxonis/depthai.git "$DEPTHAI_DIR"
203+
fi
204+
205+
cd "$DEPTHAI_DIR"
206+
git fetch
207+
git checkout main
208+
git pull
209+
210+
# install python 3.10
211+
if [ "$install_python" == "true" ]; then
212+
echo "installing python 3.10"
213+
214+
sudo yes "" | sudo add-apt-repository ppa:deadsnakes/ppa
215+
sudo apt -y install python3.10
216+
sudo apt -y install python3.10-venv
217+
python_executable=$(which python3.10)
218+
fi
219+
220+
echo "Creating python virtual environment in $VENV_DIR"
221+
222+
machine=$(uname -m)
223+
if [[ $machine != 'armv6l' && $machine != 'armv7l' && $machine != 'aarch64' && $machine != 'arm64' ]]; then
224+
"$python_executable" -m venv "$VENV_DIR"
225+
else
226+
"$python_executable" -m venv "$VENV_DIR" --system-site-packages
227+
fi
228+
229+
source "$VENV_DIR/bin/activate"
230+
python -m pip install --upgrade pip
231+
232+
pip install packaging
233+
234+
if [[ $machine != 'armv6l' && $machine != 'armv7l' && $machine != 'aarch64' && $machine != 'arm64' ]]; then
235+
pip install pyqt5
236+
fi
237+
else
238+
echo "Error: Host $(uname -s) not supported."
239+
exit 99
240+
fi
241+
242+
echo -e '\n\n:::::::::::::::: INSTALATION COMPLETE ::::::::::::::::\n'
243+
echo -e '\nTo run demo app write <depthai_launcher> in terminal.'
244+
echo "Press ENTER KEY to finish and run the demo app..."
245+
read -n1 key < /dev/tty
246+
echo "STARTING DEMO APP."
247+
python "$DEPTHAI_DIR/launcher/launcher.py" -r "$DEPTHAI_DIR"

0 commit comments

Comments
 (0)