|
1 | 1 | #!/bin/bash
|
| 2 | + |
2 | 3 | # Title: install.sh
|
3 | 4 | # Author: Pelochus
|
4 | 5 | # Brief: Basic installation script for Rockchip NPUs, including LLMs and RKNN Toolkit 2
|
5 | 6 | # Check for more info: https://github.com/Pelochus/ezrknpu/
|
6 | 7 |
|
| 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 | + |
7 | 21 | message_print() {
|
8 | 22 | echo
|
9 | 23 | echo "#########################################"
|
10 |
| - echo $1 |
| 24 | + echo "$1" |
11 | 25 | echo "#########################################"
|
12 | 26 | echo
|
13 | 27 | }
|
14 | 28 |
|
| 29 | +non_zero_status_command() { |
| 30 | + echo "Error: $1" |
| 31 | + exit 1 |
| 32 | +} |
| 33 | + |
| 34 | +message_print "Checking script arguments..." |
| 35 | + |
15 | 36 | # If zero, both Toolkit2 and LLM will be installed
|
16 |
| -[ $# = 0 ] |
17 |
| -ARGCOUNT_IS_ZERO=$? |
| 37 | +ARGCOUNT_IS_ZERO=$([ $# = 0 ]; echo $?) |
18 | 38 |
|
19 | 39 | if [[ $1 = '-h' ]]
|
20 | 40 | then
|
|
23 | 43 | echo
|
24 | 44 | echo "If you want to install both LLM and NN-Toolkit do not provide any parameter"
|
25 | 45 | echo
|
26 |
| - echo "-llm: \ŧOnly installs ezrknn-llm" |
| 46 | + echo "-llm: \tOnly installs ezrknn-llm" |
27 | 47 | echo "-toolkit: \tOnly installs ezrknn-toolkit2"
|
28 | 48 | echo "-h: \tShows this help screen"
|
29 | 49 | echo
|
30 |
| - echo "For more information visit https://github.com/Pelochus/ezrknpu" |
| 50 | + echo "For more information visit $REPO_URL" |
31 | 51 | echo
|
32 |
| - exit |
| 52 | + exit 0 |
33 | 53 | fi
|
34 | 54 |
|
35 |
| -message_print "Installing apt dependencies..." |
| 55 | +message_print "Checking root permission..." |
36 | 56 |
|
37 |
| -sudo apt update |
| 57 | +if [ "$EUID" -ne 0 ] |
| 58 | +then |
| 59 | + echo "Please run this script as root!" |
| 60 | + exit 1 |
| 61 | +fi |
38 | 62 |
|
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..." |
40 | 64 |
|
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" |
43 | 66 | then
|
44 |
| - sudo apt install -y libgl1 libglx-mesa0 |
| 67 | + ALL_DEPS=("${APT_DEPS[@]}" "${APT_DEPS_NEW[@]}") |
45 | 68 | else
|
46 |
| - sudo apt install -y libgl1-mesa-glx |
| 69 | + ALL_DEPS=("${APT_DEPS[@]}" "${APT_DEPS_OLD[@]}") |
47 | 70 | fi
|
48 | 71 |
|
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 |
50 | 78 |
|
51 | 79 | message_print "Cloning main repo with submodules..."
|
52 | 80 |
|
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 |
57 | 88 |
|
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" |
60 | 90 |
|
| 91 | +# Install RKNN LLM if requested or by default |
61 | 92 | if [[ $1 = '-llm' || $ARGCOUNT_IS_ZERO ]]
|
62 | 93 | then
|
63 | 94 | message_print "Installing RKNN LLM with install.sh script..."
|
64 | 95 | cd ezrknn-llm
|
65 | 96 | bash install.sh
|
| 97 | + |
| 98 | + if [[ $? -ne 0 ]] |
| 99 | + then |
| 100 | + non_zero_status_command "Failed installing RKNN LLM" |
| 101 | + fi |
66 | 102 | fi
|
67 | 103 |
|
| 104 | +# Install RKNN Toolkit 2 if requested or by default |
68 | 105 | if [[ $1 = '-toolkit' || $ARGCOUNT_IS_ZERO ]]
|
69 | 106 | then
|
70 | 107 | message_print "Installing RKNN Toolkit 2 with install.sh script..."
|
71 | 108 | cd ../ezrknn-toolkit2
|
72 | 109 | bash install.sh
|
| 110 | + |
| 111 | + if [[ $? -ne 0 ]] |
| 112 | + then |
| 113 | + non_zero_status_command "Failed installing RKNN Toolkit 2" |
| 114 | + fi |
73 | 115 | fi
|
74 | 116 |
|
| 117 | +cd .. |
75 | 118 | message_print "Everything done!"
|
| 119 | + |
0 commit comments