-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·358 lines (308 loc) · 9.79 KB
/
Copy pathinstall
File metadata and controls
executable file
·358 lines (308 loc) · 9.79 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/env bash
#====================================================================================
# install
#
# Installation script for easy_nrf52
#
# This file is part of easy_nrf52
# License: LGPL 2.1
# General and full license information is available at:
# https://github.com/plerup/easy_nrf52
#
# Copyright (c) 2022-2026 Peter Lerup. All rights reserved.
#
#====================================================================================
set -e
shopt -s nullglob
env_name=easy_nrf52
this_dir=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
lib_dir=/usr/lib/x86_64-linux-gnu
py_env_dir=""
cmd_out=/tmp/_com_out.txt
gcc_version=gcc-arm-none-eabi-10.3-2021.10
tool_list=(
"https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/$gcc_version-x86_64-linux.tar.bz2"
"https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/desktop-software/nrf-command-line-tools/sw/versions-10-x-x/10-24-2/nrf-command-line-tools_10.24.2_amd64.deb"
)
error() {
echo "* Error: $@" 1>&2
exit 1
}
#--------------------------------------------------------------------
prompt() {
local mess="$1"
local def="$2"
if [[ $use_defaults -eq 1 ]]; then
printf "%s" "$def"
return
fi
local resp
printf "%s [%s]: " "$mess" "$def" >&2
IFS= read -r resp
resp="${resp%"${resp##*[![:space:]]}"}"
printf "%s" "${resp:-$def}"
}
#--------------------------------------------------------------------
find_sdk() {
local vers="$1"
local main_ver
local url
local list
local zip
local m
if [[ "$vers" =~ ^([0-9]+) ]]; then
main_ver="${BASH_REMATCH[1]}"
else
error "Invalid version: $vers"
fi
url="https://files.nordicsemi.com/artifactory/nRF5-SDK/external/nRF5_SDK_v${main_ver}.x.x/"
list="$(wget -O - "$url" 2>/dev/null)"
zip=""
while [[ "$list" =~ href=\"(nRF5_SDK_${vers}[^[:space:]\"]+\.zip)\" ]]; do
m="${BASH_REMATCH[1]}"
[[ "$m" != *_doc* ]] && zip="$url$m"
list="${list#*"${BASH_REMATCH[0]}"}"
done
if [[ -z "$zip" ]]; then
error "Unable to find version: $vers"
fi
printf "%s" "$zip"
}
#--------------------------------------------------------------------
silent_command() {
# Run command without any output unless error occurs
set +e
"$@" >$cmd_out 2>&1
if [[ $? -ne 0 ]]; then
echo "** Command failed! $@ **"
cat $cmd_out
exit 1
fi
set -e
}
#--------------------------------------------------------------------
in_path() {
command -v "$1" >/dev/null 2>&1
}
#--------------------------------------------------------------------
mk_dir() {
[ -d $1 ] || mkdir -p $1
}
#--------------------------------------------------------------------
download() {
local url="$1"
local dst_dir="$2"
local name
local dst
name="$(basename "$url")"
dst="$dst_dir/$name"
echo " $name"
[[ -f "$dst" ]] && return
silent_command wget -q "$url" -O "$dst"
}
#--------------------------------------------------------------------
string_to_file() {
local path="$1"
local content="$2"
printf "%s" "$content" > "$path"
}
#--------------------------------------------------------------------
file_to_string() {
local path="$1"
[[ -f "$path" ]] || {
printf ""
return
}
cat "$path"
}
#--------------------------------------------------------------------
create_command() {
# Create shortcut for specified command
local dst="$bin_dir/$1"
[[ -e "$dst" ]] && rm "$dst"
if [[ -n "$2" ]]; then
echo $py_env_dir/bin/python3 $src_dir/tools/$1 \"\$@\" >$dst
chmod +x "$dst"
else
ln -s -f "$src_dir/tools/$1" "$dst"
fi
}
#--------------------------------------------------------------------
fix_missing() {
# Fix for missing files in Ubuntu
local dst="$1"
local alt="$2"
if [[ ! -e "$lib_dir/$dst" && -e "$lib_dir/$alt" ]]; then
$sudo ln -sf "$lib_dir/$alt" "$lib_dir/$dst"
fi
}
#--------------------------------------------------------------------
echo "==== Installing required tools for easy_nrf52 ===="
use_defaults=0
bin_dir=~/.local/bin
home_dir=$(getent passwd "$(id -u)" | cut -d: -f6)
install_root="$home_dir/.$env_name"
src_dir=$this_dir
if [[ $EUID -eq 0 ]]; then
sudo=""
is_root=1
else
sudo="sudo"
echo "Admin rights are required"
$sudo echo >/dev/null
fi
# Possible command parameters
for arg in "$@"; do
if [[ "$arg" == "--use_defaults" ]]; then
use_defaults=1
elif [[ "$arg" == "--global" ]]; then
if [[ ! -v is_root ]]; then
# Global install as root
exec sudo "$(realpath "$0")" "$@"
fi
bin_dir=/usr/local/bin
install_root=/opt/$env_name
global_install=1
echo Global installation will be made
else
error "Unknown option $arg"
fi
done
if [[ ! -v global_install ]]; then
install_root="$(prompt "Installation root directory" "$install_root")"
fi
sdk_list="$(prompt "Nordic SDK version(s)" "15 17")"
declare -A sdks
echo "Validating SDKs..."
# wget must be available
if ! in_path wget; then
silent_command $sudo apt-get update
silent_command $sudo apt-get install wget -y
fi
for s in $sdk_list; do
sdks["$s"]="$(find_sdk "$s")"
done
mapfile -t sdk_names < <(printf '%s\n' "${!sdks[@]}" | sort)
while true; do
def_sdk="$(prompt "Select default SDK" "${sdk_names[0]}")"
[[ -n "${sdks[$def_sdk]}" ]] && break
done
SECONDS=0
nrfutil="$install_root/nrfutil"
py_env_dir="$install_root/python_env"
echo "Checking/Installing required system tools..."
silent_command $sudo apt-get update
export DEBIAN_FRONTEND="noninteractive"
silent_command $sudo apt install perl dos2unix python3 python3-pip python3-venv ccache srecord openocd libzip-dev stlink-tools bluez bzip2 unzip curl libncurses5\* -y
$sudo usermod -a -G dialout $(whoami)
mk_dir "$install_root"
if [[ ! -f $this_dir/easy_nrf52.mk ]] || [[ -v global_install ]]; then
# Copy from git and put installed tools in a subdirectory
src_dir=$install_root
install_root=$install_root/inst_tools
mk_dir "$install_root"
rm -rf "$install_root"
tmp_zip=/tmp$env_name.zip
tmp_dir=/tmp/$env_name
echo "Downloading easy_nrf52 from gitHub..."
wget -q "https://github.com/plerup/easy_nrf52/archive/refs/heads/master.zip" -O $tmp_zip
unzip -q -o -d "$tmp_dir" "$tmp_zip"
mv $tmp_dir/easy_nrf52-master/* -t "$src_dir/"
unlink "$tmp_zip"
else
src_dir=$this_dir
fi
setup_dir="$install_root/setup"
mk_dir "$setup_dir"
echo "Downloading SDK(s) and build tools..."
for s in "${sdk_names[@]}"; do
download "${sdks[$s]}" "$setup_dir"
done
for t in "${tool_list[@]}"; do
download "$t" "$setup_dir"
done
echo "Unpacking..."
for f in "$setup_dir"/*; do
if [[ "$f" == *nRF5_SDK* ]]; then
if [[ "$f" =~ ([^/]+)\.zip ]]; then
dir="$install_root/${BASH_REMATCH[1]}"
printf " %s\n" "${BASH_REMATCH[1]}"
[[ -d "$dir" ]] && rm -rf "$dir"
extract_dir="$install_root"
[[ "$dir" == *SDK_17* ]] && extract_dir="$dir"
silent_command unzip -q -o -d "$extract_dir" "$f"
# Do some necessary patching
mk_file="$dir/components/toolchain/gcc/Makefile.posix"
silent_command dos2unix $mk_file
txt="$(file_to_string "$mk_file")"
txt="$(printf "%s" "$txt" | sed -E "s|(GNU_INSTALL_ROOT [^=]=).*|\1 $install_root/$gcc_version/bin/|")"
string_to_file "$mk_file" "$txt"
mk_file="$dir/components/toolchain/gcc/Makefile.common"
silent_command dos2unix $mk_file
txt="$(file_to_string "$mk_file")"
txt="$(printf "%s" "$txt" | sed 's/mkdir/mkdir -p/')"
string_to_file "$mk_file" "$txt"
ecc_file="$dir/external/micro-ecc/build_all.sh"
silent_command dos2unix $ecc_file
cd $(dirname $ecc_file) && silent_command source $ecc_file
fi
elif [[ "$f" == *gcc-arm* ]]; then
tar="${f%.bz*}"
printf " %s\n" "$(basename "$tar")"
rm -rf "$install_root"/gcc-arm\*
silent_command bunzip2 -k "$f"
silent_command tar -xf "$tar" -C "$install_root"
rm "$tar"
fi
done
echo "Installing..."
echo " Packages"
silent_command $sudo dpkg -i "$setup_dir"/*.deb
silent_command $sudo dpkg -i "$src_dir/tools"/*.deb
echo " Python requirements"
silent_command python3 -m venv "$py_env_dir"
silent_command "$py_env_dir/bin/pip" -qq install pyserial bleak aioconsole pynrfjprog
echo " Nordic tools"
silent_command curl -s https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/x86_64-unknown-linux-gnu/nrfutil -o "$nrfutil"
chmod +x "$nrfutil"
silent_command "$nrfutil" install -f device nrf5sdk-tools
if ! in_path JLinkConfig; then
jlink_deb="/tmp/JLink_Linux_x86_64.deb"
silent_command curl -s -X POST https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb -H "Content-Type: application/x-www-form-urlencoded" -d "accept_license_agreement=accepted" -o "$jlink_deb"
silent_command $sudo /lib/systemd/systemd-udevd -d
silent_command $sudo apt install "$jlink_deb" -y
fi
if in_path code; then
silent_command code --install-extension marus25.cortex-debug
fi
fix_missing "libzip.so.5" "libzip.so.4"
fix_missing "libncurses.so.5" "libncursesw.so.6.4"
fix_missing "libtinfo.so.5" "libtinfo.so.6"
echo " Creating command line commands ($bin_dir)"
[[ -d "$bin_dir" ]] && bin_present=1 || bin_present=0
mk_dir "$bin_dir"
create_command enrfmake
create_command enrfuart 1
create_command eenrfuart 1
create_command enrfpath
create_command enrfscan 1
create_command eenrfscan 1
def_priv_key="$src_dir/bootloader/dev_priv_key.pem"
nrfutil_cmd="$nrfutil nrf5sdk-tools"
[[ -f "$def_priv_key" ]] || silent_command "$nrfutil" nrf5sdk-tools keys generate "$def_priv_key"
string_to_file "$src_dir/setup.mk" \
"# $env_name setup information
INSTALL_ROOT = $install_root
SDK_VERSION = $def_sdk
PATH := $py_env_dir/bin:\$(PATH)
NRFUTIL = $nrfutil_cmd
"
echo
echo "==== Installation completed ==== "
elapsed=$SECONDS
minutes=$(((elapsed % 3600) / 60))
seconds=$((elapsed % 60))
printf "Used time: %02d:%02d\n" "$minutes" "$seconds"
if [[ $bin_present -eq 0 ]]; then
echo "Run \"source ~/.profile\" to enable enrf commands in this command window"
fi