@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
@@ -0,0 +1,438 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { tmpdir } from 'node:os';
4
+ import { execSync } from 'node:child_process';
5
+
6
+ import prompts from 'prompts';
7
+ import chalk from 'chalk';
8
+
9
+ import {
10
+ title,
11
+ renderTemplate,
12
+ readBashArray,
13
+ readBashVariable,
14
+ processPath,
15
+ confirm,
16
+ onCancel,
17
+ packageVersion,
18
+ isPrivateSshKey,
19
+ isDotpiProject,
20
+ } from './utils.js';
21
+ import {
22
+ // path of the files inside the final project
23
+ PATH_DOTPI_PROJECT_BASH,
24
+ PATH_DOTPI_SECRETS_BASH,
25
+ PATH_SSH_DIRECTORY,
26
+ PATH_NETWORK_DIRECTORY,
27
+ PATH_GITIGNORE,
28
+ PATH_README,
29
+ PATH_DOTPI_FILE,
30
+ // utilities
31
+ DOTPI_SSH_KEYS_PREFIX,
32
+ PROJECT_NAME_REGEXP,
33
+ WIFI_ID_REGEXP,
34
+ // this must be put in gitignore
35
+ PATH_DOTPI_TMP_DIRECTORY,
36
+ // where the command is executed
37
+ CWD,
38
+ } from './constants.js';
39
+ import configureHost from './configure-host.js';
40
+
41
+ export async function prepareProject(data = {}, mocks = null) {
42
+ title(`Prepare dotpi project`);
43
+
44
+ if (mocks) {
45
+ prompts.inject(Object.values(mocks));
46
+ }
47
+
48
+ const { projectName, password } = await prompts([
49
+ {
50
+ type: 'text',
51
+ name: 'projectName',
52
+ message: 'Name of your dotpi project:',
53
+ validate: value => {
54
+ const projectPath = path.join(CWD, value);
55
+
56
+ if (!PROJECT_NAME_REGEXP.test(value)) {
57
+ return 'Please provide a valid project name. A valid project name must contain only lower case letters, digits, - and _';
58
+ } else if (fs.existsSync(projectPath) && fs.statSync(projectPath).isDirectory()) {
59
+ return `A project named "${value}" already exists`;
60
+ }
61
+
62
+ return true;
63
+ },
64
+ }, {
65
+ type: 'text',
66
+ name: 'password',
67
+ message: 'Define a password for your dotpi / raspberry pi modules:',
68
+ validate: input => input.length < 6 ? 'Minimum length of 6 characters' : true,
69
+ },
70
+ ], { onCancel });
71
+
72
+ data.projectName = projectName;
73
+ data.files[PATH_DOTPI_SECRETS_BASH] = renderTemplate('dotpi_secrets.bash', { password });
74
+
75
+ return data;
76
+ }
77
+
78
+ /**
79
+ * @todo could be used to configure a specific dotpi instance too
80
+ */
81
+ export async function configureProject(data, mocks = null) {
82
+ title(`Configure system`);
83
+
84
+ if (mocks) {
85
+ prompts.inject(Object.values(mocks));
86
+ }
87
+
88
+ const { projectName } = data;
89
+ const version = packageVersion();
90
+
91
+ const answers = await prompts([
92
+ {
93
+ type: 'select',
94
+ name: 'soundCard',
95
+ message: 'Choose your soundcard:',
96
+ choices: readBashArray('dotpi_audio_device_supported').map(s => ({ title: s, value: s })),
97
+ },
98
+ {
99
+ type: 'text',
100
+ name: 'nodeVersion',
101
+ message: 'Node.js version:',
102
+ initial: 'lts',
103
+ format: val => val.trim(),
104
+ },
105
+ {
106
+ type: 'text',
107
+ name: 'timeZone',
108
+ message: 'Time zone:',
109
+ initial: 'Europe/Paris',
110
+ format: val => val.trim(),
111
+ },
112
+ {
113
+ type: 'text',
114
+ name: 'wifiCountryCode',
115
+ message: 'WiFi country code:',
116
+ initial: 'FR',
117
+ format: val => val.trim(),
118
+ },
119
+ {
120
+ type: 'text',
121
+ name: 'keyMap',
122
+ message: 'Key map:',
123
+ initial: 'fr',
124
+ format: val => val.trim(),
125
+ },
126
+ {
127
+ type: 'toggle',
128
+ name: 'installDotpiManager',
129
+ message: 'Install the dotpi-manager module?',
130
+ initial: true,
131
+ active: 'yes',
132
+ inactive: 'no'
133
+ },
134
+ {
135
+ type: 'toggle',
136
+ name: 'installDotpiLed',
137
+ message: 'Install the dotpi-led module?',
138
+ initial: false,
139
+ active: 'yes',
140
+ inactive: 'no'
141
+ },
142
+ {
143
+ type: prev => prev === true ? 'text' : false,
144
+ name: 'dotpiLedConfigFile',
145
+ message: 'Choose the dotpi-led configuration file:',
146
+ initial: './configuration/default.json',
147
+ format: val => val.trim(),
148
+ },
149
+ ], { onCancel });
150
+
151
+ data.files[PATH_DOTPI_PROJECT_BASH] = renderTemplate('dotpi_project.bash', {
152
+ projectName,
153
+ version,
154
+ ...answers,
155
+ });
156
+
157
+ // @todo - Configure a specific instance
158
+
159
+ return data;
160
+ }
161
+
162
+ export async function configureSSH(data, mocks = null) {
163
+ title(`Configure SSH keys`);
164
+
165
+ if (mocks) {
166
+ prompts.inject([mocks.createOrResuse]);
167
+ }
168
+
169
+ const { createOrReuse } = await prompts({
170
+ type: 'select',
171
+ name: 'createOrReuse',
172
+ message: 'Do you want to:',
173
+ choices: [
174
+ { title: 'Create new SSH keys (recommended)', value: 'create' },
175
+ { title: 'Use existing SSH keys', value: 'reuse' },
176
+ ],
177
+ initial: 0,
178
+ }, { onCancel });
179
+
180
+ const { projectName } = data;
181
+ const hostnamePrefix = readBashVariable('dotpi_hostname_prefix');
182
+
183
+ let keyBasename = null;
184
+
185
+ switch (createOrReuse) {
186
+ case 'create': {
187
+ // create tmp dir and generate some SHH key pair
188
+ keyBasename = `${DOTPI_SSH_KEYS_PREFIX}_${hostnamePrefix}_${projectName}`;
189
+ const tmp = fs.mkdtempSync(path.join(tmpdir(), `${projectName}-`));
190
+ const generatedPrivateKeyPath = path.join(tmp, keyBasename);
191
+ execSync(`ssh-keygen -f ${generatedPrivateKeyPath} -t rsa -b 4096 -q -N ""`);
192
+
193
+ // retreive generated keys and store in data
194
+ const privateKeyPath = path.join(PATH_SSH_DIRECTORY, keyBasename);
195
+ const privateKey = fs.readFileSync(generatedPrivateKeyPath).toString();
196
+ data.files[privateKeyPath] = privateKey;
197
+
198
+ const generatedPublicKeyPath = `${generatedPrivateKeyPath}.pub`;
199
+ const publicKeyPath = path.join(PATH_SSH_DIRECTORY, `${keyBasename}.pub`);
200
+ const publicKey = fs.readFileSync(generatedPublicKeyPath).toString();
201
+ data.files[publicKeyPath] = publicKey;
202
+
203
+ // delete tmp dir
204
+ fs.rmSync(tmp, { recursive: true, force: true });
205
+ break;
206
+ }
207
+ case 'reuse': {
208
+ const { originalPrivateKeyPath } = await prompts({
209
+ type: 'text',
210
+ name: 'originalPrivateKeyPath',
211
+ message: 'Path to the private key:',
212
+ validate: val => {
213
+ return isPrivateSshKey(processPath(val))
214
+ ? true
215
+ : `Given file is not a valid SHH private key`;
216
+ },
217
+ format: val => processPath(val),
218
+ }, { onCancel });
219
+
220
+ const privateKey = fs.readFileSync(originalPrivateKeyPath).toString();
221
+ const privateKeyPath = path.join(PATH_SSH_DIRECTORY, path.basename(originalPrivateKeyPath));
222
+ data.files[privateKeyPath] = privateKey;
223
+
224
+ const originalPublicKeyPath = `${originalPrivateKeyPath}.pub`;
225
+ const publicKey = fs.readFileSync(originalPublicKeyPath).toString();
226
+ const publicKeyPath = path.join(PATH_SSH_DIRECTORY, path.basename(originalPublicKeyPath));
227
+ data.files[publicKeyPath] = publicKey;
228
+
229
+ // for config file
230
+ keyBasename = path.basename(originalPrivateKeyPath);
231
+ break;
232
+ }
233
+ }
234
+
235
+ const configPath = path.join(PATH_SSH_DIRECTORY, 'config.d', `${hostnamePrefix}-${projectName}`);
236
+
237
+ data.files[configPath] = renderTemplate('ssh_config', {
238
+ projectName,
239
+ hostnamePrefix,
240
+ keyBasename,
241
+ });
242
+
243
+ return data;
244
+ }
245
+
246
+ export async function configureWiFi(data, mocks = null) {
247
+ title(`Configure WiFi connection`);
248
+
249
+ if (mocks) {
250
+ prompts.inject(Object.values(mocks));
251
+ }
252
+
253
+ // https://people.freedesktop.org/~lkundrak/nm-dbus-api/nm-settings.html
254
+ // @note - let's consider we always use wpa-psk for now
255
+
256
+ const answers = await prompts([
257
+ {
258
+ type: 'text',
259
+ name: 'wifiId',
260
+ message: 'Id of the WiFi connection:',
261
+ validate: value => {
262
+ const configPath = path.join(PATH_NETWORK_DIRECTORY, value);
263
+
264
+ if (!WIFI_ID_REGEXP.test(value)) {
265
+ return 'Please provide a valid WiFi configuration id. A valid configuration id must contain only lower case letters, digits, - and _';
266
+ } else if (fs.existsSync(configPath)) {
267
+ return `A WiFi configuration named "${value}" already exists`;
268
+ }
269
+
270
+ return true;
271
+ },
272
+ }, {
273
+ type: 'select',
274
+ name: 'wifiMode',
275
+ message: 'Select WiFi mode:',
276
+ choices: [
277
+ { title: 'Connect to existing WiFi network (recommended)', value: 'infrastructure' },
278
+ { title: 'Create Access Point', value: 'ap' },
279
+ ],
280
+ initial: 0,
281
+ },
282
+ {
283
+ type: 'text',
284
+ name: 'wifiSsid',
285
+ message: 'Wifi SSID:',
286
+ },
287
+ {
288
+ type: 'text',
289
+ name: 'wifiPsk',
290
+ message: 'Wifi password:',
291
+ validate: value => value.length < 8 ? 'A valid password must have at least 8 characters' : true,
292
+ },
293
+ ], { onCancel });
294
+
295
+ const { wifiId, wifiMode } = answers;
296
+ const connectionPath = path.join(PATH_NETWORK_DIRECTORY, `${wifiId}.nmconnection`);
297
+ let connectionConfig = null;
298
+
299
+ switch (wifiMode) {
300
+ case 'infrastructure': {
301
+ const { wifiPriority } = await prompts({
302
+ type: 'number',
303
+ name: 'wifiPriority',
304
+ message: 'WiFi priority (higher number means higher priority):',
305
+ min: -2147483648, // int32
306
+ max: 2147483647,
307
+ round: 0,
308
+ initial: 0,
309
+ }, { onCancel });
310
+
311
+ connectionConfig = renderTemplate('infrastructure.nmconnection', {
312
+ wifiPriority,
313
+ ...answers,
314
+ });
315
+ break;
316
+ }
317
+ case 'ap': {
318
+ connectionConfig = renderTemplate('ap.nmconnection', {
319
+ ...answers,
320
+ });
321
+ break;
322
+ }
323
+ default: {
324
+ throw new Error(`Cannot generate WiFi nmconnection file: Invalid mode ${wifiMode}`);
325
+ }
326
+ }
327
+
328
+ data.files[connectionPath] = connectionConfig;
329
+
330
+ // ask for creating another WiFi config
331
+ const { createAnotherConnection } = await prompts({
332
+ type: 'toggle',
333
+ name: 'createAnotherConnection',
334
+ message: 'Do you want to configure another WiFi connection?',
335
+ initial: false,
336
+ active: 'yes',
337
+ inactive: 'no'
338
+ });
339
+
340
+ if (createAnotherConnection) {
341
+ await configureWiFi(data, mocks);
342
+ }
343
+
344
+ return data;
345
+ }
346
+
347
+
348
+ export async function injectUtilityFiles(data) {
349
+ const { projectName } = data;
350
+
351
+ data.files[PATH_DOTPI_FILE] = JSON.stringify({ dotpiToolsVersion: packageVersion() }, null, 2);
352
+
353
+ data.files[PATH_GITIGNORE] = renderTemplate('.gitignore', {
354
+ PATH_DOTPI_SECRETS_BASH,
355
+ PATH_SSH_DIRECTORY,
356
+ PATH_NETWORK_DIRECTORY,
357
+ PATH_DOTPI_TMP_DIRECTORY,
358
+ });
359
+
360
+ data.files[PATH_README] = renderTemplate('README.md', {
361
+ projectName,
362
+ PATH_DOTPI_SECRETS_BASH,
363
+ PATH_SSH_DIRECTORY,
364
+ PATH_NETWORK_DIRECTORY,
365
+ });
366
+ }
367
+
368
+ export async function persistProject(data, mocks = null) {
369
+ title('Save dotpi project');
370
+
371
+ const { projectName } = data;
372
+ const projectPath = path.join(CWD, projectName);
373
+
374
+ console.log(chalk.yellow(`> Your project will be created in "${projectPath}"`));
375
+ if (!await confirm(mocks)) {
376
+ return;
377
+ }
378
+
379
+ console.log('');
380
+ console.log(chalk.grey(`- Creating project directory: ${projectPath}`));
381
+ fs.mkdirSync(projectPath, { recursive: true });
382
+
383
+ for (let file in data.files) {
384
+ const pathname = path.join(projectPath, file);
385
+ const content = data.files[file];
386
+ console.log(chalk.grey(`- Writing project file: ${pathname}`));
387
+ // ensure directory exists
388
+ fs.mkdirSync(path.dirname(pathname), { recursive: true });
389
+ fs.writeFileSync(pathname, content);
390
+ }
391
+
392
+ title(`Project ${projectName} successfully created!`);
393
+ }
394
+
395
+ // Wrap it all
396
+ export default async function createProject() {
397
+ if (isDotpiProject()) {
398
+ console.log('');
399
+ console.log(chalk.yellow(`> Cannot create a dotpi project in this directory, it already contains a dotpi project`));
400
+ console.log('Aborting...');
401
+ process.exit(0);
402
+ }
403
+
404
+ const data = {
405
+ projectName: null,
406
+ files: {},
407
+ };
408
+
409
+ await prepareProject(data);
410
+ await configureProject(data);
411
+ await configureSSH(data);
412
+ await configureWiFi(data);
413
+ await injectUtilityFiles(data);
414
+ await persistProject(data);
415
+
416
+ const { configure } = await prompts({
417
+ type: 'toggle',
418
+ name: 'configure',
419
+ message: 'Do you want to configure your local machine for this project?',
420
+ initial: true,
421
+ active: 'yes',
422
+ inactive: 'no'
423
+ }, { onCancel });
424
+
425
+ const { projectName } = data;
426
+
427
+ if (configure) {
428
+ const projectPath = path.join(CWD, projectName);
429
+ await configureHost(projectPath);
430
+ }
431
+
432
+ console.log(`\
433
+ > The dotpi project "${projectName}" is ready to be installed on some Raspberry Pi
434
+ >
435
+ > Next Step: plug-in a SD Card with a Raspberry Pi OS (Lite) installed and run:
436
+ > ${chalk.yellow('dotpi-tools --install-rpi')}
437
+ `);
438
+ }
@@ -0,0 +1,173 @@
1
+ import path from 'node:path';
2
+ import { spawn, execSync } from 'node:child_process';
3
+
4
+ import prompts from 'prompts';
5
+ import chalk from 'chalk';
6
+
7
+ import {
8
+ PATH_DOTPI_TMP_BASH,
9
+ PATH_DOTPI_PREPARE_SD_CARD_BASH,
10
+ CWD,
11
+ } from './constants.js';
12
+ import {
13
+ title,
14
+ confirm,
15
+ onCancel,
16
+ readBashVariable,
17
+ isDotpiProject,
18
+ chooseProject,
19
+ isWindowsWsl,
20
+ } from './utils.js'
21
+
22
+ export default async function installRpi(mocks = null) {
23
+ title('Install a dotpi project on a Raspberry Pi');
24
+
25
+ if (mocks) {
26
+ prompts.inject(Object.values(mocks))
27
+ }
28
+
29
+ let projectPath;
30
+
31
+ if (isDotpiProject(CWD)) {
32
+ projectPath = CWD;
33
+ } else {
34
+ projectPath = await chooseProject(CWD);
35
+ }
36
+
37
+ const dotpiTmpFile = path.join(projectPath, PATH_DOTPI_TMP_BASH);
38
+ const nextInstanceNumber = readBashVariable('dotpi_instance_number', dotpiTmpFile) || 1;
39
+
40
+ const { instanceNumber } = await prompts({
41
+ type: 'number',
42
+ name: 'instanceNumber',
43
+ message: 'Raspberry Pi instance number:',
44
+ initial: nextInstanceNumber,
45
+ }, { onCancel });
46
+
47
+ // If linux in window (i.e. WSL), we weed the drive letter to mount it
48
+ let bootfsDriveLetter = null;
49
+
50
+ if (isWindowsWsl()) {
51
+ const result = await prompts({
52
+ type: 'text',
53
+ name: 'bootfsDriveLetter',
54
+ message: 'Enter the drive letter of the "bootfs" SD card:',
55
+ initial: 'E',
56
+ validate: val => {
57
+ return val.length === 1 && /[A-Za-z]/.test(val)
58
+ ? true
59
+ : 'Invalid drive letter'
60
+ },
61
+ format: val => val.toUpperCase(),
62
+ }, { onCancel });
63
+
64
+ bootfsDriveLetter = result.bootfsDriveLetter;
65
+ }
66
+
67
+ console.log('');
68
+
69
+ if (!await confirm(mocks)) {
70
+ return;
71
+ }
72
+
73
+ console.log('');
74
+ console.log(chalk.yellow('> Preparing SD Card'));
75
+ console.log('');
76
+
77
+ const result = await new Promise(resolve => {
78
+ let cmd = `${PATH_DOTPI_PREPARE_SD_CARD_BASH} --project "${projectPath}" --instance-number ${instanceNumber}`;
79
+
80
+ if (bootfsDriveLetter !== null) {
81
+ cmd += ` --bootfs-drive-letter "${bootfsDriveLetter}"`;
82
+ }
83
+
84
+ console.log(cmd);
85
+ // we can now execute the shell script
86
+ const script = spawn(cmd, { shell: '/bin/bash' });
87
+ script.stdout.on('data', data => process.stdout.write(data.toString()));
88
+ script.stderr.on('data', data => process.stderr.write(data.toString()));
89
+
90
+ script.on('close', (code) => {
91
+ if (code !== 0) {
92
+ console.log(chalk.yellow(`> Process exited with code ${code}`));
93
+ return resolve(false);
94
+ }
95
+
96
+ resolve(true)
97
+ });
98
+ });
99
+
100
+ if (!result) {
101
+ return;
102
+ }
103
+
104
+ let sdCardMsg = isWindowsWsl()
105
+ ? `> You can now eject the SD card, put it in the Raspberry Pi and power it on`
106
+ : `> You can now put the SD card in the Raspberry Pi and power it on`;
107
+
108
+ console.log('');
109
+ console.log(chalk.yellow(sdCardMsg));
110
+ console.log('');
111
+
112
+ const { monitorInstall } = await prompts({
113
+ type: 'toggle',
114
+ name: 'monitorInstall',
115
+ message: 'Do you want to remotely monitor the installation?',
116
+ initial: true,
117
+ active: 'yes',
118
+ inactive: 'no'
119
+ }, { onCancel });
120
+
121
+ if (!monitorInstall) {
122
+ return;
123
+ }
124
+
125
+ // @todo - define with JIP how we can exit this properly
126
+ // - error, ask to restart from scratch
127
+ // - ok, congrats your raspberry is up and running
128
+ await new Promise(resolve => {
129
+ const DOTPI_ETC = path.normalize('tmp/file-system/opt/dotpi/etc');
130
+ const hostname = readBashVariable(
131
+ 'dotpi_instance_hostname',
132
+ path.join(projectPath, DOTPI_ETC, 'dotpi_environment_instance.bash')
133
+ );
134
+
135
+ console.log('');
136
+ console.log(chalk.cyan('> Waiting for the Pi to connect (this might take a few minutes)'));
137
+ console.log(chalk.cyan(`> hostname: ${hostname}.local`));
138
+ console.log('');
139
+
140
+ // wait for the device to be online before launching ssh command (required for Linux)
141
+ let errored = true;
142
+
143
+ while (errored) {
144
+ try {
145
+ execSync(`ping -c 1 -t 10 ${hostname}.local &> /dev/null`, { shell: '/bin/bash' });
146
+ errored = false;
147
+ } catch (err) {
148
+ process.stdout.write('.');
149
+ }
150
+ }
151
+
152
+ console.log('');
153
+ console.log('');
154
+ console.log(chalk.cyan('> Pi connected, reading log file:'));
155
+ console.log('');
156
+
157
+ const script = spawn(
158
+ `ssh pi@${hostname}.local 'tail -f /opt/dotpi/var/log/dotpi_prepare_system_*.log'`,
159
+ { shell: '/bin/bash' }
160
+ );
161
+
162
+ script.stdout.on('data', data => process.stdout.write(data.toString()));
163
+ script.stderr.on('data', data => process.stderr.write(data.toString()));
164
+ script.on('close', (code) => {
165
+ if (code !== 0) {
166
+ console.log(chalk.yellow(`> Process exited with code ${code}`));
167
+ return resolve();
168
+ }
169
+
170
+ resolve();
171
+ });
172
+ });
173
+ }
@@ -0,0 +1,16 @@
1
+ # dotpi project - ${d.projectName}
2
+
3
+ This directory contains the necessary configuration files to install a Raspberry Pi
4
+ that belongs to a given dotpi project.
5
+
6
+ ## Warning
7
+
8
+ This directory contains sensitive informations that SHOULD NOT be shared on a
9
+ public repository.
10
+
11
+ In particular, the following files are ignored by default:
12
+ - ${d.PATH_DOTPI_SECRETS_BASH}
13
+ - ${d.PATH_SSH_DIRECTORY}
14
+ - ${d.PATH_NETWORK_DIRECTORY}
15
+
16
+ You should thus share these files with people you trust through secure means.
@@ -0,0 +1,25 @@
1
+ [connection]
2
+ id=${d.wifiId}
3
+ type=wifi
4
+ # do not use external AP by default
5
+ autoconnect=true
6
+ interface-name=wlan0
7
+
8
+ [wifi]
9
+ mode=ap
10
+ ssid=${d.wifiSsid}
11
+ # disable power management
12
+ powersave=2
13
+
14
+ [wifi-security]
15
+ key-mgmt=wpa-psk
16
+ psk=${d.wifiPsk}
17
+
18
+ [ipv4]
19
+ method=shared
20
+
21
+ [ipv6]
22
+ addr-gen-mode=default
23
+ method=link-local
24
+
25
+ [proxy]
@@ -0,0 +1,31 @@
1
+ #!/bin/bash
2
+
3
+ # @dotpi/tools version
4
+ dotpi_tools_version='${d.version}'
5
+
6
+ # Project name
7
+ dotpi_project_name='${d.projectName}'
8
+
9
+ # Define soundcard
10
+ dotpi_audio_device='${d.soundCard}'
11
+
12
+ # Node.js version
13
+ dotpi_node_version='${d.nodeVersion}'
14
+
15
+ # Install dotpi-manager service
16
+ dotpi_manager_install='${d.installDotpiManager ? 'yes' : 'no'}'
17
+
18
+ # Install dotpi-led service
19
+ dotpi_led_install='${d.installDotpiLed ? 'yes' : 'no'}'
20
+ ${d.installDotpiLed ? `\
21
+ dotpi_led_strip_configuration='${d.dotPiLedConfigFile}'` : ``}
22
+
23
+ # Misc
24
+ dotpi_timezone='${d.timeZone}'
25
+ dotpi_wifi_country_code='${d.wifiCountryCode}'
26
+ dotpi_keymap='${d.keyMap}'
27
+
28
+ # If you want to have some packages to be automatically installed
29
+ # or removed by default, you can list them in the arrays above
30
+ dotpi_apt_install+=()
31
+ dotpi_apt_uninstall+=()
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ # Password of the 'pi' user
4
+ dotpi_password='${d.password}'