@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,620 @@
1
+ #!/bin/bash
2
+
3
+ set +e
4
+
5
+ _dotpi_command="$(basename -- "$0")"
6
+
7
+ ####### Bootstrap
8
+
9
+ dotpi_echo_error() {
10
+ printf 'ERROR: %s\n' "$1" >&2
11
+ }
12
+
13
+ dotpi_echo_warning() {
14
+ printf 'WARNING: %s\n' "$1" >&2
15
+ }
16
+
17
+ ####### Command-line options
18
+
19
+ _dotpi_usage() {
20
+ echo "Usage: ${_dotpi_command} --project <project_path> [--instance-number <integer>] [--bootfs-drive-letter <letter>]"
21
+ }
22
+
23
+ _echo_empty_option_error() {
24
+ dotpi_echo_error "$1 requires a non-empty option argument."
25
+ }
26
+
27
+ while true ; do
28
+ case $1 in
29
+
30
+ -h|-\?|--help)
31
+ _dotpi_usage # Display a usage synopsis.
32
+ exit 0
33
+ ;;
34
+
35
+ -p|--project) # Takes an option argument; ensure it has been specified.
36
+ if [ -z "$2" ] ; then
37
+ _echo_empty_option_error "$1"
38
+ _dotpi_usage
39
+ exit 1
40
+ else
41
+ project="$2"
42
+ shift
43
+ fi
44
+ ;;
45
+
46
+ -i|--instance-number) # Takes an option argument; ensure it has been specified.
47
+ if [ -z "$2" ] ; then
48
+ _echo_empty_option_error "$1"
49
+ _dotpi_usage
50
+ exit 1
51
+ else
52
+ instance_number="$2"
53
+ shift
54
+ fi
55
+ ;;
56
+
57
+ -d|--bootfs-drive-letter) # Takes an option argument; ensure it has been specified.
58
+ if [ -z "$2" ] ; then
59
+ _echo_empty_option_error "$1"
60
+ _dotpi_usage
61
+ exit 1
62
+ else
63
+ <<<<<<< ours
64
+ <<<<<<< Updated upstream
65
+ =======
66
+ # convert to lowercase
67
+ >>>>>>> Stashed changes
68
+ =======
69
+ # convert to lowercase
70
+ >>>>>>> theirs
71
+ bootfs_drive_letter="$2"
72
+ shift
73
+ fi
74
+ ;;
75
+
76
+ --) # End of all options.
77
+ shift
78
+ break
79
+ ;;
80
+
81
+ -?*) # Unknown
82
+ dotpi_echo_error "Unknown option: $1"
83
+ _dotpi_usage
84
+ exit 1
85
+ ;;
86
+
87
+ *) # Default case: No more options, so break out of the loop.
88
+ break
89
+
90
+ esac
91
+
92
+ shift
93
+ done
94
+
95
+ if [ -z ${project+x} ] ; then
96
+ dotpi_echo_error "missing project option"
97
+ _dotpi_usage
98
+ exit 1
99
+ fi
100
+
101
+ project_path="$( (cd -- "$project" && pwd) 2> /dev/null || {
102
+ dotpi_echo_error "unable to access project ${project}"
103
+ } )"
104
+ if [ -z "$project_path" ] ; then
105
+ exit 1
106
+ fi
107
+
108
+ local_path="$( (cd -- "$(dirname -- "$0")" && pwd) 2> /dev/null || {
109
+ dotpi_echo_error "unable to access local path $(dirname -- "$0")"
110
+ } )"
111
+ if [ -z "$local_path" ] ; then
112
+ exit 1
113
+ fi
114
+
115
+ # script in "bin"
116
+ DOTPI_ROOT="${local_path}/.."
117
+
118
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
119
+
120
+ tmp_path="${project_path}/tmp"
121
+ mkdir -p -- "$tmp_path"
122
+
123
+ # self log
124
+ log_file="${tmp_path}/${_dotpi_command}_$(date +"%Y%m%d-%H%M%S").log"
125
+ dotpi_echo_info "Log file: ${log_file}"
126
+ exec &> >(dotpi_log "$log_file")
127
+
128
+ file_system_mirror="${tmp_path}/file-system"
129
+ rm -rf "$file_system_mirror"
130
+ mkdir -p -- "$file_system_mirror"
131
+
132
+ dotpi_echo_info "Filesystem mirror: ${file_system_mirror}"
133
+
134
+ tar_options=()
135
+ while read pattern ; do
136
+
137
+ # avoid empty pattern
138
+ if [ -z "$pattern" ] ; then
139
+ continue
140
+ fi
141
+
142
+ tar_options+=( '--exclude' "${pattern}" )
143
+ done < "${DOTPI_ROOT}/etc/dotpi_tarignore"
144
+
145
+ # regular files only
146
+ if [[ "$(uname)" == "Darwin" ]] ; then
147
+ tar_options+=( '--no-mac-metadata' )
148
+ fi
149
+ tar_options+=( '--no-xattrs' )
150
+
151
+ #### copy defaults from dotpi_root
152
+
153
+ source_path="$DOTPI_ROOT"
154
+ destination_path="${file_system_mirror}/opt/dotpi"
155
+ mkdir -p -- "$destination_path"
156
+ (set -o pipefail ; \
157
+ cd -- "$source_path" && tar c "${tar_options[@]}" '.' \
158
+ | tar x -C "$destination_path") || {
159
+ dotpi_echo_error "Error while copying defaults from ${source_path} to ${destination_path}"
160
+ exit 1
161
+ }
162
+
163
+ #### copy project configuration
164
+
165
+ source_path="$project_path"
166
+ destination_path="${file_system_mirror}/opt/dotpi/etc"
167
+ mkdir -p -- "$destination_path"
168
+ source_file_path="${source_path}/dotpi_project.bash"
169
+ destination_file_path="${destination_path}/dotpi_environment_project.bash"
170
+ if [ -r "$source_file_path" ] ; then
171
+ cp -- "$source_file_path" "$destination_file_path"
172
+ fi
173
+
174
+ #### select instance
175
+
176
+ # keep reference of file to increment at the end
177
+ environment_tmp_file="${tmp_path}/dotpi_tmp.bash"
178
+ dotpi_source_if_available "$environment_tmp_file"
179
+
180
+ if [ -n "$instance_number" ] ; then
181
+ # from command-line
182
+ dotpi_instance_number="$instance_number"
183
+ else
184
+ # from environment_tmp
185
+ if [ -z "$dotpi_instance_number" ] ; then
186
+ dotpi_instance_number=1
187
+ fi
188
+
189
+ echo ''
190
+ echo '##########################################################'
191
+ echo ''
192
+ echo " Please type instance number, or type enter for ${dotpi_instance_number}"
193
+ echo -n ' '
194
+
195
+ read -r user_instance_number
196
+ if [ -n "$user_instance_number" ] ; then
197
+ dotpi_instance_number="${user_instance_number}"
198
+ fi
199
+
200
+ echo ''
201
+ echo '##########################################################'
202
+ echo ''
203
+ fi
204
+
205
+ # remove any padding zero to avoid octal interpretation (sic)
206
+ dotpi_instance_number="$((10#${dotpi_instance_number}))"
207
+
208
+ #### copy instance over-rides
209
+
210
+ source_path="$project_path"
211
+ destination_path="${file_system_mirror}/opt/dotpi/etc"
212
+ mkdir -p -- "$destination_path"
213
+ source_file_path="${source_path}/dotpi_instance_$(printf "%03d" "${dotpi_instance_number}").bash"
214
+ destination_file_path="${destination_path}/dotpi_environment_instance.bash"
215
+ if [ -r "$source_file_path" ] ; then
216
+ dotpi_echo_info "Using instance-specific configuration ${source_file_path}"
217
+ cp -- "$source_file_path" "$destination_file_path"
218
+ fi
219
+
220
+
221
+ ####################################################
222
+ # mirror should be complete, now: switch to mirror #
223
+ ####################################################
224
+
225
+ DOTPI_ROOT="${file_system_mirror}/opt/dotpi"
226
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
227
+
228
+ ######## project name
229
+
230
+ destination_path="${DOTPI_ROOT}/etc"
231
+ destination_file_path="${destination_path}/dotpi_environment_project.bash"
232
+
233
+ # default project name is directory of project
234
+ if [[ -z "$dotpi_project_name" ]] ; then
235
+ dotpi_project_name="$(basename "$project_path")"
236
+ dotpi_echo_warning "Project name not found. Using project folder name: ${dotpi_project_name}"
237
+ dotpi_configuration_write --file "$destination_file_path" --key "dotpi_project_name" --value "$dotpi_project_name"
238
+ fi
239
+
240
+ ######## read extra files
241
+
242
+ if [ -z "$dotpi_hostname_prefix" ] ; then
243
+ dotpi_echo_error "Bad dotpi_hostname_prefix: ${dotpi_hostname_prefix}"
244
+ echo "Check ${project_path}/dotpi_project.bash"
245
+ exit 1
246
+ fi
247
+
248
+ dotpi_instance_hostname="${dotpi_hostname_prefix}-${dotpi_project_name}-$(printf "%03d" "${dotpi_instance_number}")"
249
+ if (( $? != 0 )) ; then
250
+ dotpi_echo_error "Bad dotpi_instance_number: ${dotpi_instance_number}"
251
+ exit 1
252
+ fi
253
+ dotpi_echo_info "Instance hostname: ${dotpi_instance_hostname}"
254
+
255
+ destination_file="${DOTPI_ROOT}/etc/dotpi_environment_instance.bash"
256
+ dotpi_configuration_write --file "$destination_file" --key 'dotpi_instance_number' --value "$dotpi_instance_number"
257
+ dotpi_configuration_write --file "$destination_file" --key 'dotpi_instance_hostname' --value "$dotpi_instance_hostname"
258
+
259
+
260
+ ### secrets for password
261
+
262
+ source_file="${project_path}/dotpi_secrets.bash"
263
+ destination_file="${DOTPI_ROOT}/etc/dotpi_environment_project.bash"
264
+ if ! [ -r "$source_file" ] ; then
265
+ dotpi_echo_error "unable to read secrets file ${source_file}"
266
+ exit 1
267
+ else
268
+ source "$source_file"
269
+
270
+ if [ -z "$dotpi_password" ] ; then
271
+ dotpi_echo_error "You must define a password: set dotpi_password in ${source_file} to a non-empty string."
272
+ exit 1
273
+ else
274
+ hash="$(openssl passwd -1 "$dotpi_password")"
275
+ dotpi_configuration_write --file "$destination_file" --key 'dotpi_password_hash' --value "$hash"
276
+ fi
277
+ fi
278
+
279
+ ### secrets for ssh public keys
280
+
281
+ source_path="${project_path}/ssh"
282
+ destination_path="${DOTPI_ROOT}/etc/ssh"
283
+ mkdir -p -- "$destination_path"
284
+ if [ -d "$source_path" ] && [ -r "$source_path" ] ; then
285
+ (set -o pipefail ; \
286
+ cd -- "$source_path" && tar c "${tar_options[@]}" *.pub \
287
+ | tar x -C "$destination_path") || {
288
+ dotpi_echo_error "No public key found in ${source_path}"
289
+ exit 1
290
+ }
291
+ fi
292
+
293
+ ### secrets for NetworkManager connections from project
294
+
295
+ source_path="${project_path}/network"
296
+ destination_path="${DOTPI_ROOT}/etc/network"
297
+ mkdir -p -- "$destination_path"
298
+ if [ -d "$source_path" ] && [ -r "$source_path" ] ; then
299
+ (set -o pipefail ; \
300
+ cd -- "$source_path" && tar c "${tar_options[@]}" *.nmconnection \
301
+ | tar x -C "$destination_path") || {
302
+ dotpi_echo_error "No network connection found in ${source_path}"
303
+ exit 1
304
+ }
305
+ fi
306
+
307
+ # update connections in DOTPI_ROOT
308
+
309
+ if ! $(wpa_passphrase test 12345678 > /dev/null 2>&1) ; then
310
+ dotpi_echo_warning "Network password won't be salted, 'wpa_passphrase' is needed to salt passwords."
311
+ else
312
+
313
+ for file in "${destination_path}"/*.nmconnection ; do
314
+ key='wifi-security.psk'
315
+ psk="$(dotpi_connection_read --file "$file" --key "$key")"
316
+
317
+ # psk present and not salted
318
+ if (( ${#psk} > 0 && ${#psk} < 64 )) ; then
319
+ key='wifi.ssid'
320
+ ssid="$(dotpi_connection_read --file "$file" --key "$key")"
321
+ passphrase="$(wpa_passphrase "$ssid" "$psk" | dotpi_configuration_read --key 'psk' )"
322
+ key='wifi-security.psk'
323
+ dotpi_connection_write --file "$file" --key "$key" --value "$passphrase"
324
+ fi
325
+
326
+ done
327
+ fi
328
+
329
+
330
+ ######## SD card
331
+
332
+ bootfs_name="bootfs"
333
+
334
+ if [[ "$(uname)" =~ "Darwin" ]] ; then
335
+ echo ""
336
+ echo "MacOS host detected"
337
+ echo ""
338
+
339
+ # try to mount if unmounted (but not ejected)
340
+ if type -P diskutil ; then
341
+ diskutil mount "$bootfs_name"
342
+ fi
343
+
344
+ # avoid spotlight errors
345
+ bootfs_path="$(find /Volumes -name "$bootfs_name" 2> /dev/null)"
346
+ elif [[ "$(uname -a)" =~ "Microsoft" ]] ; then
347
+ echo ""
348
+ echo "Windows Subsystem for Linux system detected"
349
+ echo ""
350
+
351
+ bootfs_mount_reference=($(findmnt -lo source,target | grep "$bootfs_name"))
352
+ if ! [[ -n "$bootfs_mount_reference" ]] ; then
353
+ # not there, mount
354
+
355
+ bootfs_mount_source="${bootfs_drive_letter^^}:\\"
356
+ bootfs_mount_target="${tmp_path}/${bootfs_name}"
357
+ mkdir -p "$bootfs_mount_target"
358
+ mount -t drvfs "$bootfs_mount_source" "$bootfs_mount_target" || {
359
+ dotpi_echo_error "Unable to mount ${bootfs_mount_source} to ${bootfs_mount_target}"
360
+ }
361
+ fi
362
+
363
+ bootfs_mount_reference=($(findmnt -lo source,target | grep "$bootfs_name"))
364
+ if [[ -n "$bootfs_mount_reference" ]] ; then
365
+ bootfs_mount_source="${bootfs_mount_reference[0]}"
366
+ bootfs_mount_target="${bootfs_mount_reference[1]}"
367
+ bootfs_path="$bootfs_mount_target"
368
+ else
369
+ bootfs_path=""
370
+ rmdir "$bootfs_mount_target"
371
+ fi
372
+
373
+ elif [[ "$(uname)" =~ "Linux" ]] ; then
374
+ echo ""
375
+ echo "Linux system detected"
376
+ echo ""
377
+
378
+ # try to mount if unmounted (but not ejected)
379
+ if type -P udisksctl ; then
380
+ udisksctl mount --block-device "/dev/disk/by-label/${bootfs_name}" 2> /dev/null
381
+ fi
382
+
383
+ bootfs_path="$(lsblk --output MOUNTPOINT | grep "$bootfs_name")"
384
+ else
385
+ echo ""
386
+ echo "Unknown system detected"
387
+ echo ""
388
+ echo
389
+ echo "Please adapt for your environment and send us feedback."
390
+ exit 1
391
+ fi
392
+
393
+ if [ ! -d "$bootfs_path" ] ; then
394
+ echo ""
395
+ echo "############################################################"
396
+ echo ""
397
+ echo " Please mount SD card and try again."
398
+ echo ""
399
+ echo "############################################################"
400
+ echo ""
401
+ exit 1
402
+ fi
403
+
404
+
405
+ ######### config.txt
406
+
407
+ config_filename='config.txt'
408
+ config_file="${project}/${config_filename}"
409
+ destination_path="${DOTPI_ROOT}/etc"
410
+
411
+ mkdir -p -- "$destination_path"
412
+
413
+ if [ -r "$config_file" ] ; then
414
+ echo "using project config file ${config_file}"
415
+ else
416
+ config_file="${bootfs_path}/${config_filename}"
417
+ echo "# copy config file from imager"
418
+ fi
419
+
420
+ cp -- "$config_file" "$destination_path"
421
+
422
+ config_file="${destination_path}/${config_filename}"
423
+
424
+ echo "# edit ${config_file}"
425
+
426
+ # keep quotes here to keep quotes hereafter
427
+ cat >> "${config_file}" << EOF
428
+
429
+ ############
430
+ # dotpi
431
+ #
432
+
433
+ [all]
434
+
435
+ EOF
436
+
437
+ if [[ "$dotpi_word_size" == "32" ]] ; then
438
+ word_size="$(dotpi_file_word_size "${bootfs_path}/start.elf" )"
439
+ if [[ "$word_size" == "32" ]] ; then
440
+
441
+ file="$config_file"
442
+ key="arm_64bits"
443
+
444
+ # comment original value
445
+ dotpi_configuration_comment --file "$file" --key "$key"
446
+ dotpi_configuration_write \
447
+ --file "$file" --key "$key" \
448
+ --value "0" --prepend-line-if-new '# true 32bit system'
449
+ fi
450
+ fi
451
+
452
+ ######### audio device
453
+
454
+ # set model before, as it will select jackd configuration
455
+ dotpi_audio_device_select --model "$dotpi_audio_device" --config "$config_file"
456
+
457
+ # copy configuration files from project for over-rides
458
+ source_path="${project_path}/jackd"
459
+ destination_path="${DOTPI_ROOT}/share/jackd"
460
+ mkdir -p -- "$destination_path"
461
+ if [ -d "$source_path" ] && [ -r "$source_path" ] ; then
462
+ (set -o pipefail ; \
463
+ cd -- "$source_path" && tar c "${tar_options[@]}" '.' \
464
+ | tar x -C "$destination_path") || {
465
+ dotpi_echo_error "Unable to install files from ${source_path}"
466
+ exit 1
467
+ }
468
+ fi
469
+
470
+
471
+ # back-up imager config
472
+
473
+ destination_filename="imager_${config_filename}"
474
+
475
+ # install config.txt to /boot to be ready for first run
476
+ cp -- "$config_file" "$bootfs_path"
477
+
478
+ ######### configure first run
479
+
480
+ echo "# set-up first run"
481
+
482
+ source_file_path="${bootfs_path}/firstrun.sh"
483
+ if [ -f "$source_file_path" ] ; then
484
+ # back-up imager firstrun.sh
485
+ destination_filename='imager_firstrun.sh'
486
+ # keep a copy on bootfs
487
+ destination_path="${bootfs_path}/dotpi"
488
+
489
+ mkdir -p -- "$destination_path"
490
+
491
+ if [ -r "${destination_path}/${destination_filename}" ] ; then
492
+ dotpi_echo_warning "Keep existing imager first-run script: ${destination_path}/${destination_filename}"
493
+ else
494
+ cp -- "$source_file_path" "${destination_path}/${destination_filename}"
495
+
496
+ destination_path="${DOTPI_ROOT}/etc"
497
+ mkdir -p -- "$destination_path"
498
+ cp -- "$source_file_path" "${destination_path}/${destination_filename}"
499
+ fi
500
+ else
501
+ dotpi_echo_warning "firstrun.sh not found"
502
+ fi
503
+
504
+ # configure cmdline.txt for firstun script, if not already here
505
+ source_file_name='cmdline.txt'
506
+ source_file_path="${bootfs_path}/${source_file_name}"
507
+ destination_path="${bootfs_path}/dotpi"
508
+ pattern='systemd.run=/boot/firstrun.sh'
509
+ pattern_escaped="$(dotpi_configuration_escape_string "$pattern")"
510
+ first_run_configured="$(perl -ne 'if (m/'"$pattern_escaped"'/) { print "1"; }' "$source_file_path")"
511
+ if (( first_run_configured != 1 )) ; then
512
+ dotpi_echo_info "Configuring firstrun in ${source_file_path}"
513
+ # keep a copy of originalc command-line
514
+ mkdir -p -- "$destination_path"
515
+ cp -- "$source_file_path" "${destination_path}/imager_${source_file_name}"
516
+ # append:run script and reboot on success
517
+ arguments=(
518
+ 'systemd.run=/boot/firstrun.sh'
519
+ 'systemd.run_success_action=reboot'
520
+ 'systemd.unit=kernel-command-line.target'
521
+ )
522
+ pattern="${arguments[*]}"
523
+ pattern_escaped="$(dotpi_configuration_escape_string "$pattern")"
524
+ # do not append to a new line
525
+ # append a space to separate from previous arguments (extra does not hurt)
526
+
527
+ # windows error: Cannot complete in-place edit of tmp/bootfs/cmdline.txt
528
+ source_file_path_tmp="${tmp_path}/${source_file_name}"
529
+ cp "$source_file_path" "$source_file_path_tmp"
530
+ dotpi_sed 's/$/${1} '"$pattern_escaped"'/' -i -- "$source_file_path_tmp"
531
+ mv "$source_file_path_tmp" "$source_file_path"
532
+ fi
533
+
534
+ # replace first run with custom, that will over-ride imager settings
535
+ # run dotpi_firstrun.bash
536
+ cat > "${bootfs_path}/firstrun.sh" << "EOF"
537
+ #!/bin/bash
538
+
539
+ set +e
540
+
541
+ # since Raspberry Pi OS Bookworm
542
+ local_path='/boot/firmware'
543
+
544
+ if ! [ -d "$local_path" ] ; then
545
+ # for Raspberry Pi OS Bullseye
546
+ local_path='/boot'
547
+ fi
548
+
549
+ # log to boot partition to access it even on errors
550
+ log_file="${local_path}/firstrun-$(date +"%Y%m%d-%H%M%S").log"
551
+
552
+ clean_up() {
553
+ rm -f "${local_path}/firstrun.sh"
554
+ sed -i 's| systemd.run.*||g' "${local_path}/cmdline.txt"
555
+ }
556
+
557
+ (cd -- / && tar xz -m --no-same-owner --no-same-permissions --no-overwrite-dir -f "${local_path}/dotpi/file_system.tgz")
558
+
559
+ source_path="/opt/dotpi"
560
+ cd -- "$source_path" || { clean_up ; exit 1; }
561
+ "bin/dotpi_firstrun" "$log_file"
562
+
563
+ clean_up
564
+
565
+ exit 0
566
+
567
+ EOF
568
+
569
+
570
+ ########## archive mirror to bootfs
571
+
572
+ echo "# archive mirror"
573
+
574
+ source_path="$file_system_mirror"
575
+ destination_path="${bootfs_path}/dotpi"
576
+ mkdir -p -- "$destination_path"
577
+
578
+ # create archive for installing, later
579
+ # this overcomes the limitiations of the FAT32 boot volume
580
+ tar cz "${tar_options[@]}" -C "${source_path}" '.' > "${destination_path}/file_system.tgz"
581
+
582
+ # un-mount
583
+ if type -P diskutil 2>&1 > /dev/null ; then
584
+ diskutil umount "$bootfs_name" || :
585
+ elif [[ -n "$bootfs_mount_source" ]] && [[ -n "$bootfs_mount_target" ]] ; then
586
+ umount "$bootfs_mount_source"
587
+ rmdir "$bootfs_mount_target"
588
+
589
+
590
+ echo ""
591
+ echo "####################################################"
592
+ echo ""
593
+ echo " Please eject SD card from Windows host."
594
+ echo ""
595
+ echo "####################################################"
596
+ echo ""
597
+
598
+
599
+ elif type -P udisksctl 2>&1 > /dev/null ; then
600
+ udisksctl unmount -b "/dev/disk/by-label/${bootfs_name}" 2>&1 > /dev/null
601
+ fi
602
+
603
+ dotpi_echo_info "Mirror of file-system is here: ${file_system_mirror}"
604
+
605
+ (( dotpi_instance_number++ ))
606
+ dotpi_configuration_write --file "$environment_tmp_file" --key dotpi_instance_number --value "$dotpi_instance_number"
607
+
608
+ echo ""
609
+ echo "####################################################"
610
+ echo ""
611
+ echo " Please put SD card in Raspberry Pi and power on."
612
+ echo ""
613
+ echo "####################################################"
614
+ echo ""
615
+
616
+ dotpi_echo_info "You can monitor the preparation of the system with the following command"
617
+ dotpi_echo_info "(You will have to wait until the network is ready.)"
618
+ dotpi_echo_info ''
619
+ dotpi_echo_info "ssh ${dotpi_user}@${dotpi_instance_hostname}.local 'tail -f /opt/dotpi/var/log/dotpi_prepare_system_*.log'"
620
+
@@ -0,0 +1,82 @@
1
+ #!/bin/bash
2
+
3
+ set +e
4
+
5
+ # This script MUST be executed by `pi` user
6
+ FIRSTUSER="$(getent passwd 1000 | cut -d: -f1)"
7
+ if [[ $(whoami) != "${FIRSTUSER}" ]] ; then
8
+ echo "This script MUST be executed by pi user (or first user)"
9
+ exit 1
10
+ fi
11
+
12
+ DOTPI_ROOT="${DOTPI_ROOT:-/opt/dotpi}"
13
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
14
+
15
+ echo "Uninstall apt packages: ${dotpi_apt_uninstall[@]}"
16
+ dotpi_apt_get purge "${dotpi_apt_uninstall[@]}"
17
+
18
+ dotpi_apt_get clean
19
+ dotpi_apt_get autoremove -y
20
+
21
+ echo "Update and dist-upgrade"
22
+ dotpi_apt_get update
23
+ dotpi_apt_get dist-upgrade
24
+
25
+ echo "Install apt packages: ${dotpi_apt_install[@]}"
26
+ dotpi_apt_get install "${dotpi_apt_install[@]}"
27
+
28
+
29
+ echo "Install Node.js"
30
+
31
+ word_size="$(dotpi_file_word_size "$(which file)" )"
32
+ if [[ $word_size == "32" ]] ; then
33
+ node_arch=armv7l
34
+ else
35
+ node_arch=arm64
36
+ fi
37
+
38
+ (set -o pipefail ; curl -L https://bit.ly/n-install | bash -s -- -y -a "$node_arch" "$dotpi_node_version") && (
39
+ cat >> "${HOME}/.bashrc" << EOF
40
+
41
+ # dotpi: force the usage of -a for correct architecture
42
+ # (n relies on uname, which tells about the kernel, not the executables)
43
+
44
+ alias n="n -a ${node_arch}"
45
+
46
+ EOF
47
+ <<<<<<< HEAD
48
+ =======
49
+
50
+ >>>>>>> origin/main
51
+ )
52
+
53
+ source "${HOME}/.bashrc"
54
+
55
+ echo "Install Jackd daemon"
56
+
57
+ sudo dpkg-reconfigure -f noninteractive -p high jackd2
58
+
59
+ source_file="${DOTPI_ROOT}/share/limits/audio.conf"
60
+ destination_path='/etc/security/limits.d'
61
+ if [ -r "$source_file" ] ; then
62
+ sudo mkdir -p "$destination_path"
63
+ sudo cp "$source_file" "$destination_path"
64
+ fi
65
+
66
+ dotpi_echo_warning "You should close all active session windows for jackd high priority"
67
+
68
+ dotpi_daemon_install "${DOTPI_ROOT}/share/jackd/jackd.service"
69
+
70
+
71
+ echo "Install dotpi manager"
72
+ destination_path="${DOTPI_ROOT}/share/dotpi-manager/runtime"
73
+ sudo mkdir -p "$destination_path"
74
+ sudo chown "$FIRSTUSER" -R "$destination_path"
75
+ git clone https://github.com/ircam-ismm/dotpi-manager.git "$destination_path"
76
+ (
77
+ cd "${DOTPI_ROOT}/share/dotpi-manager/runtime"
78
+ npm install
79
+ npm run build
80
+ )
81
+ dotpi_daemon_install "${DOTPI_ROOT}/share/dotpi-manager/dotpi-manager.service"
82
+