@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.
- package/DOC.md +66 -0
- package/LICENSE +28 -0
- package/NOTES.md +81 -0
- package/README.md +341 -0
- package/dotpi-tools.js +35 -0
- package/dotpi_root/bin/dotpi +66 -0
- package/dotpi_root/bin/dotpi_firstrun +193 -0
- package/dotpi_root/bin/dotpi_prepare_sd_card +616 -0
- package/dotpi_root/bin/dotpi_prepare_system +244 -0
- package/dotpi_root/etc/dotpi_environment_default.bash +69 -0
- package/dotpi_root/etc/dotpi_tarignore +3 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_manager +39 -0
- package/dotpi_root/share/dotpi-install/update_to_v1.0.0_pi +39 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth.service +23 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_bluetooth_command +134 -0
- package/dotpi_root/share/dotpi_audio_bluetooth/dotpi_audio_pipewire_relink +132 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor.service +22 -0
- package/dotpi_root/share/dotpi_avahi_monitor/dotpi_avahi_monitor_command +14 -0
- package/dotpi_root/share/dotpi_environment.bash +5 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_bluetooth.bash +346 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +504 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_configuration.bash +435 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_connection.bash +199 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_dotpi.bash +36 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_service.bash +111 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_system.bash +175 -0
- package/dotpi_root/share/dotpi_functions/dotpi_functions_utils.bash +154 -0
- package/dotpi_root/share/dotpi_functions.bash +14 -0
- package/dotpi_root/share/dotpi_init.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_bluetooth.bash +18 -0
- package/dotpi_root/share/jackd/dotpi_jackd_command +26 -0
- package/dotpi_root/share/jackd/dotpi_jackd_headphones.bash +21 -0
- package/dotpi_root/share/jackd/dotpi_jackd_hifiberry.bash +17 -0
- package/dotpi_root/share/jackd/jackd.service +22 -0
- package/dotpi_root/share/limits/zzz_dotpi_audio.conf +11 -0
- package/dotpi_root/share/wireplumber/bluetooth.lua.d/8zzz-dotpi-wireplumber-config.lua +4 -0
- package/examples/example-development/configuration/dotpi_project.bash +40 -0
- package/examples/example-headphones/configuration/dotpi_project.bash +18 -0
- package/examples/example-hifiberry/configuration/dotpi_instance_012.bash +4 -0
- package/examples/example-hifiberry/configuration/dotpi_project.bash +18 -0
- package/examples/example-network/configuration/dotpi_project.bash +21 -0
- package/package.json +35 -0
- package/src/configure-host.js +187 -0
- package/src/constants.js +30 -0
- package/src/create-project.js +438 -0
- package/src/install-rpi.js +173 -0
- package/src/templates/README.md +16 -0
- package/src/templates/ap.nmconnection +25 -0
- package/src/templates/dotpi_project.bash +31 -0
- package/src/templates/dotpi_secrets.bash +4 -0
- package/src/templates/infrastructure.nmconnection +29 -0
- package/src/templates/ssh_config +6 -0
- package/src/utils.js +175 -0
- package/test/constants.spec.js +37 -0
- package/test/create-project.test.js +57 -0
- package/test/install-rpi.test.js +8 -0
- package/test/utils.spec.js +48 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[connection]
|
|
2
|
+
id=${d.wifiId}
|
|
3
|
+
type=wifi
|
|
4
|
+
interface-name=wlan0
|
|
5
|
+
autoconnect-priority=${d.wifiPriority}
|
|
6
|
+
# always retry to connect
|
|
7
|
+
autoconnect-retries=0
|
|
8
|
+
# always retry to authenticate
|
|
9
|
+
auth-retries=0
|
|
10
|
+
|
|
11
|
+
[wifi]
|
|
12
|
+
mode=infrastructure
|
|
13
|
+
ssid=${d.wifiSsid}
|
|
14
|
+
# disable power management
|
|
15
|
+
powersave=2
|
|
16
|
+
# band=a
|
|
17
|
+
|
|
18
|
+
[wifi-security]
|
|
19
|
+
key-mgmt=wpa-psk
|
|
20
|
+
psk=${d.wifiPsk}
|
|
21
|
+
|
|
22
|
+
[ipv4]
|
|
23
|
+
method=auto
|
|
24
|
+
|
|
25
|
+
[ipv6]
|
|
26
|
+
addr-gen-mode=default
|
|
27
|
+
method=link-local
|
|
28
|
+
|
|
29
|
+
[proxy]
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
4
|
+
import { EOL, platform } from 'node:os';
|
|
5
|
+
|
|
6
|
+
import prompts from 'prompts';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import compile from 'template-literal';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
LIB_ROOT,
|
|
12
|
+
CWD,
|
|
13
|
+
HOME,
|
|
14
|
+
PATH_DOTPI_INIT_BASH,
|
|
15
|
+
PATH_DOTPI_FILE,
|
|
16
|
+
PATH_TEMPLATE_DIRECTORY,
|
|
17
|
+
} from './constants.js';
|
|
18
|
+
|
|
19
|
+
export const packageVersion = () => {
|
|
20
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(LIB_ROOT, 'package.json')));
|
|
21
|
+
return pkg.version;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function greetings() {
|
|
25
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(LIB_ROOT, 'package.json')));
|
|
26
|
+
|
|
27
|
+
console.log(chalk.grey(`[${pkg.name}#v${pkg.version}]`));
|
|
28
|
+
console.log('');
|
|
29
|
+
console.log(chalk.yellow(`> welcome to ${pkg.name}`));
|
|
30
|
+
// @todo - update
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log(`- documentation: ${chalk.cyan(`${pkg.homepage}`)}`);
|
|
33
|
+
console.log(`- issues: ${chalk.cyan(`${pkg.bugs.url}`)}`);
|
|
34
|
+
|
|
35
|
+
// if (platform() !== 'darwin') {
|
|
36
|
+
// console.log(chalk.yellow(`
|
|
37
|
+
// * WARNING: these tools have only been tested on Mac so far, you may encounter issues
|
|
38
|
+
// * on other platform, and in particular on windows.
|
|
39
|
+
// *
|
|
40
|
+
// * Any PR welcome! ${homepage}
|
|
41
|
+
// * `))
|
|
42
|
+
// }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function title(str) {
|
|
46
|
+
console.log('');
|
|
47
|
+
console.log(chalk.cyan(`> [dotpi] ${str}`));
|
|
48
|
+
console.log('');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function renderTemplate(templatePath, data = {}) {
|
|
52
|
+
const pathname = path.join(PATH_TEMPLATE_DIRECTORY, templatePath);
|
|
53
|
+
|
|
54
|
+
if (!fs.existsSync(pathname)) {
|
|
55
|
+
throw new Error(`Cannot execute 'renderTemplate': template file '${pathname}' not found`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const template = fs.readFileSync(pathname);
|
|
59
|
+
const render = compile(template);
|
|
60
|
+
|
|
61
|
+
return render(data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const homeRE = new RegExp(`^${HOME}`);
|
|
65
|
+
export function formatPath(pathname) {
|
|
66
|
+
return pathname.replace(homeRE, '~');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isDotpiProject(pathname = CWD) {
|
|
70
|
+
const dotpiFile = path.join(pathname, PATH_DOTPI_FILE);
|
|
71
|
+
return fs.statSync(pathname).isDirectory() && fs.existsSync(dotpiFile)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function listDotpiProjects(pathname = CWD) {
|
|
75
|
+
return fs.readdirSync(pathname)
|
|
76
|
+
.map(filename => path.join(pathname, filename))
|
|
77
|
+
.filter(filename => isDotpiProject(filename))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function isPrivateSshKey(pathname) {
|
|
81
|
+
if (fs.existsSync(pathname) && fs.statSync(pathname).isFile()) {
|
|
82
|
+
const content = fs.readFileSync(pathname).toString();
|
|
83
|
+
return content.startsWith(`-----BEGIN OPENSSH PRIVATE KEY-----`);
|
|
84
|
+
} else {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function isWindowsWsl() {
|
|
90
|
+
const buffer = execSync('uname -a', { shell: '/bin/bash' });
|
|
91
|
+
const unameString = buffer.toString();
|
|
92
|
+
return /Microsoft/.test(unameString);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Allow using ~ or $HOME into given pathname
|
|
97
|
+
* @param {*} pathname
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
export function processPath(pathname) {
|
|
101
|
+
const buffer = execSync(`echo ${pathname}`);
|
|
102
|
+
return buffer.toString().trim();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// -------------------------------------------------------
|
|
106
|
+
// Bash utils
|
|
107
|
+
// -------------------------------------------------------
|
|
108
|
+
export function readBashVariable(varname, filename = PATH_DOTPI_INIT_BASH) {
|
|
109
|
+
if (!fs.existsSync(filename)) {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return execSync(`source ${filename}; echo "\${${varname}}"`, {
|
|
114
|
+
shell: '/bin/bash',
|
|
115
|
+
}).toString().trim();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function readBashArray(varname, filename = PATH_DOTPI_INIT_BASH) {
|
|
119
|
+
if (!fs.existsSync(filename)) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return execSync(`source ${filename}; for i in "\${${varname}[@]}" ; do echo "\${i}" ; done`, {
|
|
124
|
+
shell: '/bin/bash',
|
|
125
|
+
}).toString().trim().split(EOL)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// -------------------------------------------------------
|
|
129
|
+
// Prompts utils
|
|
130
|
+
// -------------------------------------------------------
|
|
131
|
+
export const onCancel = () => process.exit();
|
|
132
|
+
|
|
133
|
+
// maybe useless - tbd
|
|
134
|
+
export async function confirm(mocks = null) {
|
|
135
|
+
// always proceed in tests
|
|
136
|
+
if (mocks) {
|
|
137
|
+
prompts.inject([true]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { proceed } = await prompts({
|
|
141
|
+
type: 'toggle',
|
|
142
|
+
name: 'proceed',
|
|
143
|
+
message: 'Continue?',
|
|
144
|
+
initial: true,
|
|
145
|
+
active: 'yes',
|
|
146
|
+
inactive: 'no',
|
|
147
|
+
}, { onCancel });
|
|
148
|
+
|
|
149
|
+
// do not exit process in tests
|
|
150
|
+
if (!proceed) {
|
|
151
|
+
console.log('Aborting...');
|
|
152
|
+
process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return proceed;
|
|
156
|
+
}
|
|
157
|
+
export async function chooseProject(basePathname, mocks = null) {
|
|
158
|
+
const projects = listDotpiProjects(basePathname);
|
|
159
|
+
|
|
160
|
+
if (projects.length === 0) {
|
|
161
|
+
console.log(chalk.yellow(`> No dotpi project found in ${basePathname}`));
|
|
162
|
+
console.log('');
|
|
163
|
+
console.log('Aborting...');
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const { projectPath } = await prompts({
|
|
168
|
+
type: 'select',
|
|
169
|
+
name: 'projectPath',
|
|
170
|
+
message: 'Select a dotpi project',
|
|
171
|
+
choices: projects.map(value => ({ title: path.basename(value), value })),
|
|
172
|
+
}, { onCancel });
|
|
173
|
+
|
|
174
|
+
return projectPath;
|
|
175
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
PROJECT_NAME_REGEXP,
|
|
6
|
+
} from '../src/constants.js';
|
|
7
|
+
|
|
8
|
+
describe('# Project / Hostname RegExp', () => {
|
|
9
|
+
it('should accept valid names', () => {
|
|
10
|
+
const valid = [
|
|
11
|
+
'coucou1234',
|
|
12
|
+
'coucou_1234',
|
|
13
|
+
'coucou-1234',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
valid.forEach(str => {
|
|
17
|
+
// console.log(`- "${str}" should be valid`);
|
|
18
|
+
assert.equal(PROJECT_NAME_REGEXP.test(str), true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should refuse invalid names', () => {
|
|
23
|
+
const invalid = [
|
|
24
|
+
'',
|
|
25
|
+
'Coucou1234',
|
|
26
|
+
'coucou.1234',
|
|
27
|
+
'coucou 1234',
|
|
28
|
+
'hého',
|
|
29
|
+
'$sef',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
invalid.forEach(str => {
|
|
33
|
+
// console.log(`- "${str}" should be invalid`);
|
|
34
|
+
assert.equal(PROJECT_NAME_REGEXP.test(str), false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
import { greetings } from '../src/utils.js';
|
|
3
|
+
import {
|
|
4
|
+
prepareProject,
|
|
5
|
+
configureProject,
|
|
6
|
+
configureSSH,
|
|
7
|
+
configureWiFi,
|
|
8
|
+
injectUtilityFiles,
|
|
9
|
+
persistProject,
|
|
10
|
+
} from '../src/create-project.js';
|
|
11
|
+
|
|
12
|
+
// must match the order of the questions
|
|
13
|
+
const prepareProject = {
|
|
14
|
+
projectName: 'coucou',
|
|
15
|
+
password: 'my-password',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const configureProjectMocks = {
|
|
19
|
+
soundcard: 'hifiberry dac+ adc pro',
|
|
20
|
+
nodeVersion: 'lts',
|
|
21
|
+
timeZone: 'Europe/Paris',
|
|
22
|
+
keyMap: 'fr',
|
|
23
|
+
installDotpiManager: true,
|
|
24
|
+
installDotpiLed: false,
|
|
25
|
+
dotpiLedConfigFile: undefined,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const sshMocks = {
|
|
29
|
+
createOrResuse: 'create',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const configureWifiInfraMocks = {
|
|
33
|
+
wifiId: 'test_infra',
|
|
34
|
+
wifiMode: 'infrastructure',
|
|
35
|
+
wifiSsid: 'INFRA_SSID',
|
|
36
|
+
wifiPsk: 'INFRA_PASSWD',
|
|
37
|
+
wifiPriority: 12,
|
|
38
|
+
createAnotherConnection: false,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const configureWifiAPMocks = {
|
|
42
|
+
wifiId: 'test_ap',
|
|
43
|
+
wifiMode: 'ap',
|
|
44
|
+
wifiSsid: 'AP_SSID',
|
|
45
|
+
wifiPsk: 'PS_PASSWD',
|
|
46
|
+
createAnotherConnection: false,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// greetings();
|
|
50
|
+
const data = {};
|
|
51
|
+
await prepareProject(data, prepareMocks);
|
|
52
|
+
// await configureProject(data);
|
|
53
|
+
// await configureSSH(data);
|
|
54
|
+
// await configureWiFi(data, configureWifiAPMocks);
|
|
55
|
+
await injectUtilityFiles(data);
|
|
56
|
+
// await persistProject(data);
|
|
57
|
+
console.log(data);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { readBashArray, readBashVariable, packageVersion } from '../js/utils.js';
|
|
5
|
+
|
|
6
|
+
describe('# utils', () => {
|
|
7
|
+
it('packageVersion()', () => {
|
|
8
|
+
const version = packageVersion();
|
|
9
|
+
console.log('package version:', version);
|
|
10
|
+
assert.equal(typeof version, 'string');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('readBashVariable()', () => {
|
|
14
|
+
const value = readBashVariable('dotpi_audio_device');
|
|
15
|
+
assert.equal(value, 'default');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('readBashArray()', () => {
|
|
19
|
+
const arr = readBashArray('dotpi_audio_device_supported');
|
|
20
|
+
assert.deepEqual(arr, [
|
|
21
|
+
'default',
|
|
22
|
+
'none',
|
|
23
|
+
'headphones',
|
|
24
|
+
'hifiberry dac+ adc pro',
|
|
25
|
+
'hifiberry dac+ adc',
|
|
26
|
+
'hifiberry dac+ standard',
|
|
27
|
+
'hifiberry dac+ light',
|
|
28
|
+
'hifiberry dac zero',
|
|
29
|
+
'hifiberry miniamp',
|
|
30
|
+
'hifiberry beocreate',
|
|
31
|
+
'hifiberry dac+ dsp',
|
|
32
|
+
'hifiberry dac+ rtc',
|
|
33
|
+
'hifiberry pro',
|
|
34
|
+
'hifiberry amp2',
|
|
35
|
+
'hifiberry dac2 hd',
|
|
36
|
+
'hifiberry digi+',
|
|
37
|
+
'hifiberry digi+ pro',
|
|
38
|
+
'hifiberry amp+',
|
|
39
|
+
'hifiberry amp3',
|
|
40
|
+
'bluetooth',
|
|
41
|
+
'ue boom 2',
|
|
42
|
+
'ue boom 3',
|
|
43
|
+
'ue megaboom 2',
|
|
44
|
+
'ue megaboom 3',
|
|
45
|
+
'hifiberry dac for raspberry pi 1'
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
});
|