Skip to content

Commit caf90a6

Browse files
committedMar 9, 2025
Rework install.sh: added error-checking, variables...
1 parent 8236528 commit caf90a6

File tree

1 file changed

+64
-20
lines changed

1 file changed

+64
-20
lines changed
 

‎install.sh

+64-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
#!/bin/bash
2+
23
# Title: install.sh
34
# Author: Pelochus
45
# Brief: Basic installation script for Rockchip NPUs, including LLMs and RKNN Toolkit 2
56
# Check for more info: https://github.com/Pelochus/ezrknpu/
67

8+
REPO_URL="https://github.com/Pelochus/ezrknpu"
9+
INSTALL_DIR="ezrknpu"
10+
11+
# APT package dependencies
12+
APT_DEPS=(
13+
git git-lfs python-is-python3 python3-pip python3-dev build-essential cmake
14+
libxslt1-dev zlib1g-dev libglib2.0-dev libsm6 libprotobuf-dev libhdf5-dev
15+
)
16+
17+
# Dependencies for different OS versions
18+
APT_DEPS_NEW=(libgl1 libglx-mesa0)
19+
APT_DEPS_OLD=(libgl1-mesa-glx)
20+
721
message_print() {
822
echo
923
echo "#########################################"
10-
echo $1
24+
echo "$1"
1125
echo "#########################################"
1226
echo
1327
}
1428

29+
non_zero_status_command() {
30+
echo "Error: $1"
31+
exit 1
32+
}
33+
34+
message_print "Checking script arguments..."
35+
1536
# If zero, both Toolkit2 and LLM will be installed
16-
[ $# = 0 ]
17-
ARGCOUNT_IS_ZERO=$?
37+
ARGCOUNT_IS_ZERO=$([ $# = 0 ]; echo $?)
1838

1939
if [[ $1 = '-h' ]]
2040
then
@@ -23,53 +43,77 @@ then
2343
echo
2444
echo "If you want to install both LLM and NN-Toolkit do not provide any parameter"
2545
echo
26-
echo "-llm: \ŧOnly installs ezrknn-llm"
46+
echo "-llm: \tOnly installs ezrknn-llm"
2747
echo "-toolkit: \tOnly installs ezrknn-toolkit2"
2848
echo "-h: \tShows this help screen"
2949
echo
30-
echo "For more information visit https://github.com/Pelochus/ezrknpu"
50+
echo "For more information visit $REPO_URL"
3151
echo
32-
exit
52+
exit 0
3353
fi
3454

35-
message_print "Installing apt dependencies..."
55+
message_print "Checking root permission..."
3656

37-
sudo apt update
57+
if [ "$EUID" -ne 0 ]
58+
then
59+
echo "Please run this script as root!"
60+
exit 1
61+
fi
3862

39-
sudo apt install -y git git-lfs python-is-python3 python3-pip python3-dev build-essential cmake libxslt1-dev zlib1g-dev libglib2.0-dev libsm6 libprotobuf-dev libhdf5-dev
63+
message_print "Installing apt dependencies..."
4064

41-
OS_VERSION=$(grep 'VERSION_ID' /etc/os-release | awk -F '=' '{print $2}' | tr -d '"')
42-
if $(dpkg --compare-versions "${OS_VERSION}" "ge" "24.10")
65+
if dpkg --compare-versions "$OS_VERSION" "ge" "24.10"
4366
then
44-
sudo apt install -y libgl1 libglx-mesa0
67+
ALL_DEPS=("${APT_DEPS[@]}" "${APT_DEPS_NEW[@]}")
4568
else
46-
sudo apt install -y libgl1-mesa-glx
69+
ALL_DEPS=("${APT_DEPS[@]}" "${APT_DEPS_OLD[@]}")
4770
fi
4871

49-
# sudo apt install -y adb # For running the NPU in Android
72+
sudo apt update && sudo apt install -y "${ALL_DEPS[@]}"
73+
74+
if [[ $? -ne 0 ]]
75+
then
76+
non_zero_status_command "Could not update/upgrade with apt. No internet connection?"
77+
fi
5078

5179
message_print "Cloning main repo with submodules..."
5280

53-
# This also clones submodules
54-
# Add --remote-submodules if you want to update submodules to latest commit and not current repo commit
55-
git clone --recurse-submodules -j2 https://github.com/Pelochus/ezrknpu
56-
cd ezrknpu
81+
# Clone (recurse-submodules) submodules and update (remote-submodules) to latest commit of the branch
82+
git clone --remote-submodules --recurse-submodules -j2 "$REPO_URL" "$INSTALL_DIR"
83+
84+
if [[ $? -ne 0 ]]
85+
then
86+
non_zero_status_command "Could not clone ezrknpu. No internet connection?"
87+
fi
5788

58-
message_print "Updating submodules..."
59-
git submodule update --recursive --remote # Submodules should be updated, but just in case I forget
89+
cd "$INSTALL_DIR"
6090

91+
# Install RKNN LLM if requested or by default
6192
if [[ $1 = '-llm' || $ARGCOUNT_IS_ZERO ]]
6293
then
6394
message_print "Installing RKNN LLM with install.sh script..."
6495
cd ezrknn-llm
6596
bash install.sh
97+
98+
if [[ $? -ne 0 ]]
99+
then
100+
non_zero_status_command "Failed installing RKNN LLM"
101+
fi
66102
fi
67103

104+
# Install RKNN Toolkit 2 if requested or by default
68105
if [[ $1 = '-toolkit' || $ARGCOUNT_IS_ZERO ]]
69106
then
70107
message_print "Installing RKNN Toolkit 2 with install.sh script..."
71108
cd ../ezrknn-toolkit2
72109
bash install.sh
110+
111+
if [[ $? -ne 0 ]]
112+
then
113+
non_zero_status_command "Failed installing RKNN Toolkit 2"
114+
fi
73115
fi
74116

117+
cd ..
75118
message_print "Everything done!"
119+

0 commit comments

Comments
 (0)
Please sign in to comment.