@dotpi/tools 1.3.3 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) 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/NOTES.md +41 -1
  7. package/README.md +3 -13
  8. package/dotpi_root/bin/dotpi +1 -0
  9. package/dotpi_root/bin/dotpi_prepare_sd_card +34 -22
  10. package/dotpi_root/bin/dotpi_prepare_system +113 -68
  11. package/dotpi_root/bin/package.json +6 -0
  12. package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor.service +1 -5
  13. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_install +21 -0
  14. package/dotpi_root/dist/@dotpi/avahi_monitor/dotpi_uninstall +17 -0
  15. package/dotpi_root/dist/@dotpi/avahi_monitor/package.json +10 -0
  16. package/dotpi_root/dist/@dotpi/javascript/bash.js +103 -0
  17. package/dotpi_root/dist/@dotpi/javascript/echo.js +13 -0
  18. package/dotpi_root/dist/@dotpi/javascript/filesystem.js +25 -0
  19. package/dotpi_root/dist/@dotpi/javascript/package.json +12 -0
  20. package/dotpi_root/dist/@dotpi/javascript/service.js +49 -0
  21. package/dotpi_root/dist/@dotpi/javascript/system.js +36 -0
  22. package/dotpi_root/dist/@dotpi/javascript/template.js +13 -0
  23. package/dotpi_root/dist/@dotpi/javascript/user.js +32 -0
  24. package/dotpi_root/dist/@dotpi/module/LICENSE +28 -0
  25. package/dotpi_root/dist/@dotpi/module/bin/dotpi_module +13 -0
  26. package/dotpi_root/dist/@dotpi/module/dotpi_install +52 -0
  27. package/dotpi_root/dist/@dotpi/module/dotpi_uninstall +50 -0
  28. package/dotpi_root/dist/@dotpi/module/package.json +22 -0
  29. package/dotpi_root/dist/@dotpi/module/src/configuration.js +43 -0
  30. package/dotpi_root/dist/@dotpi/module/src/createConfig.js +108 -0
  31. package/dotpi_root/dist/@dotpi/module/src/definition.js +7 -0
  32. package/dotpi_root/dist/@dotpi/module/src/index.js +0 -0
  33. package/dotpi_root/dist/@dotpi/module/src/install.js +145 -0
  34. package/dotpi_root/dist/@dotpi/module/src/uninstall.js +180 -0
  35. package/dotpi_root/etc/dotpi_environment_default.bash +16 -0
  36. package/dotpi_root/etc/dotpi_init.d/.gitkeep +0 -0
  37. package/dotpi_root/etc/dotpi_modules.json +8 -0
  38. package/dotpi_root/lib/package.json +6 -0
  39. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +7 -6
  40. package/dotpi_root/share/dotpi_audio_bluetooth/package.json +6 -0
  41. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +12 -26
  42. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +2 -2
  43. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +6 -2
  44. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +11 -0
  45. package/dotpi_root/share/dotpi_functions/dotpi_functions_user.bash +28 -0
  46. package/dotpi_root/share/dotpi_functions.bash +4 -4
  47. package/dotpi_root/share/dotpi_init.bash +10 -1
  48. package/dotpi_root/share/dotpi_pipewire/bin/dotpi_pipewire_relink +86 -0
  49. package/dotpi_root/share/dotpi_pipewire/dotpi_install +24 -0
  50. package/dotpi_root/share/dotpi_pipewire/package.json +9 -0
  51. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire.service +22 -0
  52. package/dotpi_root/share/dotpi_pipewire/systemd/dotpi_pipewire_command +29 -0
  53. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +2 -6
  54. package/dotpi_root/share/wireplumber/wireplumber.conf.d/dotpi-wireplumber-config.conf +8 -0
  55. package/lerna.json +4 -0
  56. package/package.json +12 -2
  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/led-test/.dotpi +3 -0
  71. package/projects/led-test/README.md +16 -0
  72. package/projects/led-test/dotpi_project.bash +29 -0
  73. package/projects/old/bad/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  74. package/projects/old/bad/.editorbackup/dotpi_environment_project.bash~ +26 -0
  75. package/projects/old/bad/.editorbackup/dotpi_project.bash~ +33 -0
  76. package/projects/old/bad/.editorbackup/dotpi_tmp.bash~ +3 -0
  77. package/projects/old/bad/.editorbackup/wpa_supplicant.conf~ +37 -0
  78. package/projects/old/bad/dotpi_project.bash +20 -0
  79. package/projects/old/bluetooth/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  80. package/projects/old/bluetooth/.editorbackup/dotpi_environment_project.bash~ +26 -0
  81. package/projects/old/bluetooth/.editorbackup/dotpi_project.bash~ +21 -0
  82. package/projects/old/bluetooth/.editorbackup/dotpi_tmp.bash~ +3 -0
  83. package/projects/old/bluetooth/.editorbackup/wpa_supplicant.conf~ +37 -0
  84. package/projects/old/bluetooth/dotpi_project.bash +29 -0
  85. package/projects/old/dev.zip +0 -0
  86. package/projects/old/example/.editorbackup/dotpi_environment_instance.bash~ +1 -0
  87. package/projects/old/example/.editorbackup/dotpi_environment_project.bash~ +26 -0
  88. package/projects/old/example/.editorbackup/dotpi_project.bash~ +21 -0
  89. package/projects/old/example/.editorbackup/dotpi_tmp.bash~ +3 -0
  90. package/projects/old/example/.editorbackup/wpa_supplicant.conf~ +37 -0
  91. package/projects/old/example/configuration/.editorbackup/dotpi_project.bash~ +21 -0
  92. package/projects/old/example/configuration/dotpi_project.bash +21 -0
  93. package/projects/qsddsqsd/.dotpi +3 -0
  94. package/projects/qsddsqsd/README.md +16 -0
  95. package/projects/qsddsqsd/dotpi_project.bash +29 -0
  96. package/src/constants.js +4 -4
  97. package/src/create-project.js +124 -56
  98. package/src/templates/dotpi_project.bash +5 -7
  99. package/src/utils.js +2 -2
  100. package/test/create-project.test.js +0 -1
  101. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +0 -18
  102. package/dotpi_root/share/jackd/dotpi_jackd_command +0 -26
  103. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +0 -21
  104. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +0 -17
  105. package/dotpi_root/share/jackd/jackd.service +0 -22
  106. /package/dotpi_root/{share/dotpi_avahi_monitor → dist/@dotpi/avahi_monitor}/dotpi_avahi_monitor_command +0 -0
@@ -0,0 +1,180 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ import { $ } from 'execa';
5
+ import { globby } from 'globby';
6
+
7
+ import * as echo from '@dotpi/javascript/echo.js';
8
+
9
+ import { dotpiConfigurationGet } from './configuration.js';
10
+ import { definitionGet } from './definition.js';
11
+
12
+ export async function uninstallCommandDefine({program}) {
13
+ program
14
+ .command('uninstall [modules...]')
15
+ .summary('uninstall a list of modules')
16
+ .description('Uninstall a list of modules separated by space.')
17
+ .option('-r, --dotpi-root <path>', 'dotpi root path, to initialise environment')
18
+ .option('-p, --prefix <path>', 'install modules in this directory')
19
+ .option('-v, --verbose [full]', 'print verbose output [full]')
20
+ .action((modules, options, command) => uninstall(modules, { ...options, command }));
21
+ ;
22
+ return program;
23
+ }
24
+
25
+ async function uninstallScriptRun(module, {
26
+ verbose = 'short',
27
+ } = {}) {
28
+ try {
29
+
30
+ const cwd = module;
31
+ const output = await $({
32
+ cwd,
33
+ })`npm --prefix ${cwd}
34
+ run --json
35
+ `;
36
+ const uninstallScript = JSON.parse(output.stdout).preuninstall;
37
+
38
+ if (uninstallScript) {
39
+ // npm does not automatically run preuninstall script
40
+
41
+ if(verbose !== 'none') {
42
+ echo.info(`Running uninstall script for ${module}`);
43
+ }
44
+ await $({
45
+ cwd,
46
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
47
+ verbose: (verbose === 'full' ? 'full' : 'none'),
48
+ })`npm --prefix ${cwd}
49
+ run preuninstall
50
+ `;
51
+ }
52
+
53
+ return output;
54
+ } catch (error) {
55
+ echo.error(`Failed to run uninstall script for ${module}: ${error.message}`);
56
+ throw error;
57
+ }
58
+ }
59
+
60
+ export async function uninstall(modules = [], {
61
+ dotpiRoot,
62
+ prefix,
63
+ verbose = 'short',
64
+ } = {}) {
65
+ if (typeof modules === 'string') {
66
+ modules = [modules];
67
+ }
68
+
69
+ switch (verbose) {
70
+ case '0':
71
+ case 'false':
72
+ case false:
73
+ verbose = 'none';
74
+ break;
75
+
76
+ case '1':
77
+ case 'true':
78
+ case true:
79
+ verbose = 'short';
80
+ break;
81
+
82
+ case '2':
83
+ verbose = 'full';
84
+ break;
85
+ }
86
+
87
+ let dotpiModulesDestination;
88
+ let dotpiModulesConfiguration;
89
+ try {
90
+ ({
91
+ modulesPath: dotpiModulesDestination,
92
+ modulesConfiguration: dotpiModulesConfiguration,
93
+ } = await dotpiConfigurationGet({ dotpiRoot, prefix }));
94
+ } catch (error) {
95
+ echo.error(`Failed to get dotpi configuration: ${error.message}`);
96
+ process.exit(1);
97
+ }
98
+
99
+ // no parallelisation to uninstall modules
100
+ let moduleToUninstall;
101
+ for (const module of modules) {
102
+ try {
103
+ const moduleRegistered = dotpiModulesConfiguration.moduleSource[module];
104
+ if (moduleRegistered) {
105
+ if(verbose !== 'none') {
106
+ echo.info(`Module '${module}' is registered as '${moduleRegistered}'`);
107
+ }
108
+ moduleToUninstall = moduleRegistered;
109
+ } else {
110
+ moduleToUninstall = module;
111
+ }
112
+
113
+ let output;
114
+ let cwd;
115
+
116
+ if(verbose === 'full') {
117
+ console.log(`Getting '${moduleToUninstall}' definition`);
118
+ }
119
+ const moduleDefinition = await definitionGet(moduleToUninstall);
120
+ const { name: moduleName } = moduleDefinition;
121
+
122
+ // uninstall actually installed module
123
+ moduleToUninstall = moduleName;
124
+
125
+ if(verbose !== 'none') {
126
+ echo.info(`Uninstalling module '${moduleToUninstall}' in '${dotpiModulesDestination}'`);
127
+ }
128
+
129
+ cwd = path.resolve(dotpiModulesDestination, 'node_modules', moduleName);
130
+
131
+ // throw error if module is not installed, caught to continue with next module
132
+ await fs.access(cwd);
133
+
134
+ // First, uninstall dependencies manually,
135
+ // as npm doest not execute {pre,post}uninstall scripts since version 7
136
+
137
+ const dependencies = await globby(
138
+ // globby needs a posix path
139
+ `${path.posix.resolve(cwd)}/**/node_modules/*`
140
+ );
141
+ for(const dependency of dependencies) {
142
+ try {
143
+ await uninstallScriptRun(dependency, { verbose });
144
+ } catch (error) {
145
+ // continue with other dependencies
146
+ }
147
+ }
148
+
149
+ output = await uninstallScriptRun(cwd, { verbose });
150
+
151
+ if(verbose !== 'none') {
152
+ echo.info(`Uninstalling ${moduleToUninstall}`);
153
+ }
154
+
155
+ cwd = dotpiModulesDestination;
156
+ output = await $({
157
+ cwd,
158
+ env: { FORCE_COLOR: 'true' }, // do not remove colors
159
+ verbose: (verbose === 'full' ? 'full' : 'none'),
160
+ })`
161
+ npm --prefix ${cwd}
162
+ uninstall
163
+ --save
164
+ --
165
+ ${moduleName}
166
+ `;
167
+
168
+ } catch (error) {
169
+ if (error.code === 'ENOENT') {
170
+ echo.warning(`Module ${moduleToUninstall} is not installed`);
171
+ continue;
172
+ }
173
+
174
+ // give up for other errors
175
+ echo.error(`Failed to uninstall ${moduleToUninstall}: ${error.message}`);
176
+ process.exit(1);
177
+ }
178
+
179
+ } // for (const module of modules)
180
+ }
@@ -66,4 +66,20 @@ dotpi_apt_install_default=(
66
66
  # user-defined, use +=(package1 package2) to add packages to list
67
67
  dotpi_apt_install=()
68
68
 
69
+ # system default
70
+ dotpi_module_uninstall_default=()
71
+
72
+ # user-defined, use +=(package1 package2) to add packages to list
73
+ dotpi_module_uninstall=()
74
+
75
+ # system default
76
+ dotpi_module_install_default=(
77
+ # '@dotpi/module' is already installed to bootstrap
78
+ # '@dotpi/manager'
79
+ '@dotpi/avahi_monitor'
80
+ )
81
+
82
+ # user-defined, use +=(package1 package2) to add packages to list
83
+ dotpi_module_install=()
84
+
69
85
  dotpi_node_version='lts'
File without changes
@@ -0,0 +1,8 @@
1
+ {
2
+ "moduleSource": {
3
+
4
+ "_example_git": "git+https://github.com/ircam-ismm/dotpi-led#feat-dotpi-module",
5
+ "_example_local": "file:///opt/dotpi/dist/@dotpi/avhi_monitor",
6
+ "_see_npm_doc": "https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies"
7
+ }
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "dotpi_root_installed_packages",
3
+ "description": "Packages installed in ${DOTPI_ROOT}/lib",
4
+ "dependencies": {
5
+ }
6
+ }
@@ -1,10 +1,11 @@
1
- #!/usr/bin/node
1
+ #!/usr/bin/env node
2
2
 
3
3
  // @TODO: use a proper pipewire lua script that automatically runs
4
4
  // whenever the default audio output is restored
5
5
 
6
- const util = require('node:util');
7
- const exec = util.promisify(require('node:child_process').exec);
6
+ import util from 'node:util';
7
+ import child_process from 'node:child_process';
8
+ const exec = util.promisify(child_process.exec);
8
9
 
9
10
  let pipewireData = null;
10
11
  async function pipewireRelink() {
@@ -102,11 +103,11 @@ async function pipewireRelink() {
102
103
 
103
104
  for(let p = 0; p < playbackNodes.length; ++p) {
104
105
  for(let o = 0; o < outputNodes.length; ++o) {
105
- playbackIndex = playbackNodes[p].id;
106
- outputIndex = outputNodes[o].id;
106
+ const playbackIndex = playbackNodes[p].id;
107
+ const outputIndex = outputNodes[o].id;
107
108
  const commandString = `pw-link ${playbackIndex} ${outputIndex}`;
108
109
  try {
109
- console.log(commandString);
110
+ // console.log(commandString);
110
111
  const {stdout, stderr} = await exec(commandString);
111
112
  // console.log('pw-link stdout:', stdout);
112
113
  if(stderr) {
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@dotpi/audio_bluetooth",
3
+ "description": "Monitor audio bluetooth keep it powered on and to dynamically relink playback nodes to output nodes",
4
+ "version": "1.0.0",
5
+ "type": "module"
6
+ }
@@ -36,6 +36,18 @@ dotpi_audio_device_supported=(
36
36
  'ue megaboom 3'
37
37
  )
38
38
 
39
+ dotpi_audio_device_is_analog() {
40
+ audio_device="${1:-$dotpi_audio_device}"
41
+ case "$audio_device" in
42
+ 'headphones')
43
+ return 0
44
+ ;;
45
+ *)
46
+ return 1
47
+ ;;
48
+ esac
49
+ }
50
+
39
51
  _dotpi_audio_device_get_options() {
40
52
 
41
53
  _echo_empty_option_error() {
@@ -284,24 +296,6 @@ dotpi_audio_device_select() (
284
296
  --value \""${model_value}"\"
285
297
  )
286
298
 
287
- _dotpi_audio_device_jackd_set_configuration() (
288
- model="$1"
289
- (cd "${DOTPI_ROOT}/share/jackd" && ln -s -f "dotpi_jackd_${model}.bash" 'dotpi_jackd.bash') || {
290
- dotpi_echo_error "Unable to change jackd configuration to ${model}"
291
- return 1
292
- }
293
-
294
- # we can change audio device in a temporary file-system, too
295
- if dotpi_system_is_raspberry_pi ; then
296
- dotpi_echo_warning "Restart jackd service"
297
- service='jackd'
298
- systemctl is-active "$service" > /dev/null 2>&1 \
299
- && systemctl restart "$service" || {
300
- dotpi_echo_warning "systemctl unable to restart service ${service}"
301
- }
302
- fi
303
- )
304
-
305
299
  _dotpi_audio_device_disable_all() (
306
300
  exception_family="$1"
307
301
 
@@ -338,14 +332,10 @@ _dotpi_audio_device_select_headphones() (
338
332
  # (setting at the end the the file fails)
339
333
  pattern="$(dotpi_configuration_get_pattern --prefix "# dtparam=audio")"
340
334
  perl -pe "s/${pattern}/"'dtparam=audio=on/' -i -- "$config_file"
341
-
342
- _dotpi_audio_device_jackd_set_configuration "headphones"
343
335
  )
344
336
 
345
337
  _dotpi_audio_device_select_bluetooth() (
346
338
  _dotpi_audio_device_disable_all bluetooth
347
-
348
- _dotpi_audio_device_jackd_set_configuration "bluetooth"
349
339
  )
350
340
 
351
341
  _dotpi_audio_device_select_raspberry_pi() (
@@ -360,8 +350,6 @@ _dotpi_audio_device_select_raspberry_pi() (
360
350
  dtoverlay=${dtoverlay}
361
351
 
362
352
  EOF
363
-
364
- _dotpi_audio_device_jackd_set_configuration "hifiberry"
365
353
  )
366
354
 
367
355
 
@@ -377,8 +365,6 @@ _dotpi_audio_device_select_hifiberry() (
377
365
  dtoverlay=${dtoverlay}
378
366
 
379
367
  EOF
380
-
381
- _dotpi_audio_device_jackd_set_configuration "hifiberry"
382
368
  )
383
369
 
384
370
  _dotpi_audio_device_disable_headphones() (
@@ -93,8 +93,8 @@ _dotpi_configuration_get_options() {
93
93
  }
94
94
 
95
95
  dotpi_configuration_escape_string() (
96
- # escape / \ $
97
- echo "$(echo "$1" | perl -pe 's#([/\\\$])#\\${1}#g')"
96
+ # escape all for regexp
97
+ echo -n "$1" | perl -ne 'print quotemeta($_)'
98
98
  )
99
99
 
100
100
  dotpi_configuration_get_pattern() (
@@ -44,8 +44,10 @@ dotpi_service_install() (
44
44
  ln -s -f "$(dotpi readlink_follow "${service_file}")" "${service_destination}"
45
45
 
46
46
  if (( user_service )); then
47
+ regular_user_name="$(dotpi_regular_user_get_name)"
48
+
47
49
  # drop sudo, with a proper session, including XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS
48
- command_prefix=(systemctl --machine="${SUDO_USER}@")
50
+ command_prefix=(systemctl --machine="${regular_user_name}@")
49
51
  else
50
52
  command_prefix=(systemctl)
51
53
  fi
@@ -99,8 +101,10 @@ dotpi_service_uninstall() (
99
101
  rm -f "${service_destination}/${service_name}"
100
102
 
101
103
  if (( user_service )); then
104
+ regular_user_name="$(dotpi_regular_user_get_name)"
105
+
102
106
  # drop sudo, with a proper session, including XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS
103
- command_prefix=(systemctl --machine="${SUDO_USER}@")
107
+ command_prefix=(systemctl --machine="${regular_user_name}@")
104
108
  else
105
109
  command_prefix=(systemctl)
106
110
  fi
@@ -1,5 +1,16 @@
1
1
  #!/bin/bash
2
2
 
3
+ dotpi_root_get() (
4
+ dotpi_root="${DOTPI_ROOT}"
5
+
6
+ if [[ -z "$dotpi_root" ]] ; then
7
+ local_file="$(dotpi_readlink_follow "${BASH_SOURCE[0]}")"
8
+ dotpi_root="$(dirname -- "$(dirname -- "$local_file")")"
9
+ fi
10
+
11
+ echo "$dotpi_root"
12
+ )
13
+
3
14
  # echo 'raspberry' or 'other'
4
15
  dotpi_system_is_raspberry_pi() (
5
16
  model='other'
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+
3
+ dotpi_regular_user_get_id() (
4
+ regular_user_id="${SUDO_UID:-1000}"
5
+ if (( regular_user_id == 0 )) ; then
6
+ regular_user_id=1000
7
+ fi
8
+
9
+ echo "$regular_user_id"
10
+ )
11
+
12
+ dotpi_regular_user_get_name() (
13
+ regular_user_id="$(dotpi_regular_user_get_id)"
14
+ regular_user_name="$(getent passwd "$regular_user_id" | cut -d: -f1)"
15
+ echo "$regular_user_name"
16
+ )
17
+
18
+ dotpi_regular_user_get_gid() (
19
+ regular_user_id="$(dotpi_regular_user_get_id)"
20
+ regular_user_name="$(getent passwd "$regular_user_id" | cut -d: -f3)"
21
+ echo "$regular_user_name"
22
+ )
23
+
24
+ dotpi_regular_user_get_home() (
25
+ regular_user_id="$(dotpi_regular_user_get_id)"
26
+ regular_user_home="$(getent passwd "$regular_user_id" | cut -d: -f6)"
27
+ echo "$regular_user_home"
28
+ )
@@ -2,13 +2,13 @@
2
2
 
3
3
  #### default functions
4
4
 
5
- for file in "${DOTPI_ROOT}/share/dotpi_functions/"* ; do
5
+ while IFS= read -r -d '' source_file ; do
6
6
  # continue on error
7
- source "$file" || true
8
- done
7
+ source "$source_file" || true
8
+ done < <( find "${DOTPI_ROOT}/share/dotpi_functions" -name '*.bash' -type f -print0 )
9
9
 
10
- #### dotpi-manager
11
10
 
11
+ # @TODO remove after migration to dotpi modules
12
12
  # continue on error
13
13
  dotpi_source_if_available "${DOTPI_ROOT}/share/dotpi-manager/dotpi-manager.bash" || true
14
14
  dotpi_source_if_available "${DOTPI_ROOT}/share/dotpi-led/dotpi-led.bash" || true
@@ -13,6 +13,15 @@ _local_path="$(cd -- "$(dirname -- "${_local_file}")" && pwd)"
13
13
  DOTPI_ROOT="$(cd -- "${_local_path}/.." && pwd)"
14
14
  export DOTPI_ROOT
15
15
 
16
- source "${DOTPI_ROOT}/share/dotpi_functions.bash"
16
+ export PATH="${PATH}:${DOTPI_ROOT}/usr/bin"
17
+ export PATH="${PATH}:${DOTPI_ROOT}/bin"
17
18
 
19
+ source "${DOTPI_ROOT}/share/dotpi_functions.bash"
18
20
  source "${DOTPI_ROOT}/share/dotpi_environment.bash"
21
+
22
+ #### installed modules
23
+
24
+ while IFS= read -r -d '' source_file ; do
25
+ # continue on error
26
+ source "$source_file" || true
27
+ done < <( find "${DOTPI_ROOT}/etc/dotpi_init.d" -name '*.bash' -type f -print0 )
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @TODO: use a proper pipewire lua script that automatically runs
4
+ // whenever the default audio output is restored
5
+
6
+ import util from 'node:util';
7
+ import child_process from 'node:child_process';
8
+ const exec = util.promisify(child_process.exec);
9
+
10
+ let pipewireData = null;
11
+ async function pipewireRelink() {
12
+
13
+ try {
14
+ const { stdout, stderr } = await exec('pw-dump');
15
+ // console.log('pw-dump stdout:', stdout);
16
+ if(stderr) {
17
+ console.warn('pw-dump stderr:', stderr);
18
+ }
19
+
20
+ pipewireData = JSON.parse(stdout);
21
+
22
+ } catch (error) {
23
+ console.error('Error with pw-dump:', error.message, error);
24
+ process.exit(1);
25
+ }
26
+ const playbackNodes = pipewireData.filter( (e) => {
27
+ return e.type === "PipeWire:Interface:Node"
28
+ && e.info
29
+ && e.info.props
30
+ && typeof e.info.props['client.id'] !== 'undefined'
31
+ && e.info.props['media.type'] === 'Audio'
32
+ });
33
+
34
+ if (playbackNodes.length === 0) {
35
+ // console.warn('pipewireRelink: no playback node');
36
+ // no error
37
+ process.exit(0);
38
+ }
39
+
40
+ const outputNodes = pipewireData.filter( (e) => {
41
+ return e.type === "PipeWire:Interface:Node"
42
+ && e.info
43
+ // && e.info['max-input-ports'] > 1
44
+ && e.info.props
45
+ && e.info.props['media.class'] === 'Audio/Sink';
46
+ });
47
+
48
+ if (outputNodes.length === 0) {
49
+ console.warn('pipewireRelink: no output node');
50
+ // no error
51
+ process.exit(0);
52
+ }
53
+ else if (outputNodes.length > 1) {
54
+ console.warn('pipewireRelink: multiple output nodes');
55
+ }
56
+
57
+ for(let p = 0; p < playbackNodes.length; ++p) {
58
+ for(let o = 0; o < outputNodes.length; ++o) {
59
+ const playbackIndex = playbackNodes[p].id;
60
+ const outputIndex = outputNodes[o].id;
61
+ const commandString = `pw-link ${playbackIndex} ${outputIndex}`;
62
+ try {
63
+ // console.log(commandString);
64
+ const {stdout, stderr} = await exec(commandString);
65
+ // console.log('pw-link stdout:', stdout);
66
+ if(stderr) {
67
+ console.warn('pw-link stderr:', stderr);
68
+ }
69
+ } catch(error) {
70
+ // error when linking nodes instead of ports: ignore
71
+ // console.error( `Error with ${commandString}:`, error.message, error);
72
+ continue;
73
+ }
74
+ }
75
+ }
76
+
77
+ process.exit(0);
78
+
79
+ }
80
+
81
+ pipewireRelink();
82
+
83
+
84
+
85
+
86
+
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+
3
+ # drop sudo privileges
4
+ if [[ "$USER" == "root" ]]; then
5
+ if [[ -n "$SUDO_USER" ]] ; then
6
+ user="$SUDO_USER"
7
+ else
8
+ FIRSTUSER="$(getent passwd 1000 | cut -d: -f1)"
9
+ user="${FIRSTUSER:-pi}"
10
+ fi
11
+ sudo -u "${user}" "$0" "$@"
12
+ fi
13
+
14
+ local_file="$(dotpi readlink_follow "$0")"
15
+ local_path="$(dirname -- "$local_file")"
16
+
17
+ sudo dotpi service_install --user "${local_path}/systemd/dotpi_pipewire.service"
18
+
19
+ source_path="${local_path}/bin"
20
+ destination_path="${DOTPI_ROOT}/bin"
21
+ sudo mkdir -p -- "$destination_path"
22
+ for executable in "${source_path}/"* ; do
23
+ sudo ln -s -f -- "$executable" "${destination_path}/$(basename -- "$executable")"
24
+ done
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@dotpi/pipewire",
3
+ "description": "Monitor Pipewire to dynamically relink playback nodes to output nodes",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "postinstall": "dotpi_install"
8
+ }
9
+ }
@@ -0,0 +1,22 @@
1
+ [Unit]
2
+ Description=dotpi pipewire audio daemon
3
+ Requires=pipewire.service
4
+ After=pipewire.service
5
+
6
+ # TODO: stop on system stop
7
+
8
+ [Service]
9
+ Type=exec
10
+
11
+ ExecStart=/opt/dotpi/share/dotpi_pipewire/systemd/dotpi_pipewire_command
12
+
13
+ Restart=always
14
+
15
+ # wait before restarting
16
+ RestartSec=10s
17
+
18
+ # Do not stop to try restarting service
19
+ StartLimitBurst=0
20
+
21
+ [Install]
22
+ WantedBy=pipewire.service
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ if [[ "$USER" == "root" ]] ; then
4
+ dotpi echo_error "This script MUST NOT be executed by root (or via sudo)"
5
+ exit 1
6
+ fi
7
+
8
+ local_file="$(dotpi readlink_follow "$0")"
9
+ local_path="$(dirname -- "$local_file")"
10
+
11
+ (( trial_count_max = 10 ))
12
+ while true ; do
13
+ if systemctl --user is-active "pipewire" > /dev/null 2>&1 ; then
14
+ (
15
+ (( trial_count = 0 ))
16
+ while (( trial_count < trial_count_max )) ; do
17
+ "${local_path}/../bin/dotpi_pipewire_relink" && exit 0
18
+ sleep 3
19
+ (( ++trial_count ))
20
+ done
21
+ dotpi echo_error "Failed to relink pipewire outputs ${trial_count_max} times."
22
+ dotpi echo_warning "Rebooting system."
23
+ sudo reboot
24
+ )
25
+ fi
26
+ sleep 10
27
+ done
28
+
29
+
@@ -1,11 +1,7 @@
1
- # Provided by the jackd package.
2
- #
3
1
  # Changes to this file will be preserved.
4
2
  #
5
- # If you want to enable/disable realtime permissions, run
6
- #
7
- # dpkg-reconfigure -p high jackd2
3
+ # (Settings taken from jackd package)
8
4
 
9
5
  @audio - rtprio 95
10
6
  @audio - memlock unlimited
11
- #@audio - nice -19
7
+ # @audio - nice -19
@@ -0,0 +1,8 @@
1
+ # WIP: no tested with wireplumber >= 0.4.0
2
+
3
+ # do not start and stop bluez with login: always run
4
+ wireplumber.profiles = {
5
+ main = {
6
+ monitor.bluez.seat-monitoring = disabled
7
+ }
8
+ }
package/lerna.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "node_modules/lerna/schemas/lerna-schema.json",
3
+ "version": "independent"
4
+ }