@dotpi/tools 2.8.0 → 2.9.0

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 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 module
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
@@ -19,6 +19,11 @@ const options = program.opts();
19
19
 
20
20
  greetings();
21
21
 
22
+ if (Object.keys(options).length === 0) {
23
+ console.log('');
24
+ program.help();
25
+ }
26
+
22
27
  if (options.createProject) {
23
28
  await createProject();
24
29
  } else if (options.installRpi) {
@@ -8,7 +8,7 @@ local_path="$(dirname -- "$local_file")"
8
8
  log_file="${1:-${local_file}-$(date +"%Y%m%d-%H%M%S").log}"
9
9
 
10
10
  # Self log
11
- exec &> >(dotpi log "$log_file")
11
+ exec &> >(tee -a "$log_file")
12
12
 
13
13
  DOTPI_ROOT="${DOTPI_ROOT:-/opt/dotpi}"
14
14
 
@@ -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
- source_path="${DOTPI_ROOT}/etc/network"
130
- destination_path='/etc/NetworkManager/system-connections'
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
@@ -101,7 +101,11 @@ dotpi echo_info "Install Node.js"
101
101
 
102
102
  word_size="$(dotpi file_word_size "$(which file)" )"
103
103
  if [[ $word_size == "32" ]] ; then
104
- node_arch=armv7l
104
+ if [[ "$(uname -m)" == "armv6l" ]] ; then
105
+ node_arch=armv6l
106
+ else
107
+ node_arch=armv7l
108
+ fi
105
109
  else
106
110
  node_arch=arm64
107
111
  fi
@@ -112,8 +116,10 @@ sudo rm -rf -- "$N_PREFIX" || {
112
116
  error_exit $? "rm ${N_PREFIX}" $error_exit_code_node
113
117
  }
114
118
 
115
-
116
- sudo mkdir -p -- "$N_PREFIX" || {
119
+ {
120
+ sudo mkdir -p -- "$N_PREFIX"
121
+ sudo chmod a+rw "$N_PREFIX"
122
+ } || {
117
123
  error_exit $? "mkdir ${N_PREFIX}" $error_exit_code_node
118
124
  }
119
125
 
@@ -123,7 +129,38 @@ while ! curl -L https://bit.ly/n-install -o /tmp/n-install ; do
123
129
  echo "trying again"
124
130
  done
125
131
 
126
- while ! sudo N_PREFIX="${DOTPI_ROOT}/share/n" bash /tmp/n-install -y -a "$node_arch" "$dotpi_node_version" ; do
132
+ environment_definitions=(
133
+ # n-install checks for N_PREFIX to not be set in .bashrc
134
+ # "N_PREFIX='${N_PREFIX}'"
135
+
136
+ "N_ARCH='${node_arch}'"
137
+ )
138
+
139
+ if [[ $node_arch == "armv6l" ]] ; then
140
+ # armv6 is not supported any more in offical node.js builds
141
+ environment_definitions+=(
142
+ "N_NODE_MIRROR='https://unofficial-builds.nodejs.org/download/release'"
143
+ )
144
+ fi
145
+
146
+ echo "
147
+
148
+ # dotpi: environment variables for n (node version manager)
149
+ " >> "${HOME}/.bashrc" || {
150
+ error_exit $? "n environment in ${HOME}/.bashrc" $error_exit_code_node
151
+ }
152
+
153
+ for definition in "${environment_definitions[@]}" ; do
154
+ cmd="export ${definition}"
155
+ eval "$cmd"
156
+ echo "$cmd" >> "${HOME}/.bashrc" || {
157
+ error_exit $? "n environment in ${HOME}/.bashrc" $error_exit_code_node
158
+ }
159
+ done
160
+
161
+ # n-install checks for N_PREFIX to not be set in bashrc
162
+ # however, it must be set for the installation
163
+ while ! N_PREFIX="$N_PREFIX" bash /tmp/n-install -y -a "$node_arch" "$dotpi_node_version" ; do
127
164
  dotpi echo_warning "Error with n-install"
128
165
  sleep 1
129
166
  echo "trying again"
@@ -131,21 +168,22 @@ while ! sudo N_PREFIX="${DOTPI_ROOT}/share/n" bash /tmp/n-install -y -a "$node_a
131
168
  sudo mkdir -p -- "$N_PREFIX"
132
169
  done
133
170
 
134
- rm /tmp/n-install
135
- sudo bash -c "cat >> '/root/.bashrc' << EOF
136
171
 
137
- # dotpi: force the usage of -a for correct architecture
138
- # (n relies on uname, which tells about the kernel, not the executables)
172
+ rm -f /tmp/n-install
139
173
 
140
- alias n='n -a ${node_arch}'
141
174
 
142
- EOF
143
- " || {
144
- error_exit $? "n alias in /root/.bashrc" $error_exit_code_node
145
- }
146
175
 
147
- source="${N_PREFIX}/bin"
148
- destination="/usr/bin"
176
+ # echo "
177
+ # # dotpi: force the usage of -a for correct architecture
178
+ # # (n relies on uname, which tells about the kernel, not the executables)
179
+
180
+ # alias n='${environment_variables[*]} n -a ${node_arch}'
181
+ # " >> "${HOME}/.bashrc" || {
182
+ # error_exit $? "n alias in /root/.bashrc" $error_exit_code_node
183
+ # }
184
+
185
+ source_path="${N_PREFIX}/bin"
186
+ destination_path="/usr/bin"
149
187
  executables=(
150
188
  corepack
151
189
  n
@@ -154,8 +192,8 @@ executables=(
154
192
  npx
155
193
  )
156
194
  for executable in "${executables[@]}" ; do
157
- sudo ln -s -f "${source}/${executable}" "${destination}/${executable}" || {
158
- error_exit $? "symlink to ${destination}/${executable}" $error_exit_code_node
195
+ sudo ln -s -f "${source_path}/${executable}" "${destination_path}/${executable}" || {
196
+ error_exit $? "symlink to ${destination_path}/${executable}" $error_exit_code_node
159
197
  }
160
198
  done
161
199
 
@@ -58,7 +58,7 @@ export async function variableRead({
58
58
  uid,
59
59
  command: ` \
60
60
  for v in "\${${variable}[@]}" ; do \
61
- printf "\$v\\0" ; \
61
+ printf '%s\\0' "\$v"; \
62
62
  done \
63
63
  `,
64
64
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotpi/javascript",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "dotpi javascript utilities",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotpi/module",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
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.5.1",
11
+ "@dotpi/javascript": "^1.6.0",
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.7.2",
3
+ "version": "1.8.0",
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.5.1",
13
+ "@dotpi/javascript": "^1.6.0",
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'|'hifiberry amp2'|'hifiberry amp4')
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')
@@ -520,8 +525,9 @@ dotpi_audio_device_init() (
520
525
 
521
526
  'raspiaudio mic+ v1' | 'raspiaudio mic+ v2')
522
527
 
523
- amixer -D sysdefault sset -- 'Master' 'on'
524
- amixer -D sysdefault sset -- 'Master' '0%'
528
+ # no controller for device, use default 'Master' control
529
+ amixer sset -- 'Master' 'on'
530
+ amixer sset -- 'Master' '80%'
525
531
 
526
532
  alsactl store
527
533
  ;;
@@ -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
- prepend_line_if_new=
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\n"
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
- prepend_line_if_new=
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}${*}\n" >&2
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}${*}\n" >&2
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}${*}\n" >&2
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 $( command -v uuidgen > /dev/null ) ; then
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
 
@@ -14,7 +14,7 @@ while true ; do
14
14
  (
15
15
  (( trial_count = 0 ))
16
16
  while (( trial_count < trial_count_max )) ; do
17
- "${local_path}/../bin/dotpi_pipewire_relink" && exit 0
17
+ nice "${local_path}/../bin/dotpi_pipewire_relink" && exit 0
18
18
  sleep 3
19
19
  (( ++trial_count ))
20
20
  done
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotpi/tools",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
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.5.1",
39
+ "@dotpi/javascript": "^1.6.0",
40
40
  "@dotpi/module": "^1.5.0",
41
41
  "chalk": "^5.3.0",
42
42
  "commander": "^12.1.0",
@@ -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
- const ssidSize = new Blob([value]).size;
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 `'${value}' is too long (more than 32 bytes)`;
311
+ return `'${ssid}' is too long (more than 32 bytes)`;
278
312
  }
279
313
 
280
- const wifiId = value.toLowerCase().replace(/[^a-z0-9\-_]/g, '_');
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 "${value}" already exists`;
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
- const connectionPath = path.join(PATH_NETWORK_DIRECTORY, `${wifiId}.nmconnection`);
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=true
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
- # band=a
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