@dotpi/tools 1.0.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 (57) hide show
  1. package/DOC.md +66 -0
  2. package/LICENSE +28 -0
  3. package/NOTES.md +81 -0
  4. package/README.md +341 -0
  5. package/dotpi-tools.js +35 -0
  6. package/dotpi_root/bin/dotpi +66 -0
  7. package/dotpi_root/bin/dotpi_firstrun +193 -0
  8. package/dotpi_root/bin/dotpi_prepare_sd_card +616 -0
  9. package/dotpi_root/bin/dotpi_prepare_system +244 -0
  10. package/dotpi_root/etc/dotpi_environment_default.bash +69 -0
  11. package/dotpi_root/etc/dotpi_tarignore +3 -0
  12. package/dotpi_root/share/dotpi-install/update_to_v1.0.0_manager +39 -0
  13. package/dotpi_root/share/dotpi-install/update_to_v1.0.0_pi +39 -0
  14. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth.service +23 -0
  15. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth_command +134 -0
  16. package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +132 -0
  17. package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor.service +22 -0
  18. package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor_command +14 -0
  19. package/dotpi_root/share/dotpi_environment.bash +5 -0
  20. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_bluetooth.bash +346 -0
  21. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +504 -0
  22. package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +435 -0
  23. package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +199 -0
  24. package/dotpi_root/share/dotpi_functions/dotpi_functions_dotpi.bash +36 -0
  25. package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +111 -0
  26. package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +175 -0
  27. package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +154 -0
  28. package/dotpi_root/share/dotpi_functions.bash +14 -0
  29. package/dotpi_root/share/dotpi_init.bash +18 -0
  30. package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +18 -0
  31. package/dotpi_root/share/jackd/dotpi_jackd_command +26 -0
  32. package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +21 -0
  33. package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +17 -0
  34. package/dotpi_root/share/jackd/jackd.service +22 -0
  35. package/dotpi_root/share/limits/zzz_dotpi_audio.conf +11 -0
  36. package/dotpi_root/share/wireplumber/bluetooth.lua.d/8zzz-dotpi-wireplumber-config.lua +4 -0
  37. package/examples/example-development/configuration/dotpi_project.bash +40 -0
  38. package/examples/example-headphones/configuration/dotpi_project.bash +18 -0
  39. package/examples/example-hifiberry/configuration/dotpi_instance_012.bash +4 -0
  40. package/examples/example-hifiberry/configuration/dotpi_project.bash +18 -0
  41. package/examples/example-network/configuration/dotpi_project.bash +21 -0
  42. package/package.json +35 -0
  43. package/src/configure-host.js +187 -0
  44. package/src/constants.js +30 -0
  45. package/src/create-project.js +438 -0
  46. package/src/install-rpi.js +173 -0
  47. package/src/templates/README.md +16 -0
  48. package/src/templates/ap.nmconnection +25 -0
  49. package/src/templates/dotpi_project.bash +31 -0
  50. package/src/templates/dotpi_secrets.bash +4 -0
  51. package/src/templates/infrastructure.nmconnection +29 -0
  52. package/src/templates/ssh_config +6 -0
  53. package/src/utils.js +175 -0
  54. package/test/constants.spec.js +37 -0
  55. package/test/create-project.test.js +57 -0
  56. package/test/install-rpi.test.js +8 -0
  57. package/test/utils.spec.js +48 -0
package/DOC.md ADDED
@@ -0,0 +1,66 @@
1
+ DOC.md
2
+
3
+ ## Bluetooth [private]
4
+
5
+ _do not document for now_
6
+
7
+ dotpi audio_bluetooth_destination_connect
8
+ > connect to bluetooth speaker given a MAC address defined in the $dotpi_audio_bluetooth_mac variable
9
+
10
+
11
+ dotpi_audio_bluetooth_destination_start
12
+ > turn on speaker
13
+
14
+ dotpi_audio_bluetooth_destination_volume_set $1
15
+ > set volume and save
16
+
17
+ dotpi_audio_bluetooth_destination_volume_init
18
+ > back to default volume
19
+
20
+ .cf dotpi_audio_bluetooth_command for an example
21
+
22
+ ## dotpi_functions_dotpi
23
+
24
+ [sudo] dotpi_dotpi_update
25
+ > Update all the `dotpi` sub system
26
+
27
+ ## dotpi_functions_system
28
+
29
+ dotpi_system_is_raspberry_pi
30
+ > return if raspberry pi
31
+
32
+ [sudo] dotpi_system_set_hostname $1
33
+ > change the hostname of the RPi
34
+ > $1 - new hostname
35
+
36
+ [sudo] dotpi_system_execute_on_reboot $1 $2
37
+ > Execute file on next reboot
38
+ > $1 - user
39
+ > $2 - path to file
40
+
41
+ [sudo] dotpi_system_update
42
+ > alias apt-get update and dist upgrade
43
+
44
+ ## dotpi_functions_service
45
+
46
+ [sudo] dotpi_service_install $1
47
+ > $1 service file
48
+
49
+ [sudo] dotpi_service_uninstall $1
50
+ > $1 service name
51
+
52
+ ## dotpi_functions_connection [private]
53
+
54
+ > manipulate network config files
55
+
56
+ ## dotpi_functions_configuration [private]
57
+
58
+ > manipulate config files
59
+
60
+ ## dotpi_functions_audio_device
61
+
62
+ [sudo] dotpi_audio_device_select --model <model>
63
+ > select the soundcard
64
+
65
+ [sudo] dotpi_audio_device_volume_set
66
+ [sudo] dotpi_audio_device_volume_init
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2023-present IRCAM – Centre Pompidou (France, Paris)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice, this
12
+ list of conditions and the following disclaimer in the documentation and/or
13
+ other materials provided with the distribution.
14
+
15
+ * Neither the name of the IRCAM nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/NOTES.md ADDED
@@ -0,0 +1,81 @@
1
+ # Notes
2
+
3
+ ## TODOS
4
+
5
+ ### Fix
6
+
7
+ - [x] `--install-rpi` do not work when inside a project
8
+ - [x] modify message to eject SD card when on Windows
9
+
10
+ ### General
11
+
12
+ - [ ] Documentation when each of the following step is clean
13
+ - [ ] Create test scenarios
14
+ - provide mocks to prompts & compare output with predefined results
15
+ - [ ] Best effort for Linux and Windows, even if it's just a message w/ a link to ouside source
16
+
17
+ ### Features
18
+
19
+ - [x] parse path of ssh key (~/.ssh/ ${HOME}/.ssh)
20
+ - [ ] check platform for all commands and warn if not macOS
21
+ - [ ] test projects created with `createProject`
22
+ + review `configureSSH` keys to handle other platforms when generating keys
23
+ - [ ] remove `/jackd` stuff in `dotpi_prepare_sd_card`
24
+ - [x] implement and test `prepareRpi`
25
+ - just wrap `dotpi_prepare_system`, see SSH feedback by default
26
+ - [x] first pass on re-organizing files and folder (only on js side)
27
+ + [x] move all file templates into their own file for easier maintenance
28
+ - [x] check we have a MVP w/ JIP and converge to final structure
29
+ + [x] see what it means to have `projects` living in it own user-defined location
30
+ - [x] implement and test `configureHost` script
31
+ + for adding SSH keys, just point to gihub doc if not on MacOS for now
32
+ Linux should be rather straightforward,
33
+ - [x] rename to `@dotpi/tools` rather than `@dotpi/install`
34
+ - [x] make it work using `npx`
35
+
36
+ ## Questions
37
+
38
+ - [ ] add a level of indirection in config files?
39
+ + datas stored in yml or something, would help maintainance?
40
+ - [ ] system to check for new version
41
+ + `npm view @soundworks/core version`
42
+
43
+
44
+ ## Final File Structure
45
+
46
+ ```sh
47
+ # (-> `dotpi_root`), cf. move toward .deb package?
48
+ # cf https://www.iodigital.com/en/history/intracto/creating-debianubuntu-deb-packages
49
+ # maybe overkill for us... https://unix.stackexchange.com/a/620698
50
+ pkg
51
+ src
52
+ lib
53
+
54
+ wizard.js # one single js bin so that we can execute the command from npx, cf. above
55
+ docs # -> or use another dedicated repo `ircam-ismm/dotpi`
56
+ README.md
57
+ LICENSE
58
+ package.json
59
+ ```
60
+
61
+ ## Example Use
62
+
63
+ ```sh
64
+ # npm install -g @dotpi/tools
65
+
66
+ # my-dotpi-projects is just a reglar directory
67
+ cd ../my-dotpi-projects
68
+
69
+ # # cf. https://stackoverflow.com/a/58649605
70
+ # npx @dotpi/tools --create-project
71
+ # npx @dotpi/tools --configure-host
72
+ # npx @dotpi/tools --install-rpi
73
+ # npx @dotpi/tools --launch-manager
74
+
75
+
76
+
77
+ npx dotpi-tools --create-project
78
+ npx dotpi-tools --configure-host
79
+ npx dotpi-tools --install-rpi
80
+ npx dotpi-tools --launch-manager
81
+ ```
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ # dotpi-install
2
+
3
+ ## Intro
4
+
5
+ This utility prepares a Raspberry Pi for running in a `dotpi` distributed system. It serves several purposes:
6
+
7
+ - locally configure a project
8
+ - run locally to prepare the SD card
9
+ - run on Raspberry Pi to prepare the remote system
10
+ - add utilities and services to the remote system
11
+
12
+ ## Getting started
13
+
14
+ In the `project` folder, select a project that is close to your needs: `example-dev` is quite complete.
15
+
16
+ Do not forget to install the pair SSH keys from `projects/example-dev/secrets/ssh` to local you `${HOME}/.ssh` configuration.
17
+
18
+ - Download and install the Raspberry Pi Imager.
19
+ - Select OS (operating system)
20
+ - Choose `Rapsberry Pi OS (other)`
21
+ - Choose `Rapsberry Pi OS Lite (64-bit)`
22
+ - For Raspberry Pi 3, you may need to select `No filtering` or separately download a non-legacy OS, and choose `Use custom`.
23
+ - Insert a new SD card in your computer
24
+ - Select it as the storage
25
+
26
+ - You may change somme settings. In particular, you can choose *not* to eject media when done, to avoid pulling the SD card out, then inserting it again.
27
+ - Write the SD card
28
+ - You you choose to apply the settings, these will be the defaults before applying the `dotpi` settings
29
+
30
+ In a terminal:
31
+
32
+ ```sh
33
+ # change path to the dotpi-install folder
34
+ cd ~/src/dotpi-install
35
+
36
+ # prepare the SD car with the chosen project
37
+ ./dotpi_root/bin/dotpi_prepare_sd_card --project ./projects/example-dev
38
+ ```
39
+
40
+ Type the instance number, or accept the default. The first instance will be `1`
41
+
42
+ - Put the SD card into a Raspberry
43
+ - Power it on
44
+ - Connect it to the internet, and to you computer
45
+
46
+ You may then copy the last line to get info of the remote process.
47
+
48
+ Any SSH operation will wait until the network on the Raspberry Pi is ready.
49
+
50
+ ```sh
51
+ # This will monitor the first instance of the `dev` project
52
+ ssh pi@dotpi-dev-001.local 'tail -f /opt/dotpi/var/log/dotpi_prepare_system_*.log'
53
+ ```
54
+
55
+ When done, you can connect.
56
+
57
+ ```sh
58
+ ssh pi@dotpi-dev-001.local
59
+ ```
60
+
61
+ It should also appear in the `dotpi-manager`.
62
+
63
+ ## Settings
64
+
65
+ ### Raspberry Pi Imager
66
+
67
+ The installer will first apply the settings of the Raspberry Pi Imager.
68
+
69
+ In particular:
70
+
71
+ - host-name
72
+
73
+ - ssh access
74
+ - you can allow for password authentication (in case the authentication via key fails)
75
+
76
+ - user and password
77
+ - user name: not recommended to change
78
+ - user password, when ssh is not available
79
+
80
+ - the wifi settings will be over-ridden
81
+
82
+ - you can avoid the eject the SD car when done
83
+
84
+ ### Environment defaults
85
+
86
+ Then, `dotpi-install` will apply the default settings of the `dotpi` environment.
87
+
88
+ `dotpi_root/etc/dotpi_environment_default.bash`
89
+
90
+ You should not change anything here. Instead, you can over-ride any value in your projects.
91
+
92
+ ### Project settings
93
+
94
+ Then, `dotpi-install` will apply the default settings of your project.
95
+
96
+ #### `configuration` folder
97
+
98
+ This folder is for "public" settings, that you would share on a repository.
99
+
100
+ In you project, there is a configuration file named `configuration/dotpi_project.bash`, where you can override any value.
101
+
102
+ Note that you can also extend settings, by appendind to bash arrays:
103
+
104
+ ```sh
105
+ # this add `screen` to the list of packages to install
106
+ dotpi_apt_install+=(
107
+ screen
108
+ )
109
+ ```
110
+ In particular, you can change the name of your project. (The default is the folder name.)
111
+
112
+ ```sh
113
+ dotpi_project_name='dev'
114
+ ```
115
+
116
+ The remote machine hosnames will be on the form `dotpi-dev-xxx` with `xxx` as the instance numbers.
117
+
118
+
119
+ You can also choose your audio device.
120
+
121
+ ```sh
122
+ dotpi_audio_device='HiFiBerry DAC+ ADC Pro'
123
+ ```
124
+
125
+ ##### `jackd` folder
126
+
127
+ You can add a `jackd` folder in you `<project>/configuration` folder, in order to over-ride jackd settings from `dotpi-root/share/jackd`.
128
+
129
+ Note that there is a symbolic link to configuration for known sound-cads. If it does not suit your needs, you can use a `dotpi_jackd.bash` configuration file.
130
+
131
+ ```bash
132
+ # keep this
133
+ DOTPI_JACKD_ENVIRONMENT=(
134
+ JACK_NO_AUDIO_RESERVATION=1
135
+ )
136
+
137
+ # warning: long option for -d (--driver) seems broken
138
+
139
+ DOTPI_JACKD_ARGUMENTS=(
140
+ --realtime
141
+ --realtime-priority 95
142
+ -d alsa
143
+ --device hw:0
144
+ --playback
145
+ --period 1024
146
+ --nperiods 2
147
+ --rate 48000
148
+ )
149
+ ```
150
+
151
+ #### `secrets` folder
152
+
153
+ This folder is for "private" settings, that you would *not* share on a repository.
154
+
155
+ In you project, there is a configuration file named `secrets/dotpi_secrets.bash`, where you can chage the password.
156
+
157
+ ```sh
158
+ dotpi_password='!rapsberry'
159
+ ```
160
+
161
+ ##### `network` folder
162
+
163
+ You can add any NetworkManager configuration file. Be sure *not* to quote values, including `ssid` and `psk`, as anything is part of the value, including quotes.
164
+
165
+ To keep the automatic configuration for the ethernet interface, do not add it here.
166
+
167
+ To keep `NetworkManager` functional, do *not* configure network in an other way (ie. no `wpa_supplicant.conf` file).
168
+
169
+ ##### `ssh` folder
170
+
171
+ Be sure to install the pair of SSH keys in you `${HOME}/.ssh` configuration.
172
+
173
+ ### Instance settings, `tmp` folder
174
+
175
+ The last step is to apply particular settings relative to the instance.
176
+
177
+ After sucessfully preparing an SD card, a copy of the last settings will be in your pject, in a `tmp` folder.
178
+
179
+ - `dotpi_prepare_sd_card_*.log` is a copy of the screen messages
180
+ - `dotpi_tmp.bash` contains the instance number (to increment for the next time)
181
+ - `file-system` is a full copy of what will be installed on the Raspberry Pi.
182
+
183
+ ## On the Raspberry Pi
184
+
185
+ Any system-wide installation will link to the `/opt/dotpi` directory. Except the following.
186
+
187
+ The `/boot/firmware` folder (mounted as `/bootfs` as a local SD card) contains the `config.txt` file.
188
+
189
+
190
+ ### Commands
191
+
192
+ Use `dotpi` or `sudo dotpi` to run any `dotpi_function` function.
193
+
194
+ ### `/boot/firmware` `/bootfs`
195
+
196
+ - `config.txt` is the hardware configuration file.
197
+ - `firstrun_*.log` is the log the the first run
198
+ - Intentionnaly, the network does not start at this stage
199
+ - the `dotpi` folder contains the initial version of the `dotpi` file-system, and a non-customised version of the `firstrun.sh` script from the imager.
200
+
201
+ ### `/opt/dotpi`
202
+
203
+ `/opt/dotpi/bin/dotpi` is the main executable, installed in `/usr/bin`
204
+
205
+ #### `/opt/dotpi/etc`
206
+
207
+ - `config.txt` is an *initial* copy of the hardware configuration. It may diverge after any mofdification.
208
+ - `dotpi_environment_*.bash` contain the customisation of the environment
209
+ - `network` contains the network configuration, that where copied to `/etc/NetworkManager/system-connections`. It may diverge after any mofdification.
210
+ - `ssh` contains the public SSH keys that were copied to `${HOME}/.ssh/authorized_keys`
211
+
212
+ #### `/opt/dotpi/share`
213
+
214
+ - `dotpi-manager` contains the client and the service. Use `sudo dotpi manager_update` to update the client.
215
+ - `jackd` contains the configuration and the service.
216
+ - `limits` contains the limits that were copied to `/etc/security/limits.d`.
217
+ - `n` contains the node version manager. `node.js` itself, is in `/home/pi/n/bin/node` and linked in `/usr/bin/node`.
218
+
219
+ #### `/opt/dotpi/var/log`
220
+
221
+ Log files.
222
+
223
+ - `dotpi_prepare_system_*.log` contains the log of the system preparation
224
+ - `dotpi_manager_update_*.log` contain the logs of the dotpi-manager updates
225
+
226
+ #### `/usr/local/bin`
227
+
228
+ This is an alias to `/usr/bin`.
229
+
230
+ ### Other
231
+
232
+ #### Local machine
233
+
234
+ If you install `wpa_passphrase`, wifi passwords will be hashed.
235
+
236
+ You should install the version 3 of `rsync` to get quicker transfer times with `dotpi-manager`.
237
+
238
+ ```sh
239
+ rsync --version | grep version
240
+ ```
241
+
242
+ #### Remote Raspberry Pi
243
+
244
+
245
+ ##### Network
246
+
247
+ Everything is managed via `NetworkManager`. You can use `nmtui` to use a user-interface.
248
+
249
+ You also directly use `nmcli` with a command-line interface.
250
+
251
+ ```sh
252
+ nmcli device
253
+ # DEVICE TYPE STATE CONNECTION
254
+ # eth0 ethernet connected Wired connection 1
255
+ # lo loopback connected (externally) lo
256
+ # wlan0 wifi disconnected --
257
+ # p2p-dev-wlan0 wifi-p2p disconnected --
258
+
259
+ nmcli radio
260
+ # WIFI-HW WIFI WWAN-HW WWAN
261
+ # enabled enabled missing enabled
262
+ ```
263
+
264
+
265
+ ##### `jackd`
266
+
267
+ In order to play soundfiles via `jackd`, you can install `mpv`
268
+
269
+ ```sh
270
+ mpv --ao=jack 'sound.mp3'
271
+ ```
272
+
273
+ You can monitor a jack connection in a terminal with. Warning, you need to install the `jackmeter` package but the command is `jack_meter`.
274
+
275
+ ```sh
276
+ # list jack connections
277
+ jack_lsp
278
+ # system:capture_1
279
+ # system:capture_2
280
+ # system:playback_1
281
+ # system:playback_2
282
+ # cpal_client_out:out_0
283
+ # cpal_client_out:out_1
284
+ # cpal_client_out-01:out_0
285
+ # cpal_client_out-01:out_1
286
+
287
+ # monitor the system output
288
+ jack_meter system:playback_1
289
+
290
+ # monitor a particular connection
291
+ jack_meter mpv:out_0
292
+ ```
293
+
294
+ ##### Raspberry pi
295
+
296
+ You can get various information about the hardware and software.
297
+
298
+ ```sh
299
+ cat /proc/device-tree/model
300
+ # Raspberry Pi 4 Model B Rev 1.4pi
301
+
302
+ # 64bit kernel (even for 32bit system)
303
+ uname -a
304
+ # Linux dotpi-dev-019 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
305
+
306
+ # 64bit kernel (even for 32bit system)
307
+ arch
308
+ # aarch64
309
+
310
+ # 32bit system
311
+ file $(which file)
312
+ # /usr/bin/file: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=f5f7f7c84dbb609f53ae3b9ac6b4437d927bde7d, for GNU/Linux 3.2.0, stripped
313
+ ```
314
+
315
+ ## Known bugs
316
+
317
+ Please do report them.
318
+
319
+ - [ ] do not allow `.` character in project, it generates an invalid hostname.
320
+
321
+ ## Todo
322
+
323
+ - [x] option not to install dotpi-manager
324
+
325
+ - [ ] allow to use configuration files from project
326
+ - [ ] jack
327
+ - [ ] dotpi-led
328
+
329
+ - [ ] dotpi-manager: dependency to jackd should be soft
330
+ - [ ] allow client to run without audio
331
+ - [ ] client should continue to run if audio stops
332
+
333
+ - [ ] Make a command-line interface
334
+ - [ ] choose between options
335
+ - [ ] project name
336
+ - [ ] audio device model
337
+ - [ ] jackd configuration
338
+ - [ ] make pair of ssh keys
339
+ - [ ] wifi/network configuration
340
+
341
+ - [ ] share dotpi_manager_update w/ install
package/dotpi-tools.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import chalk from 'chalk';
4
+
5
+ import { greetings } from './src/utils.js';
6
+ import createProject from './src/create-project.js';
7
+ import installRpi from './src/install-rpi.js';
8
+ import configureHost from './src/configure-host.js';
9
+
10
+ program
11
+ .option('--create-project')
12
+ .option('--install-rpi')
13
+ .option('--configure-host')
14
+ // .option('--launch-manager');
15
+
16
+ program.parse();
17
+
18
+ const options = program.opts();
19
+
20
+ greetings();
21
+
22
+ if (options.createProject) {
23
+ await createProject();
24
+ } else if (options.installRpi) {
25
+ await installRpi();
26
+ } else if (options.configureHost) {
27
+ await configureHost();
28
+ } else if (options.launchManager) {
29
+ console.log(chalk.yellow('> launchManager is not implemented yet'));
30
+ } else {
31
+ // @todo prompt
32
+ console.log(chalk.yellow('> Invalid option:'));
33
+ console.log(options);
34
+ }
35
+
@@ -0,0 +1,66 @@
1
+ #!/bin/bash
2
+
3
+ # Busy-box like wrapper
4
+
5
+ # Main usage is for sudo, to source ${DOTPI_ROOT}/share/dotpi_init.bash before the command
6
+
7
+ # installation with a link in the path
8
+
9
+ # sudo dotpi echo_info "dotpi root is ${DOTPI_ROOT}"
10
+
11
+
12
+ # `readlink -f` is not available for MacOS
13
+ # https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
14
+ dotpi_readlink_follow() (
15
+ target_file="$1"
16
+
17
+ cd -- "$(dirname -- "$target_file")" || {
18
+ echo ''
19
+ return 1
20
+ }
21
+ target_file="$(basename -- "$target_file")"
22
+
23
+ # Iterate down a (possible) chain of symlinks
24
+ while [[ -L "$target_file" ]] ; do
25
+ target_file="$(readlink -- "$target_file")"
26
+ cd -- "$(dirname -- "$target_file")" || {
27
+ echo ''
28
+ return 1
29
+ }
30
+ target_file="$(basename -- "$target_file")"
31
+ done
32
+
33
+ # Compute the canonicalized name by finding the physical path
34
+ # for the directory we're in and appending the target file.
35
+ target_path="$(pwd -P)"
36
+ result="${target_path}/${target_file}"
37
+ echo "$result"
38
+ )
39
+
40
+ local_file="$(dotpi_readlink_follow "$0")"
41
+ local_path="$(dirname -- "$local_file")"
42
+ local_root="$(cd -- "${local_path}/.." && pwd -P)"
43
+
44
+ DOTPI_ROOT="${DOTPI_ROOT:-${local_root}}"
45
+
46
+ source "${DOTPI_ROOT}/share/dotpi_init.bash"
47
+
48
+ self_command="$(basename -- "$0")"
49
+ self_usage() {
50
+ echo "Usage: ${self_command} <command> [ <arguments> ]"
51
+ }
52
+
53
+ # allow for '_' of '-' in sub-commands
54
+ # sudo dotpi system_set_hostname dotpi-dev-123
55
+ # sudo dotpi system-set-hostname dotpi-dev-123
56
+
57
+ sub_command="${1//-/_}"
58
+
59
+ if [[ -z "$sub_command" ]] ; then
60
+ dotpi_echo_error "Missing command as first argument"
61
+ self_usage
62
+ exit 1
63
+ fi
64
+
65
+
66
+ "dotpi_${sub_command}" "${@:2}"