@dotpi/tools 2.8.1 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dotpi-tools.js +19 -4
- package/dotpi_root/bin/dotpi_firstrun +2 -6
- package/dotpi_root/bin/dotpi_prepare_sd_card +1 -1
- package/dotpi_root/dist/@dotpi/avahi-monitor-module/package.json +1 -1
- package/dotpi_root/dist/@dotpi/javascript/bash.js +1 -1
- package/dotpi_root/dist/@dotpi/javascript/package.json +1 -1
- package/dotpi_root/dist/@dotpi/module/package.json +2 -2
- package/dotpi_root/dist/@dotpi/module-module/package.json +2 -2
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +6 -1
- package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +248 -4
- package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +32 -5
- package/dotpi_root/share/dotpi_init.bash +5 -0
- package/package.json +4 -3
- package/src/create-project.js +65 -10
- package/src/templates/{ap.nmconnection → ap.nmconnection.template} +9 -1
- package/src/templates/infrastructure.nmconnection +5 -1
package/README.md
CHANGED
|
@@ -320,12 +320,15 @@ Please do report them.
|
|
|
320
320
|
|
|
321
321
|
## Todo
|
|
322
322
|
|
|
323
|
-
- [ ] allow to use configuration files from project
|
|
324
|
-
- [ ] dotpi-led
|
|
325
|
-
|
|
326
323
|
- [ ] dotpi-manager: dependency to audio should be soft
|
|
327
324
|
- [ ] allow client to run without audio
|
|
328
325
|
- [ ] client should continue to run if audio stops
|
|
329
326
|
|
|
330
|
-
- [ ] @dotpi/audio
|
|
327
|
+
- [ ] @dotpi/audio-module
|
|
331
328
|
- [ ] generate
|
|
329
|
+
- [ ] soft limiter at audio output
|
|
330
|
+
- [ ] pipewire filter-chain
|
|
331
|
+
Cf. <https://flaterco.com/kb/audio/pipewire/volume.html>
|
|
332
|
+
- [ ] easy effect
|
|
333
|
+
Cf. <https://github.com/wwmm/easyeffects/wiki/Command-Line-Options>
|
|
334
|
+
|
package/dotpi-tools.js
CHANGED
|
@@ -6,18 +6,26 @@ import { greetings } from './src/utils.js';
|
|
|
6
6
|
import createProject from './src/create-project.js';
|
|
7
7
|
import installRpi from './src/install-rpi.js';
|
|
8
8
|
import configureHost from './src/configure-host.js';
|
|
9
|
+
import { packageVersion } from './src/utils.js';
|
|
9
10
|
|
|
10
11
|
program
|
|
11
|
-
.option('--create-project')
|
|
12
|
-
.option('--install-rpi')
|
|
13
|
-
.option('--configure-host')
|
|
12
|
+
.option('--create-project', 'create a new dotpi project')
|
|
13
|
+
.option('--install-rpi', 'install a dotpi project on a Raspberry Pi SD card')
|
|
14
|
+
.option('--configure-host', 'configure the host system for dotpi development')
|
|
15
|
+
.option('-v, --version', 'display version information of this tool')
|
|
16
|
+
;
|
|
14
17
|
// .option('--launch-manager');
|
|
15
18
|
|
|
16
19
|
program.parse();
|
|
17
20
|
|
|
18
21
|
const options = program.opts();
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
let displayGreetings = true;
|
|
24
|
+
|
|
25
|
+
if (Object.keys(options).length === 0) {
|
|
26
|
+
console.log('');
|
|
27
|
+
program.help();
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
if (options.createProject) {
|
|
23
31
|
await createProject();
|
|
@@ -25,6 +33,9 @@ if (options.createProject) {
|
|
|
25
33
|
await installRpi();
|
|
26
34
|
} else if (options.configureHost) {
|
|
27
35
|
await configureHost();
|
|
36
|
+
} else if (options.version) {
|
|
37
|
+
displayGreetings = false;
|
|
38
|
+
console.log(packageVersion());
|
|
28
39
|
} else if (options.launchManager) {
|
|
29
40
|
console.log(chalk.yellow('> launchManager is not implemented yet'));
|
|
30
41
|
} else {
|
|
@@ -33,3 +44,7 @@ if (options.createProject) {
|
|
|
33
44
|
console.log(options);
|
|
34
45
|
}
|
|
35
46
|
|
|
47
|
+
|
|
48
|
+
if (displayGreetings) {
|
|
49
|
+
greetings();
|
|
50
|
+
}
|
|
@@ -126,12 +126,8 @@ dotpi echo_info "Configure wifi"
|
|
|
126
126
|
# - Bullseye: it should be sufficient in /boot
|
|
127
127
|
# - Bookworm: it breaks NetworkManager
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if [ -d "${source_path}" ] ; then
|
|
132
|
-
tar c -C "$source_path" '.' | tar xv -C "$destination_path"
|
|
133
|
-
fi
|
|
134
|
-
chmod 'u=rw,go=' "${destination_path}"/*
|
|
129
|
+
# apply from ${DOTPI_ROOT}/etc/network to /etc/NetworkManager/system-connections
|
|
130
|
+
dotpi connections_update
|
|
135
131
|
|
|
136
132
|
# unblock wifi in any case
|
|
137
133
|
#
|
|
@@ -306,7 +306,7 @@ destination_path="${DOTPI_ROOT}/etc/network"
|
|
|
306
306
|
mkdir -p -- "$destination_path"
|
|
307
307
|
if [ -d "$source_path" ] && [ -r "$source_path" ] ; then
|
|
308
308
|
(set -o pipefail ; \
|
|
309
|
-
cd -- "$source_path" && tar c "${tar_options[@]}" -- *.nmconnection \
|
|
309
|
+
cd -- "$source_path" && tar c "${tar_options[@]}" -- *.nmconnection* \
|
|
310
310
|
| tar x -C "$destination_path") || {
|
|
311
311
|
dotpi_echo_error "No network connection found in ${source_path}"
|
|
312
312
|
exit 1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotpi/module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "dotpi module management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"license": "BSD-3-clause",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@dotpi/javascript": "^1.
|
|
11
|
+
"@dotpi/javascript": "^1.6.1",
|
|
12
12
|
"execa": "^9.5.2",
|
|
13
13
|
"globby": "^14.0.2"
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotpi/module-module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "dotpi module management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./bin/dotpi_module",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "BSD-3-clause",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dotpi/javascript": "^1.
|
|
13
|
+
"@dotpi/javascript": "^1.6.1",
|
|
14
14
|
"@dotpi/module": "^1.6.1",
|
|
15
15
|
"commander": "^12.1.0"
|
|
16
16
|
}
|
|
@@ -215,7 +215,7 @@ dotpi_audio_device_select() (
|
|
|
215
215
|
_dotpi_audio_device_select_hifiberry
|
|
216
216
|
;;
|
|
217
217
|
|
|
218
|
-
'hifiberry dac+ standard'|'hifiberry pro'
|
|
218
|
+
'hifiberry dac+ standard'|'hifiberry pro')
|
|
219
219
|
dtoverlay=hifiberry-dacplus-std
|
|
220
220
|
_dotpi_audio_device_select_hifiberry
|
|
221
221
|
;;
|
|
@@ -253,6 +253,11 @@ dotpi_audio_device_select() (
|
|
|
253
253
|
'hifiberry amp3')
|
|
254
254
|
dtoverlay=hifiberry-amp3
|
|
255
255
|
_dotpi_audio_device_select_hifiberry
|
|
256
|
+
;;
|
|
257
|
+
|
|
258
|
+
'hifiberry amp2'|'hifiberry amp4')
|
|
259
|
+
dtoverlay=hifiberry-dacplus
|
|
260
|
+
_dotpi_audio_device_select_hifiberry
|
|
256
261
|
;;
|
|
257
262
|
|
|
258
263
|
'hifiberry amp4 pro')
|
|
@@ -49,6 +49,18 @@ _dotpi_connection_get_options() {
|
|
|
49
49
|
fi
|
|
50
50
|
;;
|
|
51
51
|
|
|
52
|
+
-i|--id)
|
|
53
|
+
if [ -z "$2" ] ; then
|
|
54
|
+
_dotpi_usage
|
|
55
|
+
_echo_empty_option_error "$1"
|
|
56
|
+
return 1
|
|
57
|
+
else
|
|
58
|
+
id="$2"
|
|
59
|
+
shift
|
|
60
|
+
fi
|
|
61
|
+
;;
|
|
62
|
+
|
|
63
|
+
|
|
52
64
|
--) # End of all options.
|
|
53
65
|
shift
|
|
54
66
|
break
|
|
@@ -84,7 +96,6 @@ dotpi_connection_write() (
|
|
|
84
96
|
file=
|
|
85
97
|
key=
|
|
86
98
|
value=
|
|
87
|
-
prepend_line_if_new=
|
|
88
99
|
if ! _dotpi_connection_get_options "${@}" ; then
|
|
89
100
|
return $?
|
|
90
101
|
fi
|
|
@@ -125,7 +136,7 @@ dotpi_connection_read() (
|
|
|
125
136
|
file=
|
|
126
137
|
key=
|
|
127
138
|
value=
|
|
128
|
-
|
|
139
|
+
id=
|
|
129
140
|
if ! _dotpi_connection_get_options "${@}" ; then
|
|
130
141
|
return $?
|
|
131
142
|
fi
|
|
@@ -150,7 +161,7 @@ dotpi_connection_read() (
|
|
|
150
161
|
|
|
151
162
|
# use printf to unquote strings
|
|
152
163
|
value="$(git config --file "$file" "$key")"
|
|
153
|
-
printf "$value
|
|
164
|
+
printf '%s\n' "$value"
|
|
154
165
|
|
|
155
166
|
return $?
|
|
156
167
|
)
|
|
@@ -169,7 +180,7 @@ dotpi_connection_delete() (
|
|
|
169
180
|
file=
|
|
170
181
|
key=
|
|
171
182
|
value=
|
|
172
|
-
|
|
183
|
+
id=
|
|
173
184
|
if ! _dotpi_connection_get_options "${@}" ; then
|
|
174
185
|
return $?
|
|
175
186
|
fi
|
|
@@ -197,3 +208,236 @@ dotpi_connection_delete() (
|
|
|
197
208
|
return $?
|
|
198
209
|
)
|
|
199
210
|
|
|
211
|
+
dotpi_connections_update() (
|
|
212
|
+
if [[ "$USER" != "root" ]]; then
|
|
213
|
+
dotpi_echo_error "This command must be run as root"
|
|
214
|
+
return 1
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
source_path="${DOTPI_ROOT}/etc/network"
|
|
218
|
+
destination_path='/etc/NetworkManager/system-connections'
|
|
219
|
+
mkdir -p -- "$destination_path"
|
|
220
|
+
|
|
221
|
+
# instantiate nmconnection templates
|
|
222
|
+
while IFS= read -r -d '' f ; do
|
|
223
|
+
destination_filename="$(basename -- "${f%.template}")"
|
|
224
|
+
dotpi envsubst < "$f" > "${destination_path}/${destination_filename}"
|
|
225
|
+
done < <(find "${source_path}" -name '*.nmconnection.template' -print0)
|
|
226
|
+
|
|
227
|
+
# copy regular nmconnection files
|
|
228
|
+
while IFS= read -r -d '' f ; do
|
|
229
|
+
destination_filename="$(basename -- "${f}")"
|
|
230
|
+
cp --force -- "$f" "${destination_path}/${destination_filename}"
|
|
231
|
+
done < <(find "${source_path}" -name '*.nmconnection' -print0)
|
|
232
|
+
|
|
233
|
+
# NetworkManager requires secure permissions
|
|
234
|
+
chmod 'u=rw,go=' "${destination_path}"/*
|
|
235
|
+
chown -R root:root "${destination_path}"
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
dotpi_connection_ap_id_get() (
|
|
239
|
+
|
|
240
|
+
connections_path="${DOTPI_ROOT}/etc/network"
|
|
241
|
+
|
|
242
|
+
while IFS= read -r -d '' f ; do
|
|
243
|
+
section='connection'
|
|
244
|
+
connection_type="$(dotpi_connection_read --file "$f" --key "${section}.type")"
|
|
245
|
+
if [[ "$connection_type" != 'wifi' && "$connection_type" != '802-11-wireless' ]] ; then
|
|
246
|
+
continue
|
|
247
|
+
fi
|
|
248
|
+
connection_id="$(dotpi_connection_read --file "$f" --key "${section}.id")"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
for section in 'wifi' '802-11-wireless' ; do
|
|
252
|
+
wifi_mode="$(dotpi_connection_read --file "$f" --key "${section}.mode")"
|
|
253
|
+
if [[ "$wifi_mode" == 'ap' ]] ; then
|
|
254
|
+
break
|
|
255
|
+
fi
|
|
256
|
+
done
|
|
257
|
+
|
|
258
|
+
if [[ "$wifi_mode" != 'ap' ]] ; then
|
|
259
|
+
continue
|
|
260
|
+
fi
|
|
261
|
+
|
|
262
|
+
echo "$connection_id"
|
|
263
|
+
return 0
|
|
264
|
+
|
|
265
|
+
done < <(find "${connections_path}" -name '*.nmconnection*' -print0)
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
dotpi_connection_ap_activate() (
|
|
269
|
+
if [[ "$USER" != "root" ]]; then
|
|
270
|
+
dotpi_echo_error "This command must be run as root"
|
|
271
|
+
return 1
|
|
272
|
+
fi
|
|
273
|
+
|
|
274
|
+
# sub-shell to keep everything local (functions and variables)
|
|
275
|
+
|
|
276
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
277
|
+
_dotpi_usage() {
|
|
278
|
+
echo "Usage: ${_dotpi_command} [--id <connection.id>]"
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
# Initialize all the option variables.
|
|
282
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
283
|
+
file=
|
|
284
|
+
key=
|
|
285
|
+
value=
|
|
286
|
+
id=
|
|
287
|
+
if ! _dotpi_connection_get_options "${@}" ; then
|
|
288
|
+
return $?
|
|
289
|
+
fi
|
|
290
|
+
|
|
291
|
+
if [ -z "$id" ] ; then
|
|
292
|
+
dotpi_echo_warning "Missing id option, using first access point connection"
|
|
293
|
+
id="$(dotpi_connection_ap_id_get)"
|
|
294
|
+
if [ -z "$id" ] ; then
|
|
295
|
+
dotpi_echo_error "No access point connection found"
|
|
296
|
+
return 1
|
|
297
|
+
fi
|
|
298
|
+
fi
|
|
299
|
+
|
|
300
|
+
connections_path="${DOTPI_ROOT}/etc/network"
|
|
301
|
+
|
|
302
|
+
# first, activate the requested access point
|
|
303
|
+
while IFS= read -r -d '' f ; do
|
|
304
|
+
section='connection'
|
|
305
|
+
|
|
306
|
+
connection_id="$(dotpi_connection_read --file "$f" --key "${section}.id")"
|
|
307
|
+
if [[ "$connection_id" != "$id" ]] ; then
|
|
308
|
+
continue
|
|
309
|
+
fi
|
|
310
|
+
|
|
311
|
+
connection_type="$(dotpi_connection_read --file "$f" --key "${section}.type")"
|
|
312
|
+
if [[ "$connection_type" != 'wifi' && "$connection_type" != '802-11-wireless' ]] ; then
|
|
313
|
+
continue
|
|
314
|
+
fi
|
|
315
|
+
|
|
316
|
+
for section in 'wifi' '802-11-wireless' ; do
|
|
317
|
+
wifi_mode="$(dotpi_connection_read --file "$f" --key "${section}.mode")"
|
|
318
|
+
if [[ "$wifi_mode" == 'ap' ]] ; then
|
|
319
|
+
break
|
|
320
|
+
fi
|
|
321
|
+
done
|
|
322
|
+
|
|
323
|
+
if [[ "$wifi_mode" != 'ap' ]] ; then
|
|
324
|
+
continue
|
|
325
|
+
fi
|
|
326
|
+
|
|
327
|
+
dotpi_echo_info "Activating connection id: ${connection_id}"
|
|
328
|
+
connection_autoconnect='true'
|
|
329
|
+
dotpi_connection_write --file "$f" --key 'connection.autoconnect' \
|
|
330
|
+
--value "$connection_autoconnect"
|
|
331
|
+
|
|
332
|
+
break
|
|
333
|
+
|
|
334
|
+
done < <(find "${connections_path}" -name '*.nmconnection*' -print0)
|
|
335
|
+
|
|
336
|
+
if [[ "$connection_id" != "$id" ]] ; then
|
|
337
|
+
dotpi_echo_error "Access point connection id ${id} not found"
|
|
338
|
+
return 1
|
|
339
|
+
fi
|
|
340
|
+
|
|
341
|
+
if [[ "$wifi_mode" != 'ap' ]] ; then
|
|
342
|
+
dotpi_echo_error "Connection id ${id} is not an access point"
|
|
343
|
+
return 1
|
|
344
|
+
fi
|
|
345
|
+
|
|
346
|
+
# then, on success only, deactivate other access points
|
|
347
|
+
while IFS= read -r -d '' f ; do
|
|
348
|
+
section='connection'
|
|
349
|
+
|
|
350
|
+
connection_id="$(dotpi_connection_read --file "$f" --key "${section}.id")"
|
|
351
|
+
if [[ "$connection_id" == "$id" ]] ; then
|
|
352
|
+
continue
|
|
353
|
+
fi
|
|
354
|
+
|
|
355
|
+
connection_type="$(dotpi_connection_read --file "$f" --key "${section}.type")"
|
|
356
|
+
if [[ "$connection_type" != 'wifi' && "$connection_type" != '802-11-wireless' ]] ; then
|
|
357
|
+
continue
|
|
358
|
+
fi
|
|
359
|
+
|
|
360
|
+
dotpi_echo_info "Deactivating connection id: ${connection_id}"
|
|
361
|
+
connection_autoconnect='false'
|
|
362
|
+
dotpi_connection_write --file "$f" --key 'connection.autoconnect' \
|
|
363
|
+
--value "$connection_autoconnect"
|
|
364
|
+
|
|
365
|
+
done < <(find "${connections_path}" -name '*.nmconnection*' -print0)
|
|
366
|
+
|
|
367
|
+
dotpi_connections_update
|
|
368
|
+
systemctl restart NetworkManager.service || {
|
|
369
|
+
return_code=$?
|
|
370
|
+
dotpi echo_error "error while restarting NetworkManager.service: ${return_code}"
|
|
371
|
+
return "${return_code}"
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
dotpi_connection_ap_deactivate() (
|
|
377
|
+
if [[ "$USER" != "root" ]]; then
|
|
378
|
+
dotpi_echo_error "This command must be run as root"
|
|
379
|
+
return 1
|
|
380
|
+
fi
|
|
381
|
+
|
|
382
|
+
# sub-shell to keep everything local (functions and variables)
|
|
383
|
+
|
|
384
|
+
_dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
|
|
385
|
+
_dotpi_usage() {
|
|
386
|
+
echo "Usage: ${_dotpi_command}"
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
# Initialize all the option variables.
|
|
390
|
+
# This ensures we are not contaminated by variables from the environment.
|
|
391
|
+
file=
|
|
392
|
+
key=
|
|
393
|
+
value=
|
|
394
|
+
id=
|
|
395
|
+
if ! _dotpi_connection_get_options "${@}" ; then
|
|
396
|
+
return $?
|
|
397
|
+
fi
|
|
398
|
+
|
|
399
|
+
if [[ "$id" != '' ]] ; then
|
|
400
|
+
dotpi_echo_error "id option is not valid for deactivating all access points"
|
|
401
|
+
return 1
|
|
402
|
+
fi
|
|
403
|
+
|
|
404
|
+
connections_path="${DOTPI_ROOT}/etc/network"
|
|
405
|
+
|
|
406
|
+
# first, deactivate access point
|
|
407
|
+
while IFS= read -r -d '' f ; do
|
|
408
|
+
section='connection'
|
|
409
|
+
connection_id="$(dotpi_connection_read --file "$f" --key "${section}.id")"
|
|
410
|
+
connection_type="$(dotpi_connection_read --file "$f" --key "${section}.type")"
|
|
411
|
+
if [[ "$connection_type" != 'wifi' && "$connection_type" != '802-11-wireless' ]] ; then
|
|
412
|
+
continue
|
|
413
|
+
fi
|
|
414
|
+
|
|
415
|
+
for section in 'wifi' '802-11-wireless' ; do
|
|
416
|
+
wifi_mode="$(dotpi_connection_read --file "$f" --key "${section}.mode")"
|
|
417
|
+
if [[ "$wifi_mode" == 'ap' ]] ; then
|
|
418
|
+
break
|
|
419
|
+
fi
|
|
420
|
+
done
|
|
421
|
+
|
|
422
|
+
if [[ "$wifi_mode" == 'ap' ]] ; then
|
|
423
|
+
dotpi_echo_info "Deactivating connection id: ${connection_id}"
|
|
424
|
+
connection_autoconnect='false'
|
|
425
|
+
dotpi_connection_write --file "$f" --key 'connection.autoconnect' --value 'false'
|
|
426
|
+
|
|
427
|
+
else
|
|
428
|
+
dotpi_echo_info "Activating connection id: ${connection_id}"
|
|
429
|
+
connection_autoconnect='false'
|
|
430
|
+
dotpi_connection_write --file "$f" --key 'connection.autoconnect' --value 'true'
|
|
431
|
+
fi
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
done < <(find "${connections_path}" -name '*.nmconnection*' -print0)
|
|
435
|
+
|
|
436
|
+
dotpi_connections_update
|
|
437
|
+
systemctl restart NetworkManager.service || {
|
|
438
|
+
return_code=$?
|
|
439
|
+
dotpi echo_error "error while restarting NetworkManager.service: ${return_code}"
|
|
440
|
+
return "${return_code}"
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
)
|
|
@@ -76,15 +76,15 @@ dotpi_color_orange='\e[0;33m'
|
|
|
76
76
|
dotpi_color_green='\e[0;32m'
|
|
77
77
|
|
|
78
78
|
dotpi_echo_error() {
|
|
79
|
-
printf "${dotpi_color_red}ERROR: ${dotpi_color_none}${*}
|
|
79
|
+
printf "${dotpi_color_red}ERROR: ${dotpi_color_none}%s\n" "${*}" >&2
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
dotpi_echo_warning() {
|
|
83
|
-
printf "${dotpi_color_orange}WARNING: ${dotpi_color_none}${*}
|
|
83
|
+
printf "${dotpi_color_orange}WARNING: ${dotpi_color_none}%s\n" "${*}" >&2
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
dotpi_echo_info() {
|
|
87
|
-
printf "${dotpi_color_green}INFO: ${dotpi_color_none}${*}
|
|
87
|
+
printf "${dotpi_color_green}INFO: ${dotpi_color_none}%s\n" "${*}" >&2
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
|
|
@@ -122,8 +122,35 @@ dotpi_sed() {
|
|
|
122
122
|
return $?
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
dotpi_envsubst() {
|
|
126
|
+
# envsubst with support for default values:
|
|
127
|
+
# $VAR
|
|
128
|
+
# ${VAR}
|
|
129
|
+
# ${VAR:-default} -> use default if VAR is unset or empty
|
|
130
|
+
# ${VAR-default} -> use default if VAR is unset (empty allowed)
|
|
131
|
+
perl -pe '
|
|
132
|
+
s/\$(\w+)|\$\{(\w+)(?:(:?-)([^}]*))?\}/
|
|
133
|
+
do {
|
|
134
|
+
my ($simple,$name,$op,$def) = ($1,$2,$3,$4);
|
|
135
|
+
if ($simple) {
|
|
136
|
+
defined $ENV{$simple} ? $ENV{$simple} : ""
|
|
137
|
+
} else {
|
|
138
|
+
if (defined $op) {
|
|
139
|
+
if ($op eq ":-") {
|
|
140
|
+
(defined $ENV{$name} && length $ENV{$name}) ? $ENV{$name} : $def
|
|
141
|
+
} else { # "-" operator: use default only if unset
|
|
142
|
+
defined $ENV{$name} ? $ENV{$name} : $def
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
defined $ENV{$name} ? $ENV{$name} : ""
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}/ge
|
|
149
|
+
'
|
|
150
|
+
}
|
|
151
|
+
|
|
125
152
|
# dotpi_uuidgen
|
|
126
|
-
if
|
|
153
|
+
if command -v uuidgen > /dev/null ; then
|
|
127
154
|
dotpi_uuidgen() {
|
|
128
155
|
uuidgen | tr '[:upper:]' '[:lower:]'
|
|
129
156
|
}
|
|
@@ -144,7 +171,7 @@ dotpi_file_word_size() {
|
|
|
144
171
|
return 1
|
|
145
172
|
fi
|
|
146
173
|
|
|
147
|
-
echo "$(file "$1" | perl -pe 's/.*(32|64)-bit.*/$1/' )"
|
|
174
|
+
echo "$(file "$(dotpi readlink_follow "$1")" | perl -pe 's/.*(32|64)-bit.*/$1/' )"
|
|
148
175
|
}
|
|
149
176
|
|
|
150
177
|
# requires ts form moretuils
|
|
@@ -16,8 +16,13 @@ export DOTPI_ROOT
|
|
|
16
16
|
export PATH="${PATH}:${DOTPI_ROOT}/usr/bin"
|
|
17
17
|
export PATH="${PATH}:${DOTPI_ROOT}/bin"
|
|
18
18
|
|
|
19
|
+
# functions are needed to initialise environment
|
|
19
20
|
source "${DOTPI_ROOT}/share/dotpi_functions.bash"
|
|
21
|
+
|
|
22
|
+
# export defined variables
|
|
23
|
+
set -a
|
|
20
24
|
source "${DOTPI_ROOT}/share/dotpi_environment.bash"
|
|
25
|
+
set +a
|
|
21
26
|
|
|
22
27
|
#### installed modules
|
|
23
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotpi/tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.2",
|
|
4
4
|
"description": "Set of scripts for managing dotpi fleets of Raspberry Pi",
|
|
5
5
|
"author": "Jean-Philippe Lambert",
|
|
6
6
|
"contributors": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"license": "BSD-3-Clause",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@dotpi/javascript": "^1.
|
|
39
|
+
"@dotpi/javascript": "^1.6.1",
|
|
40
40
|
"@dotpi/module": "^1.5.0",
|
|
41
41
|
"chalk": "^5.3.0",
|
|
42
42
|
"commander": "^12.1.0",
|
|
@@ -45,5 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"lerna": "^8.1.9"
|
|
48
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "f795b77d0fc1e179391f3bfff4308932f6ef581f"
|
|
49
50
|
}
|
package/src/create-project.js
CHANGED
|
@@ -249,10 +249,21 @@ export async function configureWiFi(data, mocks = null) {
|
|
|
249
249
|
prompts.inject(Object.values(mocks));
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
const wifiApInstanceSuffix = '-${dotpi_instance_number}';
|
|
253
|
+
|
|
252
254
|
// https://people.freedesktop.org/~lkundrak/nm-dbus-api/nm-settings.html
|
|
253
255
|
// @note - let's consider we always use wpa-psk for now
|
|
254
256
|
|
|
255
257
|
const computedValues = {};
|
|
258
|
+
|
|
259
|
+
const onSubmit = (prompt, answer, answers) => {
|
|
260
|
+
Object.assign(computedValues, { [prompt.name]: answer });
|
|
261
|
+
if (answers.wifiMode === 'ap') {
|
|
262
|
+
// will be specialised with instance number
|
|
263
|
+
Object.assign(computedValues, { connectionIsTemplate: true } );
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
256
267
|
const answers = await prompts([
|
|
257
268
|
{
|
|
258
269
|
type: 'select',
|
|
@@ -270,24 +281,63 @@ export async function configureWiFi(data, mocks = null) {
|
|
|
270
281
|
message: 'Wifi name (SSID):',
|
|
271
282
|
validate: value => {
|
|
272
283
|
|
|
273
|
-
|
|
284
|
+
let ssid = value;
|
|
285
|
+
|
|
286
|
+
// remove instance number suffix
|
|
287
|
+
const instanceNumberRegexp = new RegExp(
|
|
288
|
+
// escape dollar sign for regexp
|
|
289
|
+
wifiApInstanceSuffix.replace(/\$/g, '\\$'),
|
|
290
|
+
// replace all occurrences
|
|
291
|
+
'g'
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
ssid = ssid.replace(instanceNumberRegexp, '');
|
|
295
|
+
let wifiId = ssid
|
|
296
|
+
.toLowerCase()
|
|
297
|
+
.replace(/[^a-z0-9\-_]/g, '-');
|
|
298
|
+
|
|
299
|
+
if (computedValues.wifiMode === 'ap') {
|
|
300
|
+
// reserve size for instance number substitution
|
|
301
|
+
ssid += '-0000';
|
|
302
|
+
|
|
303
|
+
// for NetworkManager identifier
|
|
304
|
+
wifiId += '-ap';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const ssidSize = new Blob([ssid]).size;
|
|
274
308
|
if (ssidSize === 0) {
|
|
275
309
|
return 'Please provide a non-empty SSID';
|
|
276
310
|
} else if(ssidSize > 32) {
|
|
277
|
-
return `'${
|
|
311
|
+
return `'${ssid}' is too long (more than 32 bytes)`;
|
|
278
312
|
}
|
|
279
313
|
|
|
280
|
-
const
|
|
281
|
-
const configPath = path.join(PATH_NETWORK_DIRECTORY, value);
|
|
314
|
+
const configPath = path.join(PATH_NETWORK_DIRECTORY, wifiId);
|
|
282
315
|
|
|
283
316
|
// @TODO: file is created later, this test is bypassed
|
|
284
317
|
if (fs.existsSync(configPath)) {
|
|
285
|
-
return `A WiFi configuration named "${
|
|
318
|
+
return `A WiFi configuration named "${wifiId}" already exists`;
|
|
286
319
|
}
|
|
287
320
|
|
|
288
321
|
Object.assign(computedValues, { wifiId });
|
|
289
322
|
return true;
|
|
290
323
|
},
|
|
324
|
+
initial: (previous, values) => {
|
|
325
|
+
if (values.wifiMode === 'ap') {
|
|
326
|
+
return `dotpi-${data.projectName}${wifiApInstanceSuffix}`;
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
type: 'select',
|
|
333
|
+
name: 'wifiBand',
|
|
334
|
+
message: 'Select WiFi band:',
|
|
335
|
+
choices: [
|
|
336
|
+
{ title: 'Automatic', value: 'automatic' },
|
|
337
|
+
{ title: '2.4 GHz only', value: 'bg' },
|
|
338
|
+
{ title: '5 GHz only', value: 'a' },
|
|
339
|
+
],
|
|
340
|
+
initial: 0,
|
|
291
341
|
},
|
|
292
342
|
{
|
|
293
343
|
type: 'text',
|
|
@@ -305,12 +355,17 @@ export async function configureWiFi(data, mocks = null) {
|
|
|
305
355
|
return true;
|
|
306
356
|
},
|
|
307
357
|
},
|
|
308
|
-
], { onCancel });
|
|
358
|
+
], { onCancel, onSubmit });
|
|
309
359
|
|
|
310
360
|
Object.assign(answers, computedValues);
|
|
311
361
|
|
|
312
|
-
const { wifiId, wifiMode } = answers;
|
|
313
|
-
|
|
362
|
+
const { wifiId, wifiMode, connectionIsTemplate } = answers;
|
|
363
|
+
let connectionPath = path.join(PATH_NETWORK_DIRECTORY, `${wifiId}.nmconnection`);
|
|
364
|
+
|
|
365
|
+
if (connectionIsTemplate) {
|
|
366
|
+
connectionPath += '.template';
|
|
367
|
+
}
|
|
368
|
+
|
|
314
369
|
let connectionConfig = null;
|
|
315
370
|
|
|
316
371
|
switch (wifiMode) {
|
|
@@ -323,7 +378,7 @@ export async function configureWiFi(data, mocks = null) {
|
|
|
323
378
|
max: 2147483647,
|
|
324
379
|
round: 0,
|
|
325
380
|
initial: 0,
|
|
326
|
-
}, { onCancel });
|
|
381
|
+
}, { onCancel, onSubmit });
|
|
327
382
|
|
|
328
383
|
connectionConfig = renderTemplate('infrastructure.nmconnection', {
|
|
329
384
|
wifiPriority,
|
|
@@ -332,7 +387,7 @@ export async function configureWiFi(data, mocks = null) {
|
|
|
332
387
|
break;
|
|
333
388
|
}
|
|
334
389
|
case 'ap': {
|
|
335
|
-
connectionConfig = renderTemplate('ap.nmconnection', {
|
|
390
|
+
connectionConfig = renderTemplate('ap.nmconnection.template', {
|
|
336
391
|
...answers,
|
|
337
392
|
});
|
|
338
393
|
break;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
id=${d.wifiId}
|
|
3
3
|
type=wifi
|
|
4
4
|
# do not use external AP by default
|
|
5
|
-
autoconnect=
|
|
5
|
+
autoconnect=false
|
|
6
6
|
interface-name=wlan0
|
|
7
7
|
|
|
8
8
|
[wifi]
|
|
@@ -11,12 +11,20 @@ ssid=${d.wifiSsid}
|
|
|
11
11
|
# disable power management
|
|
12
12
|
powersave=2
|
|
13
13
|
|
|
14
|
+
# "a" for 5Ghz only, "bg" for 2.4GHz only, default for automatic selection
|
|
15
|
+
band=${d.wifiBand === 'automatic' ? '' : d.wifiBand}
|
|
16
|
+
|
|
14
17
|
[wifi-security]
|
|
15
18
|
key-mgmt=wpa-psk
|
|
16
19
|
psk=${d.wifiPsk}
|
|
20
|
+
# disable WPA1
|
|
21
|
+
proto=rsn;
|
|
17
22
|
|
|
18
23
|
[ipv4]
|
|
24
|
+
# access-point
|
|
19
25
|
method=shared
|
|
26
|
+
# no route via clients
|
|
27
|
+
never-default=true
|
|
20
28
|
|
|
21
29
|
[ipv6]
|
|
22
30
|
addr-gen-mode=default
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
id=${d.wifiId}
|
|
3
3
|
type=wifi
|
|
4
4
|
interface-name=wlan0
|
|
5
|
+
autoconnect=true
|
|
5
6
|
autoconnect-priority=${d.wifiPriority}
|
|
6
7
|
# always retry to connect
|
|
7
8
|
autoconnect-retries=0
|
|
@@ -11,9 +12,12 @@ auth-retries=0
|
|
|
11
12
|
[wifi]
|
|
12
13
|
mode=infrastructure
|
|
13
14
|
ssid=${d.wifiSsid}
|
|
15
|
+
|
|
14
16
|
# disable power management
|
|
15
17
|
powersave=2
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
# "a" for 5Ghz only, "bg" for 2.4GHz only, default for automatic selection
|
|
20
|
+
# band=
|
|
17
21
|
|
|
18
22
|
[wifi-security]
|
|
19
23
|
key-mgmt=wpa-psk
|