@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,21 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
dotpi_project_name='example'
|
|
4
|
+
|
|
5
|
+
dotpi_ssh_allow_password_authentication='yes'
|
|
6
|
+
|
|
7
|
+
dotpi_timezone='Europe/Paris'
|
|
8
|
+
dotpi_keymap='fr'
|
|
9
|
+
|
|
10
|
+
dotpi_audio_device='HiFiBerry DAC+ ADC Pro'
|
|
11
|
+
|
|
12
|
+
# add packages
|
|
13
|
+
# be sure to keep the parentheses, even for a single line
|
|
14
|
+
dotpi_apt_install+=(
|
|
15
|
+
'jackmeter' # monitor sound activity in console
|
|
16
|
+
# 'locate'
|
|
17
|
+
'dnsutils' # dig
|
|
18
|
+
'nmap' # test clients in network
|
|
19
|
+
'screen' # detach sessions
|
|
20
|
+
# 'mpv' # play soundfiles via jackd
|
|
21
|
+
)
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotpi/tools",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Set of scripts for managing dotpi fleets of Raspberry Pi",
|
|
5
|
+
"author": "Jean-Philippe Lambert",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Jean-Philippe Lambert",
|
|
8
|
+
"Benjamin Matuszewski"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"dotpi-tools": "./dotpi-tools.js"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://ircam-ismm.github.io/dotpi/",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/ircam-ismm/dotpi-tools"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/ircam-ismm/dotpi-tools/issues"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test"
|
|
27
|
+
},
|
|
28
|
+
"license": "BSD-3-Clause",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"chalk": "^5.3.0",
|
|
31
|
+
"commander": "^12.1.0",
|
|
32
|
+
"prompts": "^2.4.2",
|
|
33
|
+
"template-literal": "^1.0.4"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { EOL } from 'node:os';
|
|
4
|
+
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
CWD,
|
|
10
|
+
HOME,
|
|
11
|
+
LIB_ROOT,
|
|
12
|
+
PATH_DOTPI_PROJECT_BASH,
|
|
13
|
+
PATH_SSH_DIRECTORY,
|
|
14
|
+
} from './constants.js';
|
|
15
|
+
import {
|
|
16
|
+
onCancel,
|
|
17
|
+
formatPath,
|
|
18
|
+
confirm,
|
|
19
|
+
isDotpiProject,
|
|
20
|
+
isPrivateSshKey,
|
|
21
|
+
chooseProject,
|
|
22
|
+
title,
|
|
23
|
+
readBashVariable,
|
|
24
|
+
} from './utils.js';
|
|
25
|
+
|
|
26
|
+
// # Notes
|
|
27
|
+
// - SSH files permissions: https://jonasbn.github.io/til/ssh/permissions_on_ssh_folder_and_files.html
|
|
28
|
+
|
|
29
|
+
export default async function configureHost(projectPath = null) {
|
|
30
|
+
title('Install SSH keys on local machine');
|
|
31
|
+
|
|
32
|
+
// Allow configureHost to be called programmatically
|
|
33
|
+
if (projectPath === null) {
|
|
34
|
+
if (isDotpiProject(CWD)) {
|
|
35
|
+
projectPath = CWD;
|
|
36
|
+
} else {
|
|
37
|
+
projectPath = await chooseProject(CWD);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const testing = null;
|
|
42
|
+
|
|
43
|
+
const projectName = readBashVariable('dotpi_project_name', path.join(projectPath, PATH_DOTPI_PROJECT_BASH));
|
|
44
|
+
const projectSshPath = path.join(projectPath, PATH_SSH_DIRECTORY);
|
|
45
|
+
|
|
46
|
+
const targetSshPath = testing
|
|
47
|
+
? path.join(LIB_ROOT, 'test', 'ssh-test-output')
|
|
48
|
+
: path.join(HOME, '.ssh');
|
|
49
|
+
|
|
50
|
+
console.log(chalk.yellow(`> Project: "${projectName}" | directory: ${formatPath(projectPath)}`));
|
|
51
|
+
console.log(`
|
|
52
|
+
To configure your machine for the "${projectName}" dotpi project, this script will automatically:
|
|
53
|
+
|
|
54
|
+
1) copy the project specific SSH private and public keys into your \`$HOME/.ssh\` directory if they do not already exist
|
|
55
|
+
2) add the project specific SSH private key to the ssh-agent
|
|
56
|
+
3) copy the project specific SSH config file into your \`$HOME/.ssh/config.d\` directory if it does not exists
|
|
57
|
+
4) update or create your \`$HOME/.ssh/config\` file to automatically include all config files located in \`$HOME/.ssh/config.d\` if needed
|
|
58
|
+
|
|
59
|
+
If you prefer to do this manually, you can refer to the following documentation:
|
|
60
|
+
- https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent?platform=mac#adding-your-ssh-key-to-the-ssh-agent
|
|
61
|
+
- https://jonasbn.github.io/til/ssh/permissions_on_ssh_folder_and_files.html
|
|
62
|
+
|
|
63
|
+
You will be able to find all the relevant files in: ${formatPath(projectSshPath)}
|
|
64
|
+
`);
|
|
65
|
+
|
|
66
|
+
if (!await confirm(testing)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
title('1) Copy project SSH keys');
|
|
71
|
+
|
|
72
|
+
const files = fs.readdirSync(projectSshPath)
|
|
73
|
+
.filter(filename => fs.statSync(path.join(projectSshPath, filename)).isFile())
|
|
74
|
+
.map(filename => path.join(projectSshPath, filename));
|
|
75
|
+
|
|
76
|
+
const srcPrivateKey = files.find(filename => isPrivateSshKey(filename));
|
|
77
|
+
|
|
78
|
+
if (!srcPrivateKey) {
|
|
79
|
+
console.log(chalk.yellow(`> No valid SSH private key found in ${formatPath(projectSshPath)}`));
|
|
80
|
+
console.log('Aborting...');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log(chalk.grey(`> Found project private SSH key: ${formatPath(srcPrivateKey)}`));
|
|
85
|
+
|
|
86
|
+
const srcPublicKey = `${srcPrivateKey}.pub`;
|
|
87
|
+
|
|
88
|
+
if (!fs.existsSync(srcPublicKey) || !fs.statSync(srcPublicKey).isFile()) {
|
|
89
|
+
console.log(chalk.yellow(`> No valid SSH public key found in ${formatPath(projectSshPath)}`));
|
|
90
|
+
console.log('Aborting...');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(chalk.grey(`> Found project public SSH key: ${formatPath(srcPublicKey)}`));
|
|
95
|
+
|
|
96
|
+
if (!fs.existsSync(targetSshPath)) {
|
|
97
|
+
console.log(chalk.grey(`> Create directory: ${targetSshPath}`));
|
|
98
|
+
fs.mkdirSync(targetSshPath);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const distPrivateKey = path.join(targetSshPath, path.basename(srcPrivateKey));
|
|
102
|
+
const distPublicKey = path.join(targetSshPath, path.basename(srcPublicKey));
|
|
103
|
+
|
|
104
|
+
if (!fs.existsSync(distPrivateKey) && !fs.existsSync(distPublicKey)) {
|
|
105
|
+
// copy ssh keys
|
|
106
|
+
console.log(chalk.grey(`> Copy private key "${path.basename(srcPrivateKey)}" into "${formatPath(targetSshPath)}" with 600 permissions`));
|
|
107
|
+
fs.copyFileSync(srcPrivateKey, distPrivateKey);
|
|
108
|
+
fs.chmodSync(distPrivateKey, 0o600);
|
|
109
|
+
|
|
110
|
+
// copy ssh keys
|
|
111
|
+
console.log(chalk.grey(`> Copy public key "${path.basename(srcPublicKey)}" into "${formatPath(targetSshPath)}" with 644 permissions`));
|
|
112
|
+
fs.copyFileSync(srcPublicKey, distPublicKey);
|
|
113
|
+
fs.chmodSync(distPublicKey, 0o644);
|
|
114
|
+
} else {
|
|
115
|
+
console.log(chalk.grey(`> SSH keys with same name found in "${formatPath(targetSshPath)}", skip...`));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
title('2) Copy project config file');
|
|
120
|
+
|
|
121
|
+
const projectConfigdPath = path.join(projectSshPath, 'config.d');
|
|
122
|
+
const targetConfigdPath = path.join(targetSshPath, 'config.d');
|
|
123
|
+
const srcProjectConfigFile = fs.readdirSync(projectConfigdPath)
|
|
124
|
+
.map(filename => path.join(projectConfigdPath, filename))
|
|
125
|
+
.find(filename => filename.endsWith(projectName))
|
|
126
|
+
|
|
127
|
+
if (srcProjectConfigFile) {
|
|
128
|
+
console.log(chalk.grey(`> Found project config file: ${formatPath(srcProjectConfigFile)}`));
|
|
129
|
+
|
|
130
|
+
if (!fs.existsSync(targetConfigdPath)) {
|
|
131
|
+
console.log(chalk.grey(`> Create directory: "${formatPath(targetConfigdPath)}"`));
|
|
132
|
+
fs.mkdirSync(targetConfigdPath);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const targetProjectConfigFile = path.join(targetConfigdPath, path.basename(srcProjectConfigFile));
|
|
136
|
+
|
|
137
|
+
if (!fs.existsSync(targetProjectConfigFile)) {
|
|
138
|
+
console.log(chalk.grey(`> Copy project config file "${path.basename(srcProjectConfigFile)}" into "${formatPath(targetConfigdPath)}" with 644 permissions`));
|
|
139
|
+
fs.copyFileSync(srcProjectConfigFile, targetProjectConfigFile);
|
|
140
|
+
fs.chmodSync(targetProjectConfigFile, 0o644);
|
|
141
|
+
} else {
|
|
142
|
+
console.log(chalk.grey(`> Project config file with same name found in "${formatPath(targetConfigdPath)}", skip...`));
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
console.log(chalk.grey(`> No project config file found in "${formatPath(projectConfigdPath)}", skip...`));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const includeString = 'Include config.d/*';
|
|
149
|
+
title(`3) Check .ssh/config "${includeString}"`);
|
|
150
|
+
|
|
151
|
+
const sshConfigFile = path.join(targetSshPath, 'config');
|
|
152
|
+
|
|
153
|
+
if (!fs.existsSync(sshConfigFile)) {
|
|
154
|
+
console.log(chalk.grey(`> Create SSH config file "${formatPath(sshConfigFile)}" with 600 permissions`));
|
|
155
|
+
fs.writeFileSync(sshConfigFile, includeString, {
|
|
156
|
+
encoding: 'utf8',
|
|
157
|
+
mode: 0o600,
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
console.log(chalk.grey(`> Found SSH config file "${formatPath(sshConfigFile)}", check "${includeString}"`));
|
|
161
|
+
|
|
162
|
+
const content = fs.readFileSync(sshConfigFile);
|
|
163
|
+
const includeRe = new RegExp(includeString, 'm');
|
|
164
|
+
const included = includeRe.test(content);
|
|
165
|
+
|
|
166
|
+
if (!included) {
|
|
167
|
+
console.log(chalk.grey(`> "${includeString}" not found in "${formatPath(sshConfigFile)}", inject directive`));
|
|
168
|
+
const newContext = `\
|
|
169
|
+
${includeString}
|
|
170
|
+
|
|
171
|
+
${content}
|
|
172
|
+
`;
|
|
173
|
+
fs.writeFileSync(sshConfigFile, newContext, {
|
|
174
|
+
encoding: 'utf8',
|
|
175
|
+
mode: 0o600,
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
console.log(chalk.grey(`> "${includeString}" found in "${formatPath(sshConfigFile)}", skip...`));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
console.log('');
|
|
183
|
+
// title(`4) Check .ssh/config "${includeString}"`);
|
|
184
|
+
// cleaning for tests
|
|
185
|
+
// fs.rmSync(distPrivateKey);
|
|
186
|
+
// fs.rmSync(distPublicKey);
|
|
187
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export const LIB_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
export const CWD = process.cwd();
|
|
7
|
+
export const HOME = os.homedir();
|
|
8
|
+
|
|
9
|
+
// shell scripts that we need to execute
|
|
10
|
+
export const PATH_DOTPI_INIT_BASH = path.join(LIB_ROOT, 'dotpi_root/share/dotpi_init.bash');
|
|
11
|
+
export const PATH_DOTPI_PREPARE_SD_CARD_BASH = path.join(LIB_ROOT, 'dotpi_root/bin/dotpi_prepare_sd_card');
|
|
12
|
+
// directories to read from and write to, repsectively
|
|
13
|
+
export const PATH_TEMPLATE_DIRECTORY = path.join(LIB_ROOT, 'src/templates');
|
|
14
|
+
|
|
15
|
+
// the files / directories that define a project
|
|
16
|
+
export const PATH_DOTPI_PROJECT_BASH = 'dotpi_project.bash';
|
|
17
|
+
export const PATH_DOTPI_SECRETS_BASH = 'dotpi_secrets.bash';
|
|
18
|
+
export const PATH_SSH_DIRECTORY = 'ssh';
|
|
19
|
+
export const PATH_NETWORK_DIRECTORY = 'network';
|
|
20
|
+
export const PATH_GITIGNORE = '.gitignore';
|
|
21
|
+
export const PATH_README = 'README.md';
|
|
22
|
+
export const PATH_DOTPI_FILE = '.dotpi';
|
|
23
|
+
// these ones are within a project, e.g. where the next instance number is stored
|
|
24
|
+
export const PATH_DOTPI_TMP_DIRECTORY = 'tmp';
|
|
25
|
+
export const PATH_DOTPI_TMP_BASH = path.join(PATH_DOTPI_TMP_DIRECTORY, 'dotpi_tmp.bash');
|
|
26
|
+
|
|
27
|
+
// misc
|
|
28
|
+
export const DOTPI_SSH_KEYS_PREFIX = 'id_rsa';
|
|
29
|
+
export const PROJECT_NAME_REGEXP = /^[a-z0-9\-_]+$/;
|
|
30
|
+
export const WIFI_ID_REGEXP = PROJECT_NAME_REGEXP;
|