@dotpi/tools 2.13.1 → 2.14.1

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.
@@ -109,6 +109,9 @@ DOTPI_ROOT="${local_path}/.."
109
109
 
110
110
  source "${DOTPI_ROOT}/share/dotpi_init.bash"
111
111
 
112
+ # not a running dotpi system
113
+ dotpi_filesystem_only='true'
114
+
112
115
  tmp_path="${project_path}/tmp"
113
116
  mkdir -p -- "$tmp_path"
114
117
 
@@ -502,8 +505,6 @@ if [ -f "$source_file_path" ] ; then
502
505
  mkdir -p -- "$destination_path"
503
506
  cp -- "$source_file_path" "${destination_path}/${destination_filename}"
504
507
  fi
505
- else
506
- dotpi_echo_warning "firstrun.sh not found"
507
508
  fi
508
509
 
509
510
  # configure cmdline.txt for firstun script, if not already here
@@ -275,12 +275,6 @@ error_exit_code_audio=6
275
275
 
276
276
  dotpi echo_info "Configure audio"
277
277
 
278
- # set alsa default output volume and unmute
279
- sudo dotpi audio_device_init || {
280
- dotpi echo_warning "Error while setting default output volume and unmute for ${dotpi_audio_device} device"
281
- $error_exit_code_audio
282
- }
283
-
284
278
  # over-ride calls to jack, to use pipewire instead
285
279
  # copy with prefix 000- to ensure it is loaded before default aarch64-linux-gnu.conf
286
280
  for f in /usr/share/doc/pipewire/examples/ld.so.conf.d/pipewire-jack-*.conf ; do
@@ -315,21 +309,51 @@ if [ -r "$source_path" ] ; then
315
309
  fi
316
310
  fi
317
311
 
318
- systemctl --user enable --now wireplumber.service || {
319
- dotpi echo_warning "error while enabling wireplumber.service now: ${?}"
320
- dotpi echo_warning "wireplumber.service will be available after a reboot"
312
+ # pipewire
313
+ "${DOTPI_ROOT}/share/dotpi_pipewire/dotpi_install" || {
314
+ dotpi echo_error "error while installing dotpi_pipewire: ${?}"
321
315
  # do not exit
322
316
  }
323
317
 
324
- "${DOTPI_ROOT}/share/dotpi_pipewire/dotpi_install" || {
325
- dotpi echo_error "error while installing dotpi_pipewire: ${?}"
318
+ regular_user="$(dotpi regular_user_get_name)"
319
+ # Before next boot, pipewire is only available in a pi@ machine
320
+ sudo systemd-run --quiet --pipe --wait --collect --machine="${regular_user}@" --user -- /bin/bash -c "$(cat <<'EOF'
321
+
322
+ # wireplumber
323
+ systemctl --user enable --now wireplumber.service || {
324
+ dotpi echo_error "Error while enabling wireplumber.service now: ${?}"
325
+ dotpi echo_warning "wireplumber.service will be available after a reboot"
326
+ # do not exit
327
+ }
328
+
329
+ # wait for pipewire Master volume to be available
330
+ (( i_max = 60 ))
331
+ (( i = 0 ))
332
+ while ! amixer sget -- Master > /dev/null 2>&1 ; do
333
+ sleep 1
334
+ (( i++ ))
335
+ if (( i > i_max )) ; then
336
+ dotpi echo_error "Error while waiting for pipewire Master volume to be available"
337
+ break
338
+ fi
339
+ done
340
+
341
+ # hardware and software audio device initialisation
342
+ dotpi audio_device_init || {
343
+ dotpi echo_error "Error while initialising audio device ${dotpi_audio_device}: ${?}"
344
+ dotpi echo_warning "Please run 'dotpi audio_device_init' after a reboot"
345
+ # do not exit
346
+ }
347
+
348
+ EOF
349
+ )" || {
350
+ dotpi echo_error "Error with audio setup. Please check it after a reboot"
326
351
  # do not exit
327
352
  }
328
353
 
329
354
  ############## dotpi modules
330
355
  error_exit_code_dotpi_modules=10
331
356
 
332
-
333
357
  declare -A dotpi_module_uninstall_modules
334
358
  for module in "${dotpi_module_uninstall_default[@]}" "${dotpi_module_uninstall[@]}" ; do
335
359
  dotpi_module_uninstall_modules["$module"]=1
@@ -9,6 +9,11 @@ fi
9
9
  # connect an audio bluetooth device, corresponding to dotpi_audio_bluetooth_mac,
10
10
  # using bluetoothctl,
11
11
  dotpi_audio_bluetooth_destination_connect() (
12
+ if [[ "$USER" != "root" ]]; then
13
+ dotpi echo_error "This command must be run as root"
14
+ return 1
15
+ fi
16
+
12
17
  destination_mac="$dotpi_audio_bluetooth_mac"
13
18
 
14
19
  dotpi_echo_info "Starting bluetoothctl process"
@@ -41,6 +46,18 @@ dotpi_audio_bluetooth_destination_connect() (
41
46
  fi
42
47
 
43
48
  if [[ "$status" == 'destination discovered' ]] ; then
49
+ dotpi_echo_info "Trusting destination"
50
+ echo "trust ${destination_mac}" >&${btctl_process[1]}
51
+ status='trusting'
52
+ fi
53
+
54
+ if [[ "$status" == "trusting" ]] \
55
+ && [[ "$output" =~ "trust succeeded" ]] ; then
56
+ dotpi_echo_info "Destination trusted"
57
+ status='destination trusted'
58
+ fi
59
+
60
+ if [[ "$status" == "destination trusted" ]] ; then
44
61
  dotpi_echo_info "Pairing destination"
45
62
  echo "pair ${destination_mac}" >&${btctl_process[1]}
46
63
  status='pairing'
@@ -64,28 +81,10 @@ dotpi_audio_bluetooth_destination_connect() (
64
81
  if [[ "$status" == "destination paired" ]] ; then
65
82
  dotpi_echo_info "Connecting destination"
66
83
  echo "connect ${destination_mac}" >&${btctl_process[1]}
67
- status='connecting'
68
- fi
69
-
70
- if [[ "$status" == "connecting" ]] \
71
- && [[ "$output" =~ "Connection successful" ]] ; then
72
- dotpi_echo_info "Destination connected"
73
- status='destination connected'
74
- fi
75
-
76
- if [[ "$status" == "destination connected" ]] ; then
77
- dotpi_echo_info "Trusting destination"
78
- echo "trust ${destination_mac}" >&${btctl_process[1]}
79
- status='trusting'
80
- fi
81
-
82
- if [[ "$status" == "trusting" ]] \
83
- && [[ "$output" =~ "trust succeeded" ]] ; then
84
- dotpi_echo_info "Destination trusted"
85
- status='destination trusted'
84
+ status='destination paired'
86
85
  fi
87
86
 
88
- if [[ "$status" == "destination trusted" ]] ; then
87
+ if [[ "$status" == "destination paired" ]] ; then
89
88
  dotpi_echo_info "Ending scan"
90
89
  echo "scan off" >&${btctl_process[1]}
91
90
  status='ending scan'
@@ -105,9 +104,16 @@ dotpi_audio_bluetooth_destination_connect() (
105
104
  fi
106
105
 
107
106
  done <&${btctl_process[0]}
107
+
108
+ dotpi_audio_bluetooth_destination_volume_init
108
109
  )
109
110
 
110
111
  dotpi_audio_bluetooth_destination_disconnect() (
112
+ if [[ "$USER" != "root" ]]; then
113
+ dotpi echo_error "This command must be run as root"
114
+ return 1
115
+ fi
116
+
111
117
  bluetoothctl -- remove "$dotpi_audio_bluetooth_mac"
112
118
  )
113
119
 
@@ -164,8 +170,8 @@ _dotpi_audio_bluetooth_destination_start_ue() (
164
170
  echo "$output" >&2
165
171
 
166
172
  # Connected and transport volume available
167
- if [[ "$output" =~ [CHG].*Transport.*/org/bluez/.*dev_"${destination_descriptor}".*Volume ]] \
168
- || [[ "$output" =~ ^Transport.*/org/bluez/.*dev_"${destination_descriptor}" ]] ; then
173
+ if [[ "$output" =~ [CHG].*Transport.*/org/bluez/.*dev_"${destination_descriptor}" ]] \
174
+ || [[ "$output" =~ [NEW].*Transport.*/org/bluez/.*dev_"${destination_descriptor}" ]] ; then
169
175
  kill ${btctl_process_PID}
170
176
  dotpi_echo_info "Destination started"
171
177
  return 0
@@ -296,51 +302,13 @@ dotpi_audio_bluetooth_destination_stop() (
296
302
 
297
303
  # set and save volume
298
304
  dotpi_audio_bluetooth_destination_volume_set() (
299
- destination_volume="$1"
300
- destination_device="dev_${dotpi_audio_bluetooth_mac//:/_}"
301
- destination_transport="$(bluetoothctl transport.list \
302
- | perl -ne 'if(m/Transport\s+(\/*${destination_device}[^\s]+).*$/) { print "${1}\n"; }')"
303
-
304
- if [[ -z "$destination_transport" ]] ; then
305
- dotpi_echo_error "Failed to set volume: audio bluetooth device not found"
306
- return 1
307
- fi
308
-
309
- bluetoothctl transport.volume "$destination_transport" "$destination_volume"
310
- if (( $? != 0 )) ; then
311
- dotpi_echo_error "Failed to set bluetooth destination volume"
312
- return 1
313
- else
314
- dotpi_echo_info "Bluetooth destination volume set to ${destination_volume}"
315
- fi
316
-
317
- if [[ "$destination_volume" == "$dotpi_audio_volume" ]] ; then
318
- # no change to write
319
- return 0
320
- fi
321
-
322
- # comment setting in project
323
- dotpi_configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
324
- --key dotpi_audio_volume
325
-
326
- # escape double-quote for now, to quote when writing later
327
- model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
328
-
329
- # write changed setting in instance
330
- dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
331
- --key dotpi_audio_volume \
332
- --value "$destination_volume"
333
-
305
+ # keep for compatibility
306
+ dotpi_audio_device_volume_set "$@"
334
307
  )
335
308
 
336
309
  # set volume to default
337
310
  dotpi_audio_bluetooth_destination_volume_init() (
338
- if [[ -z "$dotpi_audio_volume" ]] ; then
339
- dotpi_echo_warning "dotpi_audio_volume not set, keeping default volume"
340
- return 0
341
- fi
342
-
343
- destination_volume="$dotpi_audio_volume"
344
- dotpi_audio_bluetooth_destination_volume_set "$destination_volume"
311
+ # keep for compatibility
312
+ dotpi_audio_device_volume_init
345
313
  )
346
314
 
@@ -34,6 +34,7 @@ dotpi_audio_device_supported=(
34
34
  'raspberry pi digiamp+'
35
35
  'raspiaudio mic+ v1'
36
36
  'raspiaudio mic+ v2'
37
+ 'raspiaudio mic+ v3'
37
38
  'raspiaudio ultra'
38
39
  'ue boom 2'
39
40
  'ue boom 3'
@@ -271,10 +272,17 @@ dotpi_audio_device_select() (
271
272
  _dotpi_audio_device_select_raspiaudio
272
273
  ;;
273
274
 
275
+ 'raspiaudio mic+ v3')
276
+ # driver in kernel
277
+ dtoverlay=''
278
+ _dotpi_audio_device_select_raspiaudio
279
+ ;;
280
+
281
+
274
282
  # Raspiaudio ULTRA (WM8960 codec, driver in kernel)
275
283
  # Cf. https://forum.raspiaudio.com/t/ultra-installation-guide/21
276
284
  'raspiaudio ultra')
277
- dtoverlay=wm8960-soundcard
285
+ dtoverlay='wm8960-soundcard'
278
286
  _dotpi_audio_device_select_raspiaudio
279
287
  ;;
280
288
 
@@ -307,11 +315,10 @@ dotpi_audio_device_select() (
307
315
  return 0;
308
316
  fi
309
317
 
310
- dotpi_echo_warning 'Audio device model is specific to this instance'
311
318
 
312
319
  # comment setting in project
313
320
  dotpi_configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
314
- --key dotpi_audio_device
321
+ --key dotpi_audio_device
315
322
 
316
323
  # escape double-quote for now, to quote when writing later
317
324
  model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
@@ -319,46 +326,32 @@ dotpi_audio_device_select() (
319
326
  # write changed setting in instance
320
327
  # be sure to quote value
321
328
  dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
322
- --key dotpi_audio_device \
323
- --value \""${model_value}"\"
324
- )
325
-
326
- _dotpi_audio_device_disable_all() (
327
- exception_family="$1"
328
-
329
- if [[ "$exception_family" = "" ]] ; then
330
- dotpi_echo_info "Disabling all audio devices"
331
- else
332
- dotpi_echo_info "Disabling all audio devices except ${exception_family}"
333
- fi
329
+ --key dotpi_audio_device \
330
+ --value \""${model_value}"\"
334
331
 
335
- if [[ ! "$exception_family" = "headphones" ]] ; then
336
- _dotpi_audio_device_disable_headphones
337
- fi
338
-
339
- if [[ ! "$exception_family" = "hdmi" ]] ; then
340
- _dotpi_audio_device_disable_hdmi
341
- fi
332
+ source "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash"
342
333
 
343
- if [[ ! "$exception_family" = "raspberry_pi" ]] ; then
344
- _dotpi_audio_device_disable_raspberry_pi
334
+ # test for a running dotpi system
335
+ if [[ -z "$dotpi_filesystem_only" ]] ; then
336
+ dotpi_echo_warning "To finalise the audio device selection, please reboot and run 'dotpi audio_device_init'"
345
337
  fi
338
+ )
346
339
 
347
- if [[ ! "$exception_family" = "hifiberry" ]] ; then
348
- _dotpi_audio_device_disable_hifiberry
349
- fi
340
+ _dotpi_audio_device_disable_all() (
350
341
 
351
- if [[ ! "$exception_family" = "raspiaudio" ]] ; then
352
- _dotpi_audio_device_disable_raspiaudio
353
- fi
342
+ dotpi_echo_info "Disabling all audio devices"
354
343
 
344
+ _dotpi_audio_device_disable_headphones
345
+ _dotpi_audio_device_disable_hdmi
346
+ _dotpi_audio_device_disable_raspberry_pi
347
+ _dotpi_audio_device_disable_hifiberry
348
+ _dotpi_audio_device_disable_raspiaudio
355
349
  )
356
350
 
357
351
  _dotpi_audio_device_select_headphones() (
352
+ _dotpi_audio_device_disable_all
358
353
  dotpi_echo_info "Installing Headphones (default) audio device"
359
354
 
360
- _dotpi_audio_device_disable_all headphones
361
-
362
355
  # un-comment dtparam=audio as it must be set first
363
356
  # (setting at the end the the file fails)
364
357
  pattern="$(dotpi_configuration_get_pattern --prefix "# dtparam=audio")"
@@ -366,17 +359,14 @@ _dotpi_audio_device_select_headphones() (
366
359
  )
367
360
 
368
361
  _dotpi_audio_device_select_bluetooth() (
369
- _dotpi_audio_device_disable_all bluetooth
370
- bluetoothctl power off
371
- rfkill unblock all
372
- sudo bluetoothctl power on
362
+ _dotpi_audio_device_disable_all
363
+ dotpi_echo_info "Enabling Bluetooth"
373
364
  )
374
365
 
375
366
  _dotpi_audio_device_select_raspberry_pi() (
367
+ _dotpi_audio_device_disable_all
376
368
  dotpi_echo_info "Configuring Raspberry Pi audio device '${model}'"
377
369
 
378
- _dotpi_audio_device_disable_all raspberry_pi
379
-
380
370
  mkdir -p "$(dirname -- "$config_file")"
381
371
  cat >> "$config_file" << EOF
382
372
 
@@ -388,10 +378,9 @@ EOF
388
378
 
389
379
 
390
380
  _dotpi_audio_device_select_hifiberry() (
381
+ _dotpi_audio_device_disable_all
391
382
  dotpi_echo_info "Configuring HiFiBerry audio device '${model}'"
392
383
 
393
- _dotpi_audio_device_disable_all hifiberry
394
-
395
384
  mkdir -p "$(dirname -- "$config_file")"
396
385
  cat >> "$config_file" << EOF
397
386
 
@@ -402,9 +391,12 @@ EOF
402
391
  )
403
392
 
404
393
  _dotpi_audio_device_select_raspiaudio() (
394
+ _dotpi_audio_device_disable_all
405
395
  dotpi_echo_info "Configuring Raspiaudio device '${model}'"
406
396
 
407
- _dotpi_audio_device_disable_all raspiaudio
397
+ if [[ "$dtoverlay" == "" ]] ; then
398
+ return 0
399
+ fi
408
400
 
409
401
  mkdir -p "$(dirname -- "$config_file")"
410
402
  cat >> "$config_file" << EOF
@@ -461,8 +453,7 @@ _dotpi_audio_device_disable_raspiaudio() (
461
453
  )
462
454
 
463
455
  _dotpi_audio_device_volume_set_alsa() (
464
- amixer -- sset "$control" "$volume"
465
- alsactl store
456
+ amixer -D sysdefault -- sset "$control" "$volume"
466
457
 
467
458
  if [[ "$volume" == "$dotpi_audio_volume" ]] ; then
468
459
  # no change to write
@@ -478,8 +469,8 @@ _dotpi_audio_device_volume_set_alsa() (
478
469
 
479
470
  # write changed setting in instance
480
471
  dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
481
- --key dotpi_audio_volume \
482
- --value "$volume"
472
+ --key dotpi_audio_volume \
473
+ --value "$volume"
483
474
  )
484
475
 
485
476
  dotpi_audio_device_init() (
@@ -500,14 +491,16 @@ dotpi_audio_device_init() (
500
491
 
501
492
  # clone once to be able to init offline
502
493
  if ! [[ -d "${usr_directory}" ]] ; then
503
- mkdir -p "${usr_directory}"
504
- git clone "https://github.com/${usr_repository}.git" "${usr_directory}" || {
494
+ sudo mkdir -p "${usr_directory}"
495
+ sudo git clone "https://github.com/${usr_repository}.git" "${usr_directory}" || {
505
496
  dotpi_echo_error "Unable to clone repository ${usr_repository}"
506
497
  return 1
507
498
  }
508
499
  fi
509
500
 
510
- alsactl restore -f "${usr_directory}/Codec_Zero_StereoMIC_record_and_HP_playback.state"
501
+ alsactl restore \
502
+ --file "${usr_directory}/Codec_Zero_StereoMIC_record_and_HP_playback.state" \
503
+ hw:0
511
504
  ;;
512
505
 
513
506
  'raspiaudio ultra')
@@ -517,27 +510,26 @@ dotpi_audio_device_init() (
517
510
 
518
511
  # clone once to be able to init offline
519
512
  if ! [[ -d "${usr_directory}" ]] ; then
520
- mkdir -p "${usr_directory}"
521
- git clone "https://github.com/${usr_repository}.git" "${usr_directory}" || {
513
+ sudo mkdir -p "${usr_directory}"
514
+ sudo git clone "https://github.com/${usr_repository}.git" "${usr_directory}" || {
522
515
  dotpi_echo_error "Unable to clone repository ${usr_repository}"
523
516
  return 1
524
517
  }
525
518
  fi
526
519
 
527
520
  # routes DAC to headphones and speakers, onboard mics to ADC
528
- alsactl restore -f "${usr_directory}/headphones.alsa"
521
+ alsactl restore \
522
+ --file "${usr_directory}/headphones.alsa" \
523
+ hw:0
529
524
  ;;
530
-
531
- esac
525
+ esac
532
526
 
533
527
  # alsa
534
528
  case "$model_normalised" in
535
529
 
536
530
  'headphones')
537
-
538
- amixer -D sysdefault sset -- 'PCM' 'on'
539
- amixer -D sysdefault sset -- 'PCM' '0dB'
540
- alsactl store
531
+ # 'PCM' control is aliased to default master
532
+ # no need for concurrent control
541
533
  ;;
542
534
 
543
535
  'raspberry pi dac pro'|'iqaudio dac pro' \
@@ -550,104 +542,88 @@ dotpi_audio_device_init() (
550
542
 
551
543
  amixer -D sysdefault sset -- 'Lineout' 'on'
552
544
  amixer -D sysdefault sset -- 'Lineout' '0dB'
553
-
554
- alsactl store
555
545
  ;;
556
546
 
557
- 'raspiaudio mic+ v1' | 'raspiaudio mic+ v2')
558
-
559
- # no controller for device, use default 'Master' control
560
- amixer sset -- 'Master' 'on'
561
- amixer sset -- 'Master' '80%'
562
-
563
- alsactl store
564
- ;;
565
-
566
- esac
567
-
568
- )
569
-
570
- # set and store volume for the current audio device
571
- dotpi_audio_device_volume_set() (
572
- volume="$1"
573
-
574
- model="$dotpi_audio_device"
575
- # lowercase everything
576
- model_normalised="$(dotpi_audio_device_model_normalise "$model")"
577
-
578
- case "$model_normalised" in
579
-
580
- ####### Generic devices
581
-
582
- 'headphones')
583
- control='PCM'
584
- _dotpi_audio_device_volume_set_alsa
585
- ;;
586
-
587
- 'bluetooth')
588
- dotpi_audio_bluetooth_destination_volume_set "$volume"
589
- ;;
590
-
591
-
592
- ####### Specific devices
593
-
594
- # HiFiBerry
595
- # Cf. https://www.hifiberry.com/docs/archive/mixer-controls-on-the-hifiberry-boards/
596
-
597
-
598
547
  'hifiberry dac+ dsp'|'hifiberry dac+ rtc'|'hifiberry dac+ standard'|'hifiberry amp2'|'hifiberry dac+ adc'|'hifiberry dac+ adc pro'|'hifiberry amp3')
599
548
  control='Digital'
600
- _dotpi_audio_device_volume_set_alsa
549
+ amixer -D sysdefault sset -- "$control" 'on'
550
+ amixer -D sysdefault sset -- "$control" '0dB'
601
551
  ;;
602
552
 
603
553
  'hifiberry dac2 hd')
604
554
  control='DAC'
605
- _dotpi_audio_device_volume_set_alsa
555
+ amixer -D sysdefault sset -- "$control" 'on'
556
+ amixer -D sysdefault sset -- "$control" '0dB'
606
557
  ;;
607
558
 
608
559
  'hifiberry amp+'|'hifiberry amp4'|'hifiberry amp4 pro')
609
560
  control='Master'
610
- _dotpi_audio_device_volume_set_alsa
561
+ amixer -D sysdefault sset -- "$control" 'on'
562
+ amixer -D sysdefault sset -- "$control" '0dB'
611
563
  ;;
612
564
 
613
- 'raspiaudio mic+ v1' | 'raspiaudio mic+ v2')
614
- control='Master'
615
- _dotpi_audio_device_volume_set_alsa
616
- ;;
565
+ esac
617
566
 
618
- 'raspiaudio ultra')
619
- # WM8960 DAC digital volume, acts on both headphones and speakers
620
- control='Playback'
621
- _dotpi_audio_device_volume_set_alsa
622
- ;;
623
567
 
568
+ dotpi_audio_device_volume_init
569
+ )
624
570
 
625
- ####### Ultimate Ears (UE)
571
+ # set and store volume for the current audio device
572
+ dotpi_audio_device_volume_set() (
626
573
 
627
- 'ue boom 2'|'ue boom 3'|'ue megaboom 2'|'ue megaboom 3')
628
- dotpi_audio_bluetooth_destination_volume_set "$volume"
629
- ;;
574
+ # Master volume is handled by pipewire, and pipewire requires a regular user session.
575
+ if [[ "$USER" == "root" ]]; then
576
+ # drop sudo privileges
577
+ dotpi_regular_user_run dotpi audio_device_volume_set "$@"
578
+ return $?
579
+ fi
630
580
 
631
- ########### Unknown device
581
+ volume="$1"
632
582
 
633
- *) # other
634
- dotpi_echo_error "Unable to set volume for unknown audio device model: ${model}"
635
- return 1
636
- ;;
583
+ if [[ -z "$volume" ]] ; then
584
+ dotpi_echo_error "Missing volume argument"
585
+ return 1
586
+ fi
587
+
588
+ if [[ ! "$volume" =~ %$ ]] ; then
589
+ dotpi_echo_error "Volume argument must be a percentage (e.g. '40%')"
590
+ return 1
591
+ fi
637
592
 
593
+ amixer -D default sset -- Master "$volume" || {
594
+ error_code=$?
595
+ dotpi_echo_error "Unable to set volume to ${volume}"
596
+ return "$error_code"
597
+ }
638
598
 
639
- esac
599
+ if [[ "$volume" == "$dotpi_audio_volume" ]] ; then
600
+ # no change to write
601
+ return 0
602
+ fi
603
+
604
+ # comment setting in project
605
+ sudo dotpi configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
606
+ --key dotpi_audio_volume
607
+
608
+ # escape double-quote for now, to quote when writing later
609
+ model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
610
+
611
+ # write changed setting in instance
612
+ sudo dotpi configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
613
+ --key dotpi_audio_volume \
614
+ --value "$volume"
640
615
  )
641
616
 
642
617
  # restore volume for the current audio device
643
618
  dotpi_audio_device_volume_init() (
644
- if [[ -z "$dotpi_audio_volume" ]] ; then
619
+ volume="$dotpi_audio_volume"
620
+
621
+ if [[ -z "$volume" ]] ; then
645
622
  dotpi_echo_warning "dotpi_audio_volume not set, keeping default volume"
646
623
  return 0
647
624
  fi
648
625
 
649
- destination_volume="$dotpi_audio_volume"
650
- dotpi_audio_device_volume_set "$destination_volume"
626
+ dotpi_audio_device_volume_set "$volume"
651
627
  )
652
628
 
653
629
 
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+
3
+ dotpi_bluetooth_enable() {
4
+
5
+ if [[ "$USER" != "root" ]]; then
6
+ dotpi echo_error "This command must be run as root"
7
+ return 1
8
+ fi
9
+
10
+ dotpi_echo_info "Enabling Bluetooth"
11
+
12
+ bluetoothctl power off
13
+ rfkill unblock bluetooth
14
+ systemctl restart bluetooth
15
+ bluetoothctl power on
16
+ }
@@ -1,6 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  dotpi_regular_user_get_id() (
4
+ # 1000 is the default user id for the first user on a Raspberry Pi OS system
4
5
  regular_user_id="${SUDO_UID:-1000}"
5
6
  if (( regular_user_id == 0 )) ; then
6
7
  regular_user_id=1000
@@ -26,3 +27,14 @@ dotpi_regular_user_get_home() (
26
27
  regular_user_home="$(getent passwd "$regular_user_id" | cut -d: -f6)"
27
28
  echo "$regular_user_home"
28
29
  )
30
+
31
+ dotpi_regular_user_run() (
32
+ if [[ "$USER" == "root" ]]; then
33
+ regular_user="$(dotpi_regular_user_get_name)"
34
+ # no sudo as user is root
35
+ # prefer systemd-run as it returns the exit code (unlike machinectl shell)
36
+ systemd-run --quiet --pipe --wait --collect --machine="${regular_user}@" --user -- /bin/bash -c '"$@"' - "$@"
37
+ else
38
+ "$@"
39
+ fi
40
+ )
@@ -9,6 +9,7 @@ if [[ "$USER" == "root" ]]; then
9
9
  user="${FIRSTUSER:-pi}"
10
10
  fi
11
11
  sudo -u "${user}" "$0" "$@"
12
+ exit $?
12
13
  fi
13
14
 
14
15
  local_file="$(dotpi readlink_follow "$0")"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotpi/tools",
3
- "version": "2.13.1",
3
+ "version": "2.14.1",
4
4
  "description": "Set of scripts for managing dotpi fleets of Raspberry Pi",
5
5
  "author": "Jean-Philippe Lambert",
6
6
  "contributors": [
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "lerna": "^10.1.1"
48
48
  },
49
- "gitHead": "7d677ea072c34e982e7f48e03aca59253c2a21ff"
49
+ "gitHead": "7374ff0ba8b0ce855149e149031a2439ee692f10"
50
50
  }
@@ -98,8 +98,12 @@ export async function configureProject(data, mocks = null) {
98
98
  const answers = await prompts([
99
99
  {
100
100
  type: 'select',
101
- name: 'soundCard',
102
- message: 'Choose your soundcard:',
101
+ name: 'audioDevice',
102
+ message: `Choose your audio device.
103
+ > Select 'default' to keep all the default devices (eg. headphones, HDMI).
104
+ > Select 'none' to keep only automatically configured devices (e.g. USB, raspiaudio mic+ v3).
105
+ > Select a specific device to keep only this one, and to configure it.
106
+ `,
103
107
  choices: readBashArray('dotpi_audio_device_supported').map(s => ({ title: s, value: s })),
104
108
  },
105
109
  {
@@ -11,8 +11,9 @@ 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}
14
+ # band: "a" for 5Ghz only, "bg" for 2.4GHz only
15
+ # omit parameter to keep default automatic selection
16
+ ${d.wifiBand !== 'automatic' ? band=d.wifiBand : ''}
16
17
 
17
18
  [wifi-security]
18
19
  key-mgmt=wpa-psk
@@ -6,8 +6,8 @@ dotpi_tools_version='${d.version}'
6
6
  # Project name
7
7
  dotpi_project_name='${d.projectName}'
8
8
 
9
- # Define soundcard
10
- dotpi_audio_device='${d.soundCard}'
9
+ # Define audio device
10
+ dotpi_audio_device='${d.audioDevice}'
11
11
 
12
12
  # Node.js version
13
13
  dotpi_node_version='${d.nodeVersion}'