@dotpi/tools 1.3.3 → 1.4.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.
Files changed (130) hide show
  1. package/.editorbackup/NOTES.md~ +974 -0
  2. package/.editorbackup/PIPEWIRE.md~ +42 -0
  3. package/.editorbackup/README.md~ +335 -0
  4. package/BACKUP-SANDO.command +61 -0
  5. package/BACKUP-SISIDO.command +61 -0
  6. package/PIPEWIRE.md +280 -0
  7. package/dotpi_root/bin/.editorbackup/dotpi_firstrun.bash~ +149 -0
  8. package/dotpi_root/bin/.editorbackup/dotpi_firstrun~ +177 -0
  9. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card.bash~ +425 -0
  10. package/dotpi_root/bin/.editorbackup/dotpi_prepare_sd_card~ +620 -0
  11. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system.bash~ +82 -0
  12. package/dotpi_root/bin/.editorbackup/dotpi_prepare_system~ +100 -0
  13. package/dotpi_root/bin/.editorbackup/dotpi~ +61 -0
  14. package/dotpi_root/bin/.editorbackup/prepare_sd_card.bash~ +252 -0
  15. package/dotpi_root/bin/dotpi_prepare_system +5 -0
  16. package/dotpi_root/etc/.editorbackup/dotpi_environment_default.bash~ +49 -0
  17. package/dotpi_root/etc/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  18. package/dotpi_root/etc/.editorbackup/dotpi_environment_project.bash~ +33 -0
  19. package/dotpi_root/etc/.editorbackup/dotpi_tarignore~ +4 -0
  20. package/dotpi_root/share/.editorbackup/coucou~ +1 -0
  21. package/dotpi_root/share/.editorbackup/dotpi_environment.bash~ +9 -0
  22. package/dotpi_root/share/.editorbackup/dotpi_functions.bash~ +11 -0
  23. package/dotpi_root/share/.editorbackup/dotpi_functions_configuration.bash~ +420 -0
  24. package/dotpi_root/share/.editorbackup/dotpi_functions_connection.bash~ +358 -0
  25. package/dotpi_root/share/.editorbackup/dotpi_init.bash~ +18 -0
  26. package/dotpi_root/share/dotpi_audio_alsa/dotpi_audio_alsa.service +15 -0
  27. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth.service~ +24 -0
  28. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_command~ +80 -0
  29. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_start_command~ +26 -0
  30. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_audio_bluetooth_stop_command~ +30 -0
  31. package/dotpi_root/share/dotpi_audio_bluetooth/.editorbackup/dotpi_bluetooth_audio.service~ +21 -0
  32. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_bluetooth.bash~ +256 -0
  33. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_audio_device.bash~ +287 -0
  34. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_bluetooth_audio.bash~ +7 -0
  35. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_configuration.bash~ +428 -0
  36. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_connection.bash~ +194 -0
  37. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_daemon.bash~ +26 -0
  38. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcard.bash~ +287 -0
  39. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_soundcards.bash~ +12 -0
  40. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_system.bash~ +158 -0
  41. package/dotpi_root/share/dotpi_functions/.editorbackup/dotpi_functions_utils.bash~ +152 -0
  42. package/dotpi_root/share/dotpi_init.bash +3 -0
  43. package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +85 -0
  44. package/dotpi_root/share/dotpi_pipewire/dotpi_install +24 -0
  45. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire.service +22 -0
  46. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire_command +29 -0
  47. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_bluetooth.bash~ +20 -0
  48. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_command~ +17 -0
  49. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_headphones.bash~ +20 -0
  50. package/dotpi_root/share/jackd/.editorbackup/dotpi_jackd_hifiberry.bash~ +16 -0
  51. package/dotpi_root/share/jackd/.editorbackup/jackd.conf~ +5 -0
  52. package/dotpi_root/share/jackd/.editorbackup/jackd.service~ +15 -0
  53. package/dotpi_root/share/jackd/.editorbackup/jackd_headphones.conf~ +5 -0
  54. package/dotpi_root/share/jackd/dotpi_jack_simple_client.service +23 -0
  55. package/dotpi_root/share/wireplumber/.editorbackup/8zzz-dotpi-wireplumber-config.lua~ +1 -0
  56. package/package.json +1 -1
  57. package/projects/asterismes.tgz +0 -0
  58. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_001.bash~ +4 -0
  59. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_instance_002.bash~ +3 -0
  60. package/projects/example-bluetooth/configuration/.editorbackup/dotpi_project.bash~ +46 -0
  61. package/projects/example-bluetooth/configuration/dotpi_instance_001.bash +3 -0
  62. package/projects/example-bluetooth/configuration/dotpi_instance_002.bash +3 -0
  63. package/projects/example-bluetooth/configuration/dotpi_project.bash +48 -0
  64. package/projects/example-development/configuration/.editorbackup/dotpi_project.bash~ +59 -0
  65. package/projects/example-development/configuration/dotpi_instance_114.bash +4 -0
  66. package/projects/example-headphones/configuration/.editorbackup/dotpi_project.bash~ +18 -0
  67. package/projects/example-hifiberry/configuration/.editorbackup/dotpi_instance_012.bash~ +4 -0
  68. package/projects/example-hifiberry/configuration/.editorbackup/dotpi_project.bash~ +18 -0
  69. package/projects/example-network/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  70. package/projects/old/bad/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  71. package/projects/old/bad/.editorbackup/dotpi_environment_project.bash~ +26 -0
  72. package/projects/old/bad/.editorbackup/dotpi_project.bash~ +33 -0
  73. package/projects/old/bad/.editorbackup/dotpi_tmp.bash~ +3 -0
  74. package/projects/old/bad/.editorbackup/wpa_supplicant.conf~ +37 -0
  75. package/projects/old/bad/dotpi_project.bash +20 -0
  76. package/projects/old/bluetooth/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  77. package/projects/old/bluetooth/.editorbackup/dotpi_environment_project.bash~ +26 -0
  78. package/projects/old/bluetooth/.editorbackup/dotpi_project.bash~ +21 -0
  79. package/projects/old/bluetooth/.editorbackup/dotpi_tmp.bash~ +3 -0
  80. package/projects/old/bluetooth/.editorbackup/wpa_supplicant.conf~ +37 -0
  81. package/projects/old/bluetooth/dotpi_project.bash +29 -0
  82. package/projects/old/dev.bak/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  83. package/projects/old/dev.bak/.editorbackup/dotpi_environment_project.bash~ +33 -0
  84. package/projects/old/dev.bak/.editorbackup/wpa_supplicant.conf~ +37 -0
  85. package/projects/old/dev.bak/dotpi_environment_instance.bash +1 -0
  86. package/projects/old/dev.bak/dotpi_environment_project.bash +46 -0
  87. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI-A114.nmconnection~ +24 -0
  88. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/DOTPI.nmconnection~ +24 -0
  89. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +24 -0
  90. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/onze.nmconnection~ +22 -0
  91. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/.editorbackup/welcome.nmconnection~ +23 -0
  92. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI-A114.nmconnection +23 -0
  93. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/DOTPI.nmconnection +23 -0
  94. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/Livebox-97C6_wifi_invite.nmconnection +24 -0
  95. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/onze.nmconnection +24 -0
  96. package/projects/old/dev.bak/file-system/etc/NetworkManager/system-connections/welcome.nmconnection +23 -0
  97. package/projects/old/dev.bak/network/.editorbackup/DOTPI-A114.nmconnection~ +24 -0
  98. package/projects/old/dev.bak/network/.editorbackup/DOTPI.nmconnection~ +24 -0
  99. package/projects/old/dev.bak/network/.editorbackup/Livebox-97C6_wifi_invite.nmconnection~ +24 -0
  100. package/projects/old/dev.bak/network/.editorbackup/onze.nmconnection~ +22 -0
  101. package/projects/old/dev.bak/network/.editorbackup/welcome.nmconnection~ +23 -0
  102. package/projects/old/dev.bak/network/AccueilCie.nmconnection +24 -0
  103. package/projects/old/dev.bak/network/DOTPI-A114.nmconnection +23 -0
  104. package/projects/old/dev.bak/network/DOTPI.nmconnection +23 -0
  105. package/projects/old/dev.bak/network/Livebox-97C6_wifi_invite.nmconnection +25 -0
  106. package/projects/old/dev.bak/network/onze.nmconnection +24 -0
  107. package/projects/old/dev.bak/network/welcome.nmconnection +23 -0
  108. package/projects/old/dev.bak/network/wifi-access-point.nmconnection +23 -0
  109. package/projects/old/dev.bak/network/wifi-internet.nmconnection +24 -0
  110. package/projects/old/dev.bak/network/wifi-ircam-public.nmconnection +24 -0
  111. package/projects/old/dev.bak/network/wifi-local.nmconnection +22 -0
  112. package/projects/old/dev.bak/network/wifi-welcome.nmconnection +24 -0
  113. package/projects/old/dev.bak/wpa_supplicant.conf +43 -0
  114. package/projects/old/dev.zip +0 -0
  115. package/projects/old/example/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  116. package/projects/old/example/.editorbackup/dotpi_environment_project.bash~ +26 -0
  117. package/projects/old/example/.editorbackup/dotpi_project.bash~ +21 -0
  118. package/projects/old/example/.editorbackup/dotpi_tmp.bash~ +3 -0
  119. package/projects/old/example/.editorbackup/wpa_supplicant.conf~ +37 -0
  120. package/projects/old/example/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  121. package/projects/old/example/configuration/dotpi_project.bash +21 -0
  122. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  123. package/projects/old/example-complete.bak/.editorbackup/dotpi_environment_project.bash~ +26 -0
  124. package/projects/old/example-complete.bak/.editorbackup/dotpi_project.bash~ +21 -0
  125. package/projects/old/example-complete.bak/.editorbackup/dotpi_tmp.bash~ +3 -0
  126. package/projects/old/example-complete.bak/.editorbackup/wpa_supplicant.conf~ +37 -0
  127. package/projects/old/example-complete.bak/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  128. package/projects/old/example-complete.bak/configuration/dotpi_project.bash +21 -0
  129. package/projects/old/example-complete.bak/configuration/jackd/.editorbackup/dotpi_jackd.bash~ +14 -0
  130. package/projects/old/example-complete.bak/configuration/jackd/dotpi_jackd.bash +14 -0
@@ -0,0 +1,287 @@
1
+ #!/bin/bash
2
+
3
+ _dotpi_soundcard_get_options() {
4
+
5
+ _echo_empty_option_error() {
6
+ dotpi_echo_error "$1 requires a non-empty option argument."
7
+ }
8
+
9
+ # From http://mywiki.wooledge.org/BashFAQ/035
10
+
11
+ while true ; do
12
+ case $1 in
13
+
14
+ -h|-\?|--help)
15
+ _dotpi_usage # Display a usage synopsis.
16
+ return 0
17
+ ;;
18
+
19
+ -m|--model) # Takes an option argument; ensure it has been specified.
20
+ if [ -z "$2" ] ; then
21
+ _dotpi_usage
22
+ _echo_empty_option_error "$1"
23
+ return 1
24
+ else
25
+ model="$2"
26
+ shift
27
+ fi
28
+ ;;
29
+
30
+ -c|--config) # Takes an option argument; ensure it has been specified.
31
+ if [ -z "$2" ] ; then
32
+ _dotpi_usage
33
+ _echo_empty_option_error "$1"
34
+ return 1
35
+ else
36
+ config_file="$2"
37
+ shift
38
+ fi
39
+ ;;
40
+
41
+ --) # End of all options.
42
+ shift
43
+ break
44
+ ;;
45
+
46
+ -?*) # Unknown
47
+ _dotpi_usage
48
+ dotpi_echo_error "Unknown option: $1"
49
+ return 1
50
+ ;;
51
+
52
+ *) # Default case: No more options, so break out of the loop.
53
+ break
54
+
55
+ esac
56
+
57
+ shift
58
+ done
59
+
60
+ }
61
+
62
+ dotpi_soundcard_model_normalise() {
63
+ echo "$1" | tr '[:upper:]' '[:lower:]'
64
+ }
65
+
66
+ dotpi_soundcard_select() (
67
+ # sub-shell to keep everything local (functions and variables)
68
+
69
+ _dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
70
+ _dotpi_usage() {
71
+ echo "Usage: ${_dotpi_command} --model <model> --config <config_file_path>"
72
+ }
73
+
74
+ # Initialize all the option variables.
75
+ # This ensures we are not contaminated by variables from the environment.
76
+ model=
77
+ config_file=
78
+
79
+ if ! _dotpi_soundcard_get_options "${@}" ; then
80
+ return $?
81
+ fi
82
+
83
+ if [ -z "$model" ] ; then
84
+ _dotpi_usage
85
+ dotpi_echo_error "missing model option"
86
+ return 1
87
+ fi
88
+
89
+ if [ -z "$config_file" ] ; then
90
+ config_path="$(dotpi_system_get_bootfs_path)"
91
+ if [ -z "$config_path" ] ; then
92
+ dotpi_echo_error "Unable to get default system path for config file"
93
+ _dotpi_usage
94
+ return 1
95
+ fi
96
+ config_filename='config.txt'
97
+ config_file="${config_path}/${config_filename}"
98
+ dotpi_echo_warning "Using default config file ${config_file}"
99
+ fi
100
+
101
+
102
+ if ! [ -w "$config_file" ] ; then
103
+ dotpi_echo_error "Unable to access config file ${config_file} for writing"
104
+ return 1
105
+ fi
106
+
107
+ # lowercase everything
108
+ model_normalised="$(dotpi_soundcard_model_normalise "$model")"
109
+
110
+ case "$model_normalised" in
111
+
112
+ # HiFiBerry
113
+ # Cf. https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/
114
+
115
+ 'hifiberry dac for raspberry pi 1'|'hifiberry dac+ light'|'hifiberry dac zero'|'hifiberry miniamp'|'hifiberry beocreate'|'hifiberry dac+ dsp'|'hifiberry dac+ rtc')
116
+ dtoverlay=hifiberry-dac
117
+ _dotpi_soundcard_select_hifiberry
118
+ ;;
119
+
120
+ 'hifiberry dac+ standard'|'hifiberry pro'|'hifiberry amp2')
121
+ dtoverlay=hifiberry-dacplus
122
+ _dotpi_soundcard_select_hifiberry
123
+ ;;
124
+
125
+ 'hifiberry dac2 hd')
126
+ dtoverlay=hifiberry-dacplushd
127
+ _dotpi_soundcard_select_hifiberry
128
+ ;;
129
+
130
+ 'hifiberry dac+ adc')
131
+ dtoverlay=hifiberry-dacplusadc
132
+ _dotpi_soundcard_select_hifiberry
133
+ ;;
134
+
135
+ 'hifiberry dac+ adc pro')
136
+ dtoverlay=hifiberry-dacplusadcpro
137
+ _dotpi_soundcard_select_hifiberry
138
+ ;;
139
+
140
+ 'hifiberry digi+')
141
+ dtoverlay=hifiberry-digi
142
+ _dotpi_soundcard_select_hifiberry
143
+ ;;
144
+
145
+ 'hifiberry digi+ pro')
146
+ dtoverlay=hifiberry-digi-pro
147
+ _dotpi_soundcard_select_hifiberry
148
+ ;;
149
+
150
+ 'hifiberry amp+')
151
+ dtoverlay=hifiberry-amp
152
+ _dotpi_soundcard_select_hifiberry
153
+ ;;
154
+
155
+ 'hifiberry amp3')
156
+ dtoverlay=hifiberry-amp3
157
+ _dotpi_soundcard_select_hifiberry
158
+ ;;
159
+
160
+ headphones)
161
+ _dotpi_soundcard_select_headphones
162
+ ;;
163
+
164
+ default)
165
+ dotpi_echo_warning "Not installing a specific soundcard, keeping defaults"
166
+ ;;
167
+
168
+ none)
169
+ _dotpi_soundcard_disable_all
170
+ ;;
171
+
172
+ -?*) # Unknown
173
+ _dotpi_usage
174
+ dotpi_echo_error "Unknown soundcard model: ${model}"
175
+ return 1
176
+ ;;
177
+
178
+ esac
179
+
180
+ # use xargs to unquote value
181
+ model_project="$(dotpi_configuration_read \
182
+ --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
183
+ --key dotpi_soundcard \
184
+ | xargs)"
185
+
186
+
187
+ if [[ "$model_normalised" == "$(dotpi_soundcard_model_normalise "$model_project")" ]] ; then
188
+ # no need to update environment
189
+ return 0;
190
+ fi
191
+
192
+ dotpi_echo_warning 'Sound-card model is specific to this instance'
193
+
194
+ # comment setting in project
195
+ dotpi_configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
196
+ --key dotpi_soundcard
197
+
198
+ # escape double-quote for now, to quote when writing later
199
+ model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
200
+
201
+ # write changed setting in instance
202
+ # be sure to quote value
203
+ dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
204
+ --key dotpi_soundcard \
205
+ --value \""${model_value}"\"
206
+ )
207
+
208
+ _dotpi_soundcard_jackd_set_configuration() (
209
+ model="$1"
210
+ (cd "${DOTPI_ROOT}/share/jackd" && ln -s -f "dotpi_jackd_${model}.bash" 'dotpi_jackd.bash') || {
211
+ dotpi_echo_error "Unable to change jackd configuration to ${model}"
212
+ return 1
213
+ }
214
+
215
+ # we can change soundcard in a temporary file-system, too
216
+ if dotpi_system_is_raspberry_pi ; then
217
+ dotpi_echo_warning "Restart jackd service"
218
+ service='jackd'
219
+ systemctl is-active "$service" > /dev/null 2>&1 \
220
+ && systemctl restart "$service" || {
221
+ dotpi_echo_warning "systemctl unable to restart service ${service}"
222
+ }
223
+ fi
224
+ )
225
+
226
+ _dotpi_soundcard_disable_all() (
227
+ dotpi_echo_info "Disabling all sound-cards"
228
+
229
+ _dotpi_soundcard_disable_headphones
230
+ _dotpi_soundcard_disable_hdmi
231
+ _dotpi_soundcard_disable_hifiberry
232
+ )
233
+
234
+ _dotpi_soundcard_select_headphones() (
235
+ dotpi_echo_info "Installing Headphones (default) sound-card"
236
+
237
+ _dotpi_soundcard_disable_hdmi
238
+ _dotpi_soundcard_disable_hifiberry
239
+
240
+ # un-comment dtparam=audio as it must be set first
241
+ # (setting at the end the the file fails)
242
+ pattern="$(dotpi_configuration_get_pattern --prefix "# dtparam=audio")"
243
+ perl -pe "s/${pattern}/"'dtparam=audio=on/' -i "$config_file"
244
+
245
+ _dotpi_soundcard_jackd_set_configuration "headphones"
246
+ )
247
+
248
+ _dotpi_soundcard_select_hifiberry() (
249
+ dotpi_echo_info "Configuring HiFiBerry sound-card '${model}'"
250
+
251
+ _dotpi_soundcard_disable_headphones
252
+ _dotpi_soundcard_disable_hdmi
253
+ _dotpi_soundcard_disable_hifiberry
254
+
255
+ mkdir -p "$(dirname -- "$config_file")"
256
+ cat >> "$config_file" << EOF
257
+
258
+ # dotpi: overlay for soundcard '${model}'
259
+ dtoverlay=${dtoverlay}
260
+
261
+ EOF
262
+
263
+ _dotpi_soundcard_jackd_set_configuration "hifiberry"
264
+ )
265
+
266
+ _dotpi_soundcard_disable_headphones() (
267
+ # disable internal soundcard
268
+ dotpi_configuration_comment --file "$config_file" --key 'dtparam=audio'
269
+ )
270
+
271
+ _dotpi_soundcard_disable_hdmi() (
272
+ # disable HDMI audio
273
+
274
+ # new systems
275
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=vc4-kms-v3d")"
276
+ perl -pe "s/${pattern}/"'${1}${2},noaudio/' -i "$config_file"
277
+
278
+ # old systems
279
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=vc4-fkms-v3d")"
280
+ perl -pe "s/${pattern}/"'${1}${2},audio=off/' -i "$config_file"
281
+ )
282
+
283
+ _dotpi_soundcard_disable_hifiberry() (
284
+ # disable hifiberry
285
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=hifiberry-")"
286
+ perl -pe "s/${pattern}/"'${1}# ${2}${3}/' -i "$config_file"
287
+ )
@@ -0,0 +1,12 @@
1
+ dotpi_soundcard_select() {
2
+ local soundcard="$1"
3
+ local config_file="$2"
4
+
5
+
6
+ sub
7
+ }
8
+
9
+ sub() {
10
+ echo soundcard="$1"
11
+ echo config_file="$2"
12
+ }
@@ -0,0 +1,158 @@
1
+ #!/bin/bash
2
+
3
+ dotpi_system_is_raspberry_pi() (
4
+ model='other'
5
+
6
+ if [ -r /proc/device-tree/model ] ; then
7
+ model="$( (set -o pipefail ; \
8
+ cat /proc/device-tree/model \
9
+ | perl -ne '
10
+ if ( m/raspberry/i ) {
11
+ print "raspberry\n"
12
+ } else {
13
+ print "other\n"
14
+ }
15
+ ' ) || echo 'other')"
16
+
17
+ fi
18
+
19
+ if [[ "$model" == "raspberry" ]] ; then
20
+ return 0
21
+ else
22
+ return 1
23
+ fi
24
+ )
25
+
26
+ dotpi_system_get_bootfs_path() (
27
+ # since Raspberry Pi OS Bookworm
28
+ local_path='/boot/firmware'
29
+
30
+ if ! [ -d "$local_path" ] ; then
31
+ # for Raspberry Pi OS Bullseye
32
+ local_path='/boot'
33
+
34
+ if ! [ -d "$local_path" ] ; then
35
+ dotpi_echo_error "Boot file-system not found"
36
+ echo ""
37
+ return 1
38
+ fi
39
+
40
+ fi
41
+
42
+ echo "$local_path"
43
+ )
44
+
45
+ dotpi_system_set_hostname() (
46
+ if [ -z "$DOTPI_ROOT" ] ; then
47
+ echo "DOTPI_ROOT undefined" >&2
48
+ return 1
49
+ fi
50
+
51
+ if ! dotpi_system_is_raspberry_pi ; then
52
+ dotpi_echo_error "System is not a Raspberry Pi. Not changing hostname"
53
+ return 1
54
+ fi
55
+
56
+ if [ -z "$1" ] ; then
57
+ dotpi_echo_error "New hostname argument is required"
58
+ return 1
59
+ fi
60
+ dotpi_instance_hostname="$1"
61
+
62
+ destination_file="${DOTPI_ROOT}/etc/dotpi_environment_instance.bash"
63
+ dotpi_configuration_write --file "$destination_file" --key 'dotpi_instance_hostname' --value "$dotpi_instance_hostname"
64
+
65
+ hostname_current="$(cat /etc/hostname | tr -d " \t\n\r")"
66
+ if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
67
+ /usr/lib/raspberrypi-sys-mods/imager_custom set_hostname "${dotpi_instance_hostname}"
68
+ else
69
+ echo "${dotpi_instance_hostname}" >/etc/hostname
70
+ sed -i "s/127.0.1.1.*${hostname_current}/127.0.1.1\t${dotpi_instance_hostname}/g" /etc/hosts
71
+ fi
72
+
73
+ # explicitly update hostnamectl for immediate effect
74
+ hostnamectl hostname "$dotpi_instance_hostname" || {
75
+ dotpi_echo_warning "hostnamectl unable to change hostname to ${dotpi_instance_hostname}"
76
+ }
77
+
78
+ # update services to use the new hostname
79
+ services=(
80
+ 'NetworkManager'
81
+ 'avahi-daemon.service' # Bonjour / zeroconf / mDNS
82
+ )
83
+ for service in "${services[@]}" ; do
84
+ # restart service only if active (avoid early start on first boot)
85
+ systemctl is-active "$service" > /dev/null 2>&1 \
86
+ && systemctl restart "$service" || {
87
+ dotpi_echo_warning "systemctl unable to restart service ${service}"
88
+ }
89
+ done
90
+
91
+ )
92
+
93
+ dotpi_system_execute_on_reboot() (
94
+ _dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
95
+ _dotpi_usage() {
96
+ echo "Usage: ${_dotpi_command} <user> <executable>"
97
+ }
98
+
99
+ user="$1"
100
+ if [[ -z "$user" ]] ; then
101
+ dotpi_echo_error "Missing user argument."
102
+ _dotpi_usage
103
+ exit 1
104
+ fi
105
+
106
+ executable="$2"
107
+ if [[ -z "$executable" ]] ; then
108
+ dotpi_echo_error "Missing executable argument."
109
+ _dotpi_usage
110
+ exit 1
111
+ fi
112
+
113
+ if ! [[ -d /etc/cron.d ]] ; then
114
+ dotpi_echo_error "System without cron.d support."
115
+ dotpi_echo_error "$1 will NOT execute on next boot."
116
+ return 1
117
+ fi
118
+
119
+ executable_name="$(basename "$executable")"
120
+ executable_file="$(dotpi_readlink_follow "$executable")"
121
+
122
+ date_string="$(date '+%Y%m%d_%H%M%S')"
123
+
124
+ # Cf. https://manpages.debian.org/bookworm/cron/cron.8.en.html
125
+
126
+ # As described above, the files under these directories have to pass some
127
+ # sanity checks including the following: be executable, be owned by root, not
128
+ # be writable by group or other and, if symlinks, point to files owned by
129
+ # root. Additionally, the file names must conform to the filename requirements
130
+ # of run-parts: they must be entirely made up of letters, digits and can only
131
+ # contain the special signs underscores ('_') and hyphens ('-'). Any file that
132
+ # does not conform to these requirements will not be executed by
133
+ # run-parts. For example, any file containing dots will be ignored. This is
134
+ # done to prevent cron from running any of the files that are left by the
135
+ # Debian package management system when handling files in /etc/cron.d/ as
136
+ # configuration files (i.e. files ending in .dpkg-dist, .dpkg-orig, .dpkg-old,
137
+ # and .dpkg-new).
138
+
139
+ cron_file="/etc/cron.d/zzz_dotpi_${date_string}_$(echo -n "${executable_name}" \
140
+ | dotpi_sed 's/[^a-zA-Z0-9_-]/_/g')"
141
+
142
+ log_path="${DOTPI_ROOT}/var/log"
143
+ mkdir -p "$log_path"
144
+
145
+ log_name="${executable_name}_${date_string}.log"
146
+ log_file="${log_path}/${log_name}"
147
+
148
+ cat >> "$cron_file" << EOF
149
+
150
+ SHELL=/bin/bash
151
+
152
+ @reboot ${user} "${executable_file}" 2>&1 | sudo dotpi log "$log_file"
153
+ @reboot root rm "$cron_file"
154
+
155
+ EOF
156
+
157
+
158
+ )
@@ -0,0 +1,152 @@
1
+ #!/bin/bash
2
+
3
+ dotpi_apt_get() {
4
+ # fully automated, with default choices (yes to any questions)
5
+ # DEBIAN_FRONTEND=noninteractive
6
+ # -y
7
+
8
+ # quiet output
9
+ # -q
10
+
11
+ # keep installation explicit, do not install recommended
12
+ # -no-install-recommends
13
+
14
+ # wait for other apt-get processes (first or daily updates)
15
+ # -1 is unlimited
16
+ # DPkg::Lock::Timeout=-1
17
+
18
+ # wait for distant resources (internet)
19
+ # -1 is unlimited
20
+ # Acquire::Retries=-1
21
+
22
+ DEBIAN_FRONTEND=noninteractive \
23
+ apt-get \
24
+ -y \
25
+ -q \
26
+ --no-install-recommends \
27
+ -o DPkg::Lock::Timeout=-1 \
28
+ -o Acquire::Retries=-1 \
29
+ "${@}"
30
+ }
31
+
32
+ dotpi_source_if_available() {
33
+ if [ -f "$1" ] && [ -r "$1" ] ; then
34
+ source "$1"
35
+ return 0
36
+ else
37
+ return 1
38
+ fi
39
+ }
40
+
41
+ # `readlink -f` is not available for MacOS
42
+ # https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
43
+ dotpi_readlink_follow() (
44
+ target_file="$1"
45
+
46
+ cd -- "$(dirname -- "$target_file")" || {
47
+ echo ''
48
+ return 1
49
+ }
50
+ target_file="$(basename -- "$target_file")"
51
+
52
+ # Iterate down a (possible) chain of symlinks
53
+ while [[ -L "$target_file" ]] ; do
54
+ target_file="$(readlink -- "$target_file")"
55
+ cd -- "$(dirname -- "$target_file")" || {
56
+ echo ''
57
+ return 1
58
+ }
59
+ target_file="$(basename -- "$target_file")"
60
+ done
61
+
62
+ # Compute the canonicalized name by finding the physical path
63
+ # for the directory we're in and appending the target file.
64
+ target_path="$(pwd -P)"
65
+ result="${target_path}/${target_file}"
66
+ echo "$result"
67
+ )
68
+
69
+ # Black 0;30 Dark Gray 1;30
70
+ # Red 0;31 Light Red 1;31
71
+ # Green 0;32 Light Green 1;32
72
+ # Brown/Orange 0;33 Yellow 1;33
73
+ # Blue 0;34 Light Blue 1;34
74
+ # Purple 0;35 Light Purple 1;35
75
+ # Cyan 0;36 Light Cyan 1;36
76
+ # Light Gray 0;37 White 1;37
77
+
78
+ dotpi_color_none='\e[0m'
79
+ dotpi_color_red='\e[0;31m'
80
+ dotpi_color_orange='\e[0;33m'
81
+ dotpi_color_green='\e[0;32m'
82
+
83
+ dotpi_echo_error() {
84
+ printf "${dotpi_color_red}ERROR: ${dotpi_color_none}${*}\n" >&2
85
+ }
86
+
87
+ dotpi_echo_warning() {
88
+ printf "${dotpi_color_orange}WARNING: ${dotpi_color_none}${*}\n" >&2
89
+ }
90
+
91
+ dotpi_echo_info() {
92
+ printf "${dotpi_color_green}INFO: ${dotpi_color_none}${*}\n" >&2
93
+ }
94
+
95
+ dotpi_colour_remove() {
96
+ dotpi_sed 's/\e\[[0-9;]*m(?:\e\[K)?//g'
97
+ }
98
+
99
+ dotpi_log() (
100
+ _dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
101
+ _dotpi_usage() {
102
+ echo "Usage: <command> 2>&1 | ${_dotpi_command} <log_file>" >&2
103
+ }
104
+
105
+ log_file="$1"
106
+ if [[ -z "$log_file" ]] ; then
107
+ dotpi_echo_error "missing output filename"
108
+ _dotpi_usage
109
+ return 1
110
+ fi
111
+
112
+ tee -i >(dotpi_colour_remove \
113
+ | dotpi_sed "s/^/$(date '+%Y-%m-%d %H:%M:%S') /" \
114
+ >> "$log_file")
115
+ )
116
+
117
+ dotpi_sed() {
118
+ # sed is not portable
119
+ perl -pe "$@"
120
+ return $?
121
+ }
122
+
123
+ # dotpi_uuidgen
124
+ if $( command -v uuidgen > /dev/null ) ; then
125
+ dotpi_uuidgen() {
126
+ uuidgen | tr '[:upper:]' '[:lower:]'
127
+ }
128
+ elif [ -r /proc/sys/kernel/random/uuid ] ; then
129
+ dotpi_uuidgen() {
130
+ cat /proc/sys/kernel/random/uuid
131
+ }
132
+ else
133
+ dotpi_uuidgen() {
134
+ printf '%08x-%04x-%04x-%012x\n' $(( (RANDOM << 16 + RANDOM) % 0xffffffff )) $(( RANDOM )) $(( RANDOM )) $(( ( (RANDOM << 16 + RANDOM) << 16) + RANDOM % 0xffffffffffff ))
135
+ }
136
+ fi
137
+
138
+ dotpi_file_word_size() {
139
+ if [[ $# != 1 ]] ; then
140
+ dotpi_echo_error 'First argument is file to read'
141
+ dotpi_echo_error "Usage: ${FUNCNAME[0]} <file_to_read>"
142
+ return 1
143
+ fi
144
+
145
+ echo "$(file "$1" | perl -pe 's/.*(32|64)-bit.*/$1/' )"
146
+ }
147
+
148
+ # requires ts form moretuils
149
+ dotpi_timestamp() {
150
+ # [now (time_from_start)]
151
+ ts -s '(%H:%M:%.S)]' | ts '[%Y-%m-%d %H:%M:%S'
152
+ }
@@ -13,6 +13,9 @@ _local_path="$(cd -- "$(dirname -- "${_local_file}")" && pwd)"
13
13
  DOTPI_ROOT="$(cd -- "${_local_path}/.." && pwd)"
14
14
  export DOTPI_ROOT
15
15
 
16
+ export PATH="${PATH}:${DOTPI_ROOT}/usr/bin"
17
+ export PATH="${PATH}:${DOTPI_ROOT}/bin"
18
+
16
19
  source "${DOTPI_ROOT}/share/dotpi_functions.bash"
17
20
 
18
21
  source "${DOTPI_ROOT}/share/dotpi_environment.bash"
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/node
2
+
3
+ // @TODO: use a proper pipewire lua script that automatically runs
4
+ // whenever the default audio output is restored
5
+
6
+ const util = require('node:util');
7
+ const exec = util.promisify(require('node:child_process').exec);
8
+
9
+ let pipewireData = null;
10
+ async function pipewireRelink() {
11
+
12
+ try {
13
+ const { stdout, stderr } = await exec('pw-dump');
14
+ // console.log('pw-dump stdout:', stdout);
15
+ if(stderr) {
16
+ console.warn('pw-dump stderr:', stderr);
17
+ }
18
+
19
+ pipewireData = JSON.parse(stdout);
20
+
21
+ } catch (error) {
22
+ console.error('Error with pw-dump:', error.message, error);
23
+ process.exit(1);
24
+ }
25
+ const playbackNodes = pipewireData.filter( (e) => {
26
+ return e.type === "PipeWire:Interface:Node"
27
+ && e.info
28
+ && e.info.props
29
+ && typeof e.info.props['client.id'] !== 'undefined'
30
+ && e.info.props['media.type'] === 'Audio'
31
+ });
32
+
33
+ if (playbackNodes.length === 0) {
34
+ console.warn('pipewireRelink: no playback node');
35
+ // no error
36
+ process.exit(0);
37
+ }
38
+
39
+ const outputNodes = pipewireData.filter( (e) => {
40
+ return e.type === "PipeWire:Interface:Node"
41
+ && e.info
42
+ // && e.info['max-input-ports'] > 1
43
+ && e.info.props
44
+ && e.info.props['media.class'] === 'Audio/Sink';
45
+ });
46
+
47
+ if (outputNodes.length === 0) {
48
+ console.warn('pipewireRelink: no output node');
49
+ // no error
50
+ process.exit(0);
51
+ }
52
+ else if (outputNodes.length > 1) {
53
+ console.warn('pipewireRelink: multiple output nodes');
54
+ }
55
+
56
+ for(let p = 0; p < playbackNodes.length; ++p) {
57
+ for(let o = 0; o < outputNodes.length; ++o) {
58
+ playbackIndex = playbackNodes[p].id;
59
+ outputIndex = outputNodes[o].id;
60
+ const commandString = `pw-link ${playbackIndex} ${outputIndex}`;
61
+ try {
62
+ // console.log(commandString);
63
+ const {stdout, stderr} = await exec(commandString);
64
+ // console.log('pw-link stdout:', stdout);
65
+ if(stderr) {
66
+ console.warn('pw-link stderr:', stderr);
67
+ }
68
+ } catch(error) {
69
+ // error when linking nodes instead of ports: ignore
70
+ // console.error( `Error with ${commandString}:`, error.message, error);
71
+ continue;
72
+ }
73
+ }
74
+ }
75
+
76
+ process.exit(0);
77
+
78
+ }
79
+
80
+ pipewireRelink();
81
+
82
+
83
+
84
+
85
+