penguins-eggs 10.0.60 → 10.1.1

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 (138) hide show
  1. package/.oclif.manifest.json +62 -1
  2. package/README.md +145 -75
  3. package/addons/eggs/theme/calamares/modules/{_users.yml → users.yml} +3 -3
  4. package/addons/eggs/theme/livecd/grub.main.full.cfg +1 -1
  5. package/addons/eggs/theme/livecd/grub.main.simple.cfg +1 -1
  6. package/conf/derivatives.yaml +4 -3
  7. package/conf/derivatives_fedora.yaml +6 -0
  8. package/conf/distros/alpine/calamares/modules/users.yml +3 -3
  9. package/conf/distros/bionic/calamares/calamares-modules/grubcfg/grubcfg.yml +1 -1
  10. package/conf/distros/bionic/calamares/modules/users.yml +3 -3
  11. package/conf/distros/buster/calamares/modules/users.yml +4 -3
  12. package/conf/distros/fedora/calamares/modules/users.yml +3 -3
  13. package/conf/distros/noble/calamares/modules/focal-jammy/users.yml +3 -3
  14. package/conf/distros/noble/calamares/modules/users.yml +1 -0
  15. package/conf/distros/opensuse/calamares/modules/users.yml +3 -3
  16. package/conf/distros/rolling/calamares/modules/users.yml +3 -3
  17. package/conf/eggs.yaml +1 -1
  18. package/conf/love.yaml +4 -4
  19. package/dist/classes/compressors.js +1 -1
  20. package/dist/classes/distro.d.ts +27 -3
  21. package/dist/classes/distro.js +361 -289
  22. package/dist/classes/ovary.d/bind-live-fs.js +22 -30
  23. package/dist/classes/ovary.d/edit-live-fs.d.ts +1 -0
  24. package/dist/classes/ovary.d/edit-live-fs.js +9 -13
  25. package/dist/classes/ovary.d/fertilization.js +6 -1
  26. package/dist/classes/ovary.d/initrd.js +11 -15
  27. package/dist/classes/ovary.d/kernel-copy.js +2 -16
  28. package/dist/classes/ovary.d/make-efi.js +8 -5
  29. package/dist/classes/ovary.d/make-squashfs.d.ts +1 -1
  30. package/dist/classes/ovary.d/make-squashfs.js +17 -24
  31. package/dist/classes/ovary.d/merged.d.ts +9 -13
  32. package/dist/classes/ovary.d/merged.js +38 -48
  33. package/dist/classes/ovary.d/produce.d.ts +1 -1
  34. package/dist/classes/ovary.d/produce.js +38 -32
  35. package/dist/classes/ovary.d/syslinux.js +4 -4
  36. package/dist/classes/ovary.d/user-create-live.js +12 -5
  37. package/dist/classes/ovary.d.ts +8 -3
  38. package/dist/classes/ovary.js +8 -3
  39. package/dist/classes/pacman.d/archlinux.js +1 -5
  40. package/dist/classes/pacman.js +2 -1
  41. package/dist/classes/systemctl.d.ts +1 -1
  42. package/dist/classes/systemctl.js +1 -1
  43. package/dist/classes/tailor.js +2 -1
  44. package/dist/classes/utils.d/architecture.d.ts +41 -0
  45. package/dist/classes/utils.d/architecture.js +87 -0
  46. package/dist/classes/utils.d/console-output.d.ts +26 -0
  47. package/dist/classes/utils.d/console-output.js +46 -0
  48. package/dist/classes/utils.d/filesystem.d.ts +53 -0
  49. package/dist/classes/utils.d/filesystem.js +152 -0
  50. package/dist/classes/utils.d/formatters.d.ts +32 -0
  51. package/dist/classes/utils.d/formatters.js +64 -0
  52. package/dist/classes/utils.d/kernel.d.ts +83 -0
  53. package/dist/classes/utils.d/kernel.js +288 -0
  54. package/dist/classes/utils.d/network.d.ts +43 -0
  55. package/dist/classes/utils.d/network.js +133 -0
  56. package/dist/classes/utils.d/package-info.d.ts +55 -0
  57. package/dist/classes/utils.d/package-info.js +137 -0
  58. package/dist/classes/utils.d/snapshot.d.ts +44 -0
  59. package/dist/classes/utils.d/snapshot.js +102 -0
  60. package/dist/classes/utils.d/system.d.ts +63 -0
  61. package/dist/classes/utils.d/system.js +200 -0
  62. package/dist/classes/utils.d/user-interaction.d.ts +39 -0
  63. package/dist/classes/utils.d/user-interaction.js +104 -0
  64. package/dist/classes/utils.d.ts +90 -322
  65. package/dist/classes/utils.js +105 -1013
  66. package/dist/commands/dad.d.ts +1 -0
  67. package/dist/commands/dad.js +1 -0
  68. package/dist/commands/export/pkg.js +6 -6
  69. package/dist/commands/export/tarballs.js +11 -16
  70. package/dist/commands/kill.js +1 -1
  71. package/dist/commands/love.d.ts +1 -0
  72. package/dist/commands/love.js +21 -7
  73. package/dist/commands/pods.d.ts +22 -0
  74. package/dist/commands/pods.js +92 -0
  75. package/dist/commands/produce.d.ts +1 -0
  76. package/dist/commands/produce.js +21 -1
  77. package/dist/commands/update.js +2 -2
  78. package/dist/index.d.ts +6 -52
  79. package/dist/index.js +6 -145
  80. package/dist/krill/classes/krill_enums.d.ts +14 -1
  81. package/dist/krill/classes/krill_enums.js +16 -1
  82. package/dist/krill/classes/prepare.d/partitions.js +3 -3
  83. package/dist/krill/classes/prepare.d.ts +46 -21
  84. package/dist/krill/classes/prepare.js +187 -187
  85. package/dist/krill/classes/sequence.d/add_user.js +21 -3
  86. package/dist/krill/classes/sequence.d/partition.js +2 -2
  87. package/dist/krill/classes/sequence.d.ts +18 -21
  88. package/dist/krill/classes/sequence.js +156 -423
  89. package/dist/krill/components/information.js +13 -7
  90. package/dist/{krill/lib → lib}/kill_me_softly.js +2 -2
  91. package/dist/penguins-eggs_10.1.1-0_amd64.deb +0 -0
  92. package/dist/penguins-eggs_10.1.1-0_amd64.deb.sha256 +1 -0
  93. package/package.json +32 -27
  94. package/perrisbrewery/scripts/postinst +98 -0
  95. package/perrisbrewery/scripts/postrm +82 -0
  96. package/perrisbrewery/scripts/preinst +40 -0
  97. package/perrisbrewery/scripts/prerm +47 -0
  98. package/perrisbrewery/template/control.template +17 -0
  99. package/perrisbrewery/template/dependencies-bionic.yaml +33 -0
  100. package/perrisbrewery/template/dependencies.yaml +37 -0
  101. package/perrisbrewery/template/man.template.md +110 -0
  102. package/pods/README.md +14 -0
  103. package/pods/almalinux.sh +10 -0
  104. package/pods/archlinux.sh +10 -0
  105. package/pods/ci/README.md +5 -0
  106. package/pods/ci/kernel-overlay-install.sh +114 -0
  107. package/pods/ci/minimal/almalinux-container2host.sh +165 -0
  108. package/pods/ci/minimal/archlinux-container2host.sh +125 -0
  109. package/pods/ci/minimal/debian-container2host.sh +173 -0
  110. package/pods/ci/minimal/fedora-container2host.sh +170 -0
  111. package/pods/ci/minimal/manjaro-container2host.sh +123 -0
  112. package/pods/ci/minimal/opensuse-container2host.sh +143 -0
  113. package/pods/ci/penguins-eggs-execute.sh +22 -0
  114. package/pods/ci/penguins-eggs-install.sh +115 -0
  115. package/pods/ci/run +34 -0
  116. package/pods/ci/run-on-almalinux.sh +50 -0
  117. package/pods/ci/run-on-archlinux.sh +64 -0
  118. package/pods/ci/run-on-debian.sh +51 -0
  119. package/pods/ci/run-on-devuan.sh +48 -0
  120. package/pods/ci/run-on-fedora.sh +51 -0
  121. package/pods/ci/run-on-manjaro.sh +61 -0
  122. package/pods/ci/run-on-opensuse.sh +58 -0
  123. package/pods/ci/run-on-rockylinux.sh +51 -0
  124. package/pods/ci/run-on-ubuntu.sh +52 -0
  125. package/pods/debian.sh +23 -0
  126. package/pods/devuan.sh +26 -0
  127. package/pods/fedora.sh +12 -0
  128. package/pods/lmde.sh +22 -0
  129. package/pods/manjaro.sh +10 -0
  130. package/pods/opensuse.sh +12 -0
  131. package/pods/podman.command.sh +85 -0
  132. package/pods/rocky.sh +12 -0
  133. package/pods/run-build-packages-debs.sh +45 -0
  134. package/pods/run-create-debs.sh +23 -0
  135. package/pods/ubuntu.sh +24 -0
  136. package/scripts/_eggs +14 -5
  137. package/scripts/eggs.bash +5 -4
  138. /package/dist/{krill/lib → lib}/kill_me_softly.d.ts +0 -0
@@ -1,1019 +1,111 @@
1
1
  /**
2
- * ./src/classes/utils.tsx
3
- * penguins-eggs v.10.0.0 / ecmascript 2020
4
- * author: Piero Proietti
5
- * email: piero.proietti@gmail.com
6
- * license: MIT
7
- */
8
- import shx from 'shelljs';
9
- import fs from 'fs';
10
- import dns from 'dns';
11
- import path from 'path';
12
- import os from 'os';
13
- import inquirer from 'inquirer';
14
- import { execSync, spawnSync } from 'child_process';
15
- import chalk from 'chalk';
16
- import { Netmask } from 'netmask';
17
- import Distro from './distro.js';
18
- import Diversions from './diversions.js';
19
- // pjson
20
- import { createRequire } from 'module';
21
- const require = createRequire(import.meta.url);
22
- const pjson = require('../../package.json');
23
- // __dirname
24
- const __dirname = path.dirname(new URL(import.meta.url).pathname);
2
+ * ./src/classes/utils.ts
3
+ * penguins-eggs v.10.0.0 / ecmascript 2020
4
+ * author: Piero Proietti
5
+ * email: piero.proietti@gmail.com
6
+ * license: MIT
7
+ *
8
+ * Refactored Utils class - imports from modular utilities
9
+ */
10
+ // Import all utility modules
11
+ import System from './utils.d/system.js';
12
+ import PackageInfo from './utils.d/package-info.js';
13
+ import Network from './utils.d/network.js';
14
+ import Filesystem from './utils.d/filesystem.js';
15
+ import Snapshot from './utils.d/snapshot.js';
16
+ import Architecture from './utils.d/architecture.js';
17
+ import UserInteraction from './utils.d/user-interaction.js';
18
+ import ConsoleOutput from './utils.d/console-output.js';
19
+ import Formatters from './utils.d/formatters.js';
20
+ import Kernel from './utils.d/kernel.js';
25
21
  /**
26
- * Utils: general porpourse utils
27
- * @remarks all the utilities
22
+ * Utils: general purpose utils
23
+ * @remarks all the utilities - refactored into modular structure
28
24
  */
29
25
  export default class Utils {
30
- /**
31
- * Custom function to sort object keys
32
- * @param obj
33
- * @returns
34
- */
35
- static sortObjectKeys(obj) {
36
- const sorted = {};
37
- Object.keys(obj)
38
- .sort()
39
- .forEach(key => {
40
- sorted[key] = obj[key];
41
- });
42
- return sorted;
43
- }
44
- /**
45
- *
46
- * @param file
47
- * @param search
48
- * @returns value
49
- */
50
- static searchOnFile(file = '', search = '') {
51
- const lines = fs.readFileSync(file, 'utf8').split("\n");
52
- let value = '';
53
- lines.forEach(line => {
54
- line = line.replace(/\s+/g, ' '); // Remove multiple spaces with single space
55
- if (line.includes(search)) {
56
- value = line.substring(line.indexOf('=') + 1);
57
- }
58
- });
59
- value = value.replaceAll('"', ''); // Remove "
60
- return value.trim();
61
- }
62
- /**
63
- * Restituisce il prefisso della iso
64
- * @param distroId
65
- * @param codenameId
66
- */
67
- static snapshotPrefix(distroId, codenameId) {
68
- let result = '';
69
- if (codenameId === 'rolling' || codenameId === '') {
70
- result = 'egg-of_' + distroId.toLowerCase() + '-';
71
- if (distroId === 'ALDOS' ||
72
- distroId === 'Almalinux' ||
73
- distroId === 'Alpine' ||
74
- distroId === 'Fedora' ||
75
- distroId === 'Rocky') {
76
- const releaseId = Utils.getOsRelease().VERSION_ID;
77
- result = 'egg-of_' + distroId.toLowerCase() + '-' + releaseId.trim() + '-';
78
- }
79
- }
80
- else {
81
- result = 'egg-of_' + distroId.toLowerCase() + '-' + codenameId.toLowerCase() + '-';
82
- }
83
- result = result.replace(`/`, '-');
84
- return result;
85
- }
86
- /**
87
- * isSystemd
88
- */
89
- static isSystemd() {
90
- const isSystemd = fs.readFileSync("/proc/1/comm").includes('systemd');
91
- return isSystemd;
92
- }
93
- /**
94
- * isSysvinit
95
- */
96
- static isSysvinit() {
97
- let isSysvinit = false;
98
- if (!this.isOpenRc()) {
99
- isSysvinit = fs.readFileSync("/proc/1/comm").includes('init');
100
- }
101
- return isSysvinit;
102
- }
103
- /**
104
- * isOpenRc
105
- */
106
- static isOpenRc() {
107
- let isOpenRc = false;
108
- try {
109
- execSync('command -v openrc');
110
- isOpenRc = true;
111
- }
112
- catch (error) {
113
- isOpenRc = false;
114
- }
115
- return isOpenRc;
116
- }
117
- /**
118
- * ricava path per vmlinuz
119
- * Normalmente cerca BOOT_IMAGE
120
- * BOOT_IMAGE=/boot/vmlinuz-5.16.0-3-amd64 root=UUID=13768873-d6ba-4ae5-9e14-b5011f5aa31c ro quiet splash resume=UUID=beafb9b4-c429-4e1f-a268-4270b63a14e6
121
- * se non è presente, come nel caso di Franco, cerca initrd e ricostruisce vmlinuz
122
- * ro root=UUID=3dc0f202-8ac8-4686-9316-dddcec060c48 initrd=boot\initrd.img-5.15.0-0.bpo.3-amd64 // Conidi
123
- */
124
- static vmlinuz() {
125
- let distro = new Distro();
126
- let vmlinuz = '';
127
- // find BOOT_IMAGE /proc/cmdline
128
- const cmdline = fs.readFileSync('/proc/cmdline', 'utf8').split(" ");
129
- cmdline.forEach(cmd => {
130
- if (cmd.includes('BOOT_IMAGE')) {
131
- vmlinuz = cmd.substring(cmd.indexOf('=') + 1);
132
- // patch per fedora BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6.9.9-200.fc40.x86_64
133
- if (vmlinuz.includes(")")) {
134
- vmlinuz = cmd.substring(cmd.indexOf(')') + 1);
135
- }
136
- if (!fs.existsSync(vmlinuz)) {
137
- if (fs.existsSync(`/boot/${vmlinuz}`)) {
138
- vmlinuz = `/boot/${vmlinuz}`;
139
- }
140
- }
141
- }
142
- });
143
- /**
144
- * BOOT_IMAGE not found in /proc/cmdline
145
- * sample: initrd=\initramfs-6.11.10-300.fc41.x86_64.img root=/dev/sda3 rw
146
- */
147
- if (vmlinuz === '') {
148
- cmdline.forEach(cmd => {
149
- if (cmd.includes('initrd=')) {
150
- let initrd = cmd.substring(cmd.indexOf('initramfs-') + 10);
151
- let version = initrd.substring(0, initrd.indexOf('.img'));
152
- vmlinuz = `/boot/efi/vmlinuz-${version}`;
153
- }
154
- });
155
- }
156
- // btrfs: eg: /@root/boot/vmlinuz
157
- if (vmlinuz.indexOf('@')) {
158
- let subvolumeEnd = vmlinuz.indexOf('/', vmlinuz.indexOf('@'));
159
- vmlinuz = vmlinuz.substring(subvolumeEnd);
160
- }
161
- if (process.arch === 'arm64') {
162
- const kernelVersion = shx.exec('uname -r', { silent: true }).stdout.trim();
163
- vmlinuz = `/boot/vmlinuz-${kernelVersion}`;
164
- }
165
- /**
166
- * if not exists exit
167
- */
168
- if (!fs.existsSync(vmlinuz) && !Utils.isLive()) {
169
- console.log(vmlinuz + ' not exists!');
170
- process.exit();
171
- }
172
- return vmlinuz;
173
- }
174
- /**
175
- * ricava path per initrdImg
176
- */
177
- static initrdImg() {
178
- const vmlinuz = Utils.vmlinuz();
179
- const path = vmlinuz.substring(0, vmlinuz.lastIndexOf('/')) + '/';
180
- let initrd = '';
181
- let separator = '';
182
- let version = '';
183
- let suffix = '';
184
- let distro = new Distro();
185
- if (distro.familyId === 'alpine') {
186
- initrd = 'initramfs';
187
- separator = '-';
188
- version = 'lts';
189
- }
190
- else if (distro.familyId === 'archlinux') {
191
- initrd = 'initramfs';
192
- separator = '-';
193
- version = 'linux';
194
- suffix = '.img';
195
- if (Diversions.isManjaroBased(distro.distroId)) {
196
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
197
- }
198
- }
199
- else if (distro.familyId === 'debian') {
200
- initrd = 'initrd.img';
201
- separator = "-";
202
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
203
- }
204
- else if (distro.familyId === 'fedora') {
205
- initrd = 'initramfs';
206
- separator = '-';
207
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
208
- suffix = '.img';
209
- }
210
- else if (distro.familyId === 'openmamba') {
211
- initrd = 'initramfs';
212
- separator = '-';
213
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
214
- }
215
- else if (distro.familyId === 'aldos') {
216
- initrd = 'initramfs';
217
- separator = '-';
218
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
219
- }
220
- else if (distro.familyId === 'opensuse') {
221
- initrd = 'initrd';
222
- separator = '-';
223
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
224
- }
225
- else if (distro.familyId === 'voidlinux') {
226
- initrd = 'initramfs';
227
- separator = '-';
228
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
229
- suffix = '.img';
230
- }
231
- // manjaro eredita da arch
232
- if (distro.distroId === 'Manjaro') {
233
- version = vmlinuz.substring(vmlinuz.indexOf('-') + 1);
234
- }
235
- initrd = path + initrd + separator + version + suffix;
236
- return initrd;
237
- }
238
- /**
239
- * Occore vedere un modo per creare machine-id dove non esiste
240
- */
241
- static machineId() {
242
- let result = '';
243
- if (fs.existsSync('/etc/machine-id')) {
244
- result = fs.readFileSync('/etc/machine-id', 'utf-8').trim();
245
- }
246
- else if (fs.existsSync('/var/lib/dbus/machine-id')) {
247
- result = fs.readFileSync('/var/lib/dbus/machine-id', 'utf-8').trim();
248
- }
249
- return result;
250
- }
251
- /**
252
- *
253
- * @param msg
254
- */
255
- static warning(msg = '') {
256
- console.log(pjson.shortName + ' >>> ' + chalk.cyanBright(msg) + '.');
257
- }
258
- static error(msg = '') {
259
- console.error(pjson.shortName + ' >>> ' + chalk.bgMagentaBright(chalk.whiteBright(msg)) + '.');
260
- }
261
- /**
262
- * Return the primary user's name
263
- */
264
- static async getPrimaryUser() {
265
- const { execSync } = require('child_process');
266
- let primaryUser = '';
267
- try {
268
- // Attempt to get the user from logname
269
- primaryUser = execSync('/usr/bin/logname 2>/dev/null', { encoding: 'utf-8' }).trim();
270
- }
271
- catch (error) {
272
- // console.log("logname failed, so we continue with other methods")
273
- }
274
- if (primaryUser === 'root') {
275
- primaryUser = '';
276
- }
277
- if (primaryUser === '') {
278
- try {
279
- // Check if doas is installed and get the DOAS_USER
280
- execSync('command -v doas', { stdio: 'ignore' });
281
- primaryUser = execSync('echo $DOAS_USER', { encoding: 'utf-8' }).trim();
282
- }
283
- catch (error) {
284
- // console.log("doas is not installed or DOAS_USER is not set, continue with the next method")
285
- }
286
- }
287
- if (primaryUser === '') {
288
- try {
289
- // Check for the SUDO_USER
290
- primaryUser = execSync('echo $SUDO_USER', { encoding: 'utf-8' }).trim();
291
- }
292
- catch (error) {
293
- // console.log("SUDO_USER is not set, continue with the next method")
294
- }
295
- }
296
- if (primaryUser === '') {
297
- // console.log("Fallback to the USER environment variable")
298
- primaryUser = process.env.USER || '';
299
- }
300
- if (primaryUser === '') {
301
- console.error('Cannot determine the primary user.');
302
- process.exit(1);
303
- }
304
- return primaryUser;
305
- }
306
- /**
307
- * restituisce uuid
308
- * @param device
309
- */
310
- static uuid(device) {
311
- const uuid = shx.exec(`blkid -s UUID -o value ${device}`).stdout.trim();
312
- return uuid;
313
- }
314
- /**
315
- *
316
- * @param device
317
- * @returns
318
- */
319
- static uuidGen() {
320
- const uuid = shx.exec(`uuidgen`, { silent: true }).stdout.trim();
321
- return uuid;
322
- }
323
- /**
324
- *
325
- * @param date
326
- */
327
- static formatDate(date) {
328
- const d = new Date(date);
329
- let month = String(d.getMonth() + 1);
330
- let day = String(d.getDate());
331
- const year = d.getFullYear();
332
- let hh = String(d.getHours());
333
- let mm = String(d.getMinutes());
334
- if (month.length < 2) {
335
- month = '0' + month;
336
- }
337
- if (day.length < 2) {
338
- day = '0' + day;
339
- }
340
- if (hh.length < 2) {
341
- hh = '0' + hh;
342
- }
343
- if (mm.length < 2) {
344
- mm = '0' + mm;
345
- }
346
- return [year, month, day].join('-') + '_' + hh + mm;
347
- }
348
- /**
349
- * return the name of the package: penguins-eggs
350
- * @returns penguins-eggs
351
- */
352
- static getPackageName() {
353
- return pjson.shortName;
354
- }
355
- /**
356
- * Count the eggs present in the nest
357
- * @returns {number} Numero degli snapshot presenti
358
- */
359
- static getSnapshotCount(snapshot_dir = '/') {
360
- if (fs.existsSync(snapshot_dir)) {
361
- const files = fs.readdirSync(snapshot_dir);
362
- let nIsos = 0;
363
- for (const f of files) {
364
- if (f.endsWith('.iso')) {
365
- nIsos++;
366
- }
367
- }
368
- return nIsos;
369
- }
370
- return 0;
371
- }
372
- /**
373
- * Get the syze of the snapshot
374
- * @returns {string} grandezza dello snapshot in Byte
375
- */
376
- static getSnapshotSize(snapshot_dir = '/') {
377
- let fileSizeInBytes = 0;
378
- const size = shx.exec(`/usr/bin/find ${snapshot_dir} -maxdepth 1 -type f -name '*.iso' -exec du -sc {} + | tail -1 | awk '{print $1}'`, { silent: true }).stdout.trim();
379
- if (size === '') {
380
- fileSizeInBytes = 0;
381
- }
382
- else {
383
- fileSizeInBytes = Number(size);
384
- }
385
- return fileSizeInBytes;
386
- }
387
- /**
388
- * uefiArch
389
- * @returns arch
390
- */
391
- static uefiArch() {
392
- let arch = '';
393
- if (process.arch === 'ia32') {
394
- arch = 'i386';
395
- //
396
- if (shx.exec('uname -m', { silent: true }).stdout.trim() === 'x86_64') {
397
- arch = 'amd64';
398
- }
399
- }
400
- else if (process.arch === 'x64') {
401
- arch = 'amd64';
402
- }
403
- else if (process.arch === 'arm64') {
404
- arch = 'arm64';
405
- }
406
- return arch;
407
- }
408
- /**
409
- * i386-pc,
410
- * i386-efi,
411
- * x86_64-efi,
412
- * arm64-efi,
413
- *
414
- * ATTEMZIONE: install efibootmgr
415
- *
416
- * Fedora/RHEL have i386-pc
417
- */
418
- static uefiFormat() {
419
- let format = '';
420
- if (process.arch === 'ia32') {
421
- format = 'i386-efi';
422
- if (shx.exec('uname -m', { silent: true }).stdout.trim() === 'x86_64') {
423
- format = 'x86_64-efi';
424
- }
425
- }
426
- else if (process.arch === 'x64') {
427
- format = 'x86_64-efi';
428
- }
429
- else if (process.arch === 'arm64') {
430
- format = 'arm64-efi';
431
- }
432
- return format;
433
- }
434
- /**
435
- *
436
- * @returns
437
- */
438
- static usrLibPath() {
439
- let path = '';
440
- if (process.arch === 'x64') {
441
- path = 'x86_64-linux-gnu';
442
- }
443
- else if (process.arch === 'arm64') {
444
- path = 'aarch64-linux-gnu';
445
- }
446
- return path;
447
- }
448
- /**
449
- *
450
- * @param prefix
451
- * @param backup
452
- * @returns
453
- */
454
- static getPrefix(prefix, backup = false) {
455
- if (backup) {
456
- if (prefix.substring(0, 7) === 'egg-of_') {
457
- prefix = 'egg-bk_' + prefix.substring(7);
458
- }
459
- else {
460
- prefix = 'egg-bk_' + prefix;
461
- }
462
- }
463
- return prefix;
464
- }
465
- /**
466
- *
467
- * @param volid
468
- */
469
- static getVolid(volid = 'unknown') {
470
- // // 28 + 4 .iso = 32 lunghezza max di volid
471
- if (volid.length >= 32) {
472
- volid = volid.substring(0, 32);
473
- }
474
- return volid;
475
- }
476
- /**
477
- * Return postfix
478
- * @param basename
479
- * @returns eggName
480
- */
481
- static getPostfix() {
482
- let postfix = '_' + Utils.formatDate(new Date()) + '.iso';
483
- return postfix;
484
- }
485
- /**
486
- * Calculate the space used on the disk
487
- * @return {void}
488
- */
489
- static getUsedSpace() {
490
- let fileSizeInBytes = 0;
491
- if (this.isLive()) {
492
- fileSizeInBytes = 0; // this.getLiveRootSpace()
493
- }
494
- else {
495
- fileSizeInBytes = Number(shx.exec(`df /home | /usr/bin/awk 'NR==2 {print $3}'`, {
496
- silent: true
497
- }).stdout);
498
- }
499
- return fileSizeInBytes;
500
- }
501
- /**
502
- * Extimate the linuxfs dimension
503
- * probably is better to rename it as
504
- * getLiveSpaceRootNeed
505
- * @returns {number} Byte
506
- */
507
- static getLiveRootSpace(type = 'debian-live') {
508
- let squashFs = '/run/live/medium/live/filesystem.squashfs';
509
- if (type === 'mx') {
510
- squashFs = '/live/boot-dev/antiX/linuxfs';
511
- }
512
- // Ottengo la dimensione del file compresso
513
- const compressedFs = fs.statSync(squashFs).size;
514
- // get compression factor by reading the linuxfs squasfs file, if available
515
- const compressedFs_compression_type = shx.exec(`dd if=${compressedFs} bs=1 skip=20 count=2 status=none 2>/dev/null| /usr/bin/od -An -tdI`);
516
- let compression_factor = 0;
517
- if (compressedFs_compression_type === '1') {
518
- compression_factor = 37; // gzip
519
- }
520
- else if (compressedFs_compression_type === '2') {
521
- compression_factor = 52; // lzo, not used by antiX
522
- }
523
- else if (compressedFs_compression_type === '3') {
524
- compression_factor = 52; // lzma, not used by antiX
525
- }
526
- else if (compressedFs_compression_type === '4') {
527
- compression_factor = 31; // xz
528
- }
529
- else if (compressedFs_compression_type === '5') {
530
- compression_factor = 52; // lz4
531
- }
532
- else {
533
- compression_factor = 30; // anything else or linuxfs not reachable (toram), should be pretty conservative
534
- }
535
- let rootfs_file_size = 0;
536
- const linuxfs_file_size = (Number(shx.exec('df /live/linux --output=used --total | /usr/bin/tail -n1').stdout.trim()) * 1024 * 100) / compression_factor;
537
- if (fs.existsSync('/live/persist-root')) {
538
- rootfs_file_size = Number(shx.exec('df /live/persist-root --output=used --total | /usr/bin/tail -n1').stdout.trim()) * 1024;
539
- }
540
- let rootSpaceNeeded;
541
- if (type === 'mx') {
542
- /**
543
- * add rootfs file size to the calculated linuxfs file size. Probaby conservative, as rootfs will likely have some overlap with linuxfs
544
- */
545
- rootSpaceNeeded = linuxfs_file_size + rootfs_file_size;
546
- }
547
- else {
548
- rootSpaceNeeded = linuxfs_file_size;
549
- }
550
- return rootSpaceNeeded / 1073741824.0; // Converte in GB
551
- }
552
- /**
553
- * Return true if i686 architecture
554
- * @remarks to move in Utils
555
- * @returns {boolean} true se l'architettura è i686
556
- */
557
- static isi686() {
558
- return process.arch === 'ia32';
559
- }
560
- /**
561
- * Controlla se è un pacchetto deb
562
- * /usr/lib/penguins-eggs/bin/node
563
- */
564
- static isDebPackage() {
565
- let ret = false;
566
- //if (process.execPath !== '/usr/bin/node') {
567
- if (process.execPath === '/usr/lib/penguins-eggs/bin/node') {
568
- ret = true;
569
- }
570
- return ret;
571
- }
572
- /**
573
- * Controlla se è un pacchetto sorgente
574
- */
575
- static isSources() {
576
- let ret = false;
577
- if (__dirname.substring(0, 6) === '/home/') {
578
- ret = true;
579
- }
580
- return ret;
581
- }
582
- /**
583
- * Controlla se è un pacchetto npm
584
- */
585
- static isNpmPackage() {
586
- return !(this.isDebPackage() || this.isSources());
587
- }
588
- /**
589
- *
590
- */
591
- static rootPenguin() {
592
- return path.resolve(__dirname, '../../');
593
- }
594
- /**
595
- * return the short name of the package: eggs
596
- * @returns eggs
597
- */
598
- static getFriendName() {
599
- return pjson.shortName;
600
- }
601
- /**
602
- * return the version of the package
603
- * @returns version example 8.0.0
604
- */
605
- static getPackageVersion() {
606
- return pjson.version;
607
- }
608
- /**
609
- * Get author name
610
- */
611
- static getAuthorName() {
612
- return 'Piero Proietti piero.proietti@gmail.com';
613
- }
614
- /**
615
- * Return the Debian version
616
- * @returns {number} Versione di Debian
617
- */
618
- static getDebianVersion() {
619
- const cmd = "cat /etc/debian_version | /usr/bin/cut -f1 -d'.'";
620
- const version = Number(shx.exec(cmd, { silent: true }).stdout);
621
- return version;
622
- }
623
- /**
624
- * Return true if live system
625
- * @returns {boolean} isLive
626
- */
627
- static isLive() {
628
- let retVal = false;
629
- const paths = [
630
- '/lib/live/mount', // debian-live
631
- '/lib/live/mount/rootfs/filesystem.squashfs', // ubuntu bionic
632
- '/live/aufs', // mx-linux
633
- '/media/root-rw', // AlpineLinux
634
- '/run/archiso/airootfs', // Arch
635
- '/run/miso/sfs/livefs', // Manjarolinux
636
- '/run/rootfsbase' // Fedora
637
- ];
638
- for (let i = 0; i < paths.length; i++) {
639
- if (Utils.isMountpoint(paths[i])) {
640
- retVal = true;
641
- }
642
- }
643
- return retVal;
644
- }
645
- /**
646
- * Ritorna vero se path è un mountpoint
647
- * @param path
648
- */
649
- static isMountpoint(path = '') {
650
- const cmd = `mountpoint -q ${path}`;
651
- // return 0 if the directory is a mountpoint, non-zero if not.
652
- const result = shx.exec(cmd, { silent: true }).code;
653
- return result === 0;
654
- }
655
- /**
656
- *
657
- * @param device
658
- * @returns
659
- */
660
- static isBlockDevice(device = '') {
661
- const cmd = `lsblk -d -o name | grep ${device}`;
662
- const result = shx.exec(cmd, { silent: true }).code;
663
- return result === 0;
664
- }
665
- /**
666
- * return true if eggs run as root
667
- * @returns isRoot
668
- */
669
- static isRoot(command = '') {
670
- if (process.getuid && process.getuid() === 0) {
671
- return true;
672
- }
673
- return false;
674
- }
675
- /**
676
- *
677
- * @param command
678
- */
679
- static useRoot(command = '') {
680
- Utils.titles(pjson.shortName + ' ' + command + ` need to run with root privileges. Please, prefix it with sudo`);
681
- }
682
- /**
683
- * get the kernel version
684
- */
685
- static kernelVersion() {
686
- return os.release();
687
- }
688
- /**
689
- * return the name of network device
690
- */
691
- static async iface() {
692
- // return shx.exec(`ifconfig | awk 'FNR==1 { print $1 }' | tr --d :`, { silent: true }).stdout.trim()
693
- const interfaces = Object.keys(os.networkInterfaces());
694
- let netDeviceName = '';
695
- for (const k in interfaces) {
696
- if (interfaces[k] != 'lo') {
697
- netDeviceName = interfaces[k];
698
- }
699
- }
700
- return netDeviceName;
701
- }
702
- /**
703
- * address
704
- */
705
- static address() {
706
- const interfaces = os.networkInterfaces();
707
- let address = '';
708
- if (interfaces !== undefined) {
709
- for (const devName in interfaces) {
710
- const iface = interfaces[devName];
711
- if (iface !== undefined) {
712
- for (const alias of iface) {
713
- if (alias.family === 'IPv4' &&
714
- alias.address !== '127.0.0.1' &&
715
- !alias.internal) {
716
- // take just the first!
717
- if (address === '') {
718
- address = alias.address;
719
- }
720
- }
721
- }
722
- }
723
- }
724
- }
725
- return address;
726
- }
727
- /**
728
- * netmask
729
- */
730
- static netmask() {
731
- const interfaces = os.networkInterfaces();
732
- let netmask = '';
733
- if (interfaces !== undefined) {
734
- for (const devName in interfaces) {
735
- const iface = interfaces[devName];
736
- if (iface !== undefined) {
737
- for (const alias of iface) {
738
- if (alias.family === 'IPv4' &&
739
- alias.address !== '127.0.0.1' &&
740
- !alias.internal) {
741
- // take just the first!
742
- if (netmask === '') {
743
- netmask = alias.netmask;
744
- }
745
- }
746
- }
747
- }
748
- }
749
- }
750
- return netmask;
751
- }
752
- /**
753
- * cidr
754
- */
755
- static cidr() {
756
- const interfaces = os.networkInterfaces();
757
- let cidr = '';
758
- if (interfaces !== undefined) {
759
- for (const devName in interfaces) {
760
- const iface = interfaces[devName];
761
- if (iface !== undefined) {
762
- for (const alias of iface) {
763
- if (alias.family === 'IPv4' &&
764
- alias.address !== '127.0.0.1' &&
765
- !alias.internal) {
766
- // take just the first!
767
- if (cidr === '') {
768
- if (alias.cidr !== null) {
769
- cidr = alias.cidr;
770
- }
771
- }
772
- }
773
- }
774
- }
775
- }
776
- }
777
- return cidr;
778
- }
779
- /**
780
- *
781
- * broadcast
782
- */
783
- static broadcast() {
784
- let n = new Netmask(Utils.cidr());
785
- return n.broadcast;
786
- }
787
- /**
788
- * dns
789
- */
790
- static getDns() {
791
- return dns.getServers();
792
- }
793
- /**
794
- * getDomain
795
- */
796
- static getDomain() {
797
- return shx.exec('domainname', { silent: true }).stdout.trim();
798
- // return shx.exec(`route -n | grep 'UG[ \t]' | awk '{print $2}'`, { silent: true }).stdout.trim()
799
- }
800
- /**
801
- * @returns gateway
802
- */
803
- static gateway() {
804
- return shx.exec(`ip r | grep 'default' | awk '{print $3}'`, { silent: true }).stdout.trim();
805
- //return shx.exec(`route -n | grep 'UG[ \t]' | awk '{print $2}'`, { silent: true }).stdout.trim()
806
- }
807
- /**
808
- * write a file
809
- * @param file
810
- * @param text
811
- */
812
- static write(file, text) {
813
- text = text.trim() + '\n';
814
- file = file.trim();
815
- fs.writeFileSync(file, text);
816
- }
817
- /**
818
- *
819
- * @param file
820
- * @param cmd
821
- */
822
- static writeX(file, cmd) {
823
- let text = `#!/bin/sh\n\n`;
824
- text += `# Created at: ${Utils.formatDate(new Date())}\n`;
825
- text += `# By: penguins_eggs v. ${Utils.getPackageVersion()}\n`;
826
- text += `# ==> Perri\'s Brewery edition <== \n\n`;
827
- text += cmd;
828
- Utils.write(file, text);
829
- shx.chmod('+x', file);
830
- }
831
- /**
832
- *
833
- * @param file
834
- * @param cmd
835
- */
836
- static writeXs(file, cmds) {
837
- let cmd = '';
838
- for (const elem of cmds) {
839
- cmd += elem + '\n';
840
- }
841
- Utils.writeX(file, cmd);
842
- }
843
- /**
844
- *
845
- * @param msg
846
- */
847
- static async customConfirm(msg = 'Select yes to continue... ') {
848
- const varResult = await Utils.customConfirmCompanion(msg);
849
- const result = JSON.parse(varResult);
850
- if (result.confirm === 'Yes') {
851
- return true;
852
- }
853
- else {
854
- return false;
855
- }
856
- }
857
- /**
858
- *
859
- * @param msg
860
- */
861
- static async customConfirmCompanion(msg = 'Select yes to continue... ') {
862
- return new Promise(function (resolve) {
863
- const questions = [
864
- {
865
- type: 'list',
866
- name: 'confirm',
867
- message: msg,
868
- choices: ['No', 'Yes'],
869
- default: 'No'
870
- }
871
- ];
872
- inquirer.prompt(questions).then(function (options) {
873
- resolve(JSON.stringify(options));
874
- });
875
- });
876
- }
877
- /**
878
- *
879
- * @param msg
880
- */
881
- static async customConfirmAbort(msg = 'Confirm') {
882
- return new Promise(function (resolve) {
883
- const questions = [
884
- {
885
- type: 'list',
886
- name: 'confirm',
887
- message: msg,
888
- choices: ['No', 'Yes', 'Abort'],
889
- default: 'Yes'
890
- }
891
- ];
892
- inquirer.prompt(questions).then(function (options) {
893
- resolve(JSON.stringify(options));
894
- });
895
- });
896
- }
897
- /**
898
- *
899
- */
900
- static async pressKeyToExit(warming = 'Process will end', procContinue = true) {
901
- Utils.warning(warming);
902
- let msg = 'Press a key to exit...';
903
- if (procContinue) {
904
- msg = 'Press a key to continue...';
905
- }
906
- console.log(msg);
907
- const pressKeyToExit = spawnSync('read _ ', { shell: true, stdio: [0, 1, 2] });
908
- if (!procContinue) {
909
- process.exit(0);
910
- }
911
- }
912
- /**
913
- * titles
914
- * Penguin's are gettings alive!
915
- */
916
- static titles(command = '') {
917
- console.clear();
918
- console.log('');
919
- console.log(' E G G S: the reproductive system of penguins');
920
- console.log('');
921
- console.log(Utils.flag());
922
- console.log('command: ' + chalk.bgBlack.white(command) + '\n');
923
- }
924
- /**
925
- *
926
- * @returns flag
927
- */
928
- static flag() {
929
- return chalk.bgGreen.whiteBright(' ' + pjson.name + ' ') +
930
- chalk.bgWhite.blue(" Perri's Brewery edition ") +
931
- chalk.bgRed.whiteBright(' ver. ' + pjson.version + ' ');
932
- }
933
- /**
934
- *
935
- * @param verbose
936
- */
937
- static setEcho(verbose = false) {
938
- let echo = { echo: false, ignore: true };
939
- if (verbose) {
940
- echo = { echo: true, ignore: false };
941
- }
942
- return echo;
943
- }
944
- /**
945
- *
946
- * @param bytes
947
- * @param decimals
948
- * @returns
949
- */
950
- static formatBytes(bytes, decimals = 2) {
951
- if (bytes === 0)
952
- return '0 Bytes';
953
- const k = 1024;
954
- const dm = decimals < 0 ? 0 : decimals;
955
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
956
- const i = Math.floor(Math.log(bytes) / Math.log(k));
957
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i];
958
- }
959
- /**
960
- *
961
- * @returns wardrobe
962
- */
963
- static async wardrobe() {
964
- let wardrobe = `${os.homedir()}/.wardrobe`;
965
- if (Utils.isRoot()) {
966
- wardrobe = `/home/${await Utils.getPrimaryUser()}/.wardrobe`;
967
- }
968
- return wardrobe;
969
- }
970
- // Se il metodo fa parte di una classe, usa `static`. Altrimenti, rimuovilo.
971
- static getOsRelease() {
972
- const osReleasePath = path.join('/etc', 'os-release');
973
- // Inizializza l'oggetto con valori predefiniti
974
- const osInfo = {
975
- ID: '',
976
- VERSION_ID: '',
977
- VERSION_CODENAME: 'n/a'
978
- };
979
- // Verifica se il file esiste
980
- if (!fs.existsSync(osReleasePath)) {
981
- console.error('/etc/os-release file does not exist.');
982
- return osInfo;
983
- }
984
- // Leggi il contenuto del file
985
- let fileContent;
986
- try {
987
- fileContent = fs.readFileSync(osReleasePath, 'utf8');
988
- }
989
- catch (error) {
990
- console.error('Error reading /etc/os-release:', error);
991
- return osInfo;
992
- }
993
- // Analizza ogni linea
994
- const lines = fileContent.split('\n');
995
- lines.forEach(line => {
996
- if (line.startsWith('#') || line.trim() === '')
997
- return;
998
- const [key, value] = line.split('=');
999
- if (key && value) {
1000
- const trimmedKey = key.trim();
1001
- const trimmedValue = value.trim().replace(/"/g, '');
1002
- // Popola solo le chiavi desiderate
1003
- if (trimmedKey === 'ID') {
1004
- osInfo.ID = trimmedValue;
1005
- }
1006
- else if (trimmedKey === 'VERSION_ID') {
1007
- osInfo.VERSION_ID = trimmedValue;
1008
- }
1009
- else if (trimmedKey === 'VERSION_CODENAME') {
1010
- osInfo.VERSION_CODENAME = trimmedValue;
1011
- }
1012
- }
1013
- });
1014
- // capitalize distroId
1015
- osInfo.ID = osInfo.ID[0].toUpperCase() + osInfo.ID.slice(1).toLowerCase();
1016
- osInfo.VERSION_CODENAME = osInfo.VERSION_CODENAME.toLowerCase();
1017
- return osInfo;
26
+ // ===== SYSTEM UTILITIES =====
27
+ static isContainer = System.isContainer;
28
+ static isSystemd = System.isSystemd;
29
+ static isSysvinit = System.isSysvinit;
30
+ static isOpenRc = System.isOpenRc;
31
+ static isLive = System.isLive;
32
+ static isMountpoint = System.isMountpoint;
33
+ static isBlockDevice = System.isBlockDevice;
34
+ static isRoot = System.isRoot;
35
+ static machineId = System.machineId;
36
+ static getDebianVersion = System.getDebianVersion;
37
+ static getLiveRootSpace = System.getLiveRootSpace;
38
+ // ===== PACKAGE INFO UTILITIES =====
39
+ static getPackageName = PackageInfo.getPackageName;
40
+ static getFriendName = PackageInfo.getFriendName;
41
+ static getPackageVersion = PackageInfo.getPackageVersion;
42
+ static getAuthorName = PackageInfo.getAuthorName;
43
+ static isPackage = PackageInfo.isPackage;
44
+ static isSources = PackageInfo.isSources;
45
+ static isNpmPackage = PackageInfo.isNpmPackage;
46
+ static rootPenguin = PackageInfo.rootPenguin;
47
+ static wardrobe = PackageInfo.wardrobe;
48
+ static getPrimaryUser = PackageInfo.getPrimaryUser;
49
+ // ===== NETWORK UTILITIES =====
50
+ static iface = Network.iface;
51
+ static address = Network.address;
52
+ static netmask = Network.netmask;
53
+ static cidr = Network.cidr;
54
+ static broadcast = Network.broadcast;
55
+ static getDns = Network.getDns;
56
+ static getDomain = Network.getDomain;
57
+ static gateway = Network.gateway;
58
+ // ===== FILESYSTEM UTILITIES =====
59
+ static searchOnFile = Filesystem.searchOnFile;
60
+ static uuid = Filesystem.uuid;
61
+ static uuidGen = Filesystem.uuidGen;
62
+ static getUsedSpace = Filesystem.getUsedSpace;
63
+ static write = Filesystem.write;
64
+ static writeX = Filesystem.writeX;
65
+ static writeXs = Filesystem.writeXs;
66
+ static getOsRelease = Filesystem.getOsRelease;
67
+ // ===== SNAPSHOT UTILITIES =====
68
+ static snapshotPrefix = Snapshot.snapshotPrefix;
69
+ static getSnapshotCount = Snapshot.getSnapshotCount;
70
+ static getSnapshotSize = Snapshot.getSnapshotSize;
71
+ static getPrefix = Snapshot.getPrefix;
72
+ static getVolid = Snapshot.getVolid;
73
+ static getPostfix = Snapshot.getPostfix;
74
+ // ===== ARCHITECTURE UTILITIES =====
75
+ static isi686 = Architecture.isi686;
76
+ static uefiArch = Architecture.uefiArch;
77
+ static uefiFormat = Architecture.uefiFormat;
78
+ static usrLibPath = Architecture.usrLibPath;
79
+ static kernelVersion = Architecture.kernelVersion;
80
+ // ===== USER INTERACTION UTILITIES =====
81
+ static customConfirm = UserInteraction.customConfirm;
82
+ static customConfirmCompanion = UserInteraction.customConfirmCompanion;
83
+ static customConfirmAbort = UserInteraction.customConfirmAbort;
84
+ static pressKeyToExit = UserInteraction.pressKeyToExit;
85
+ static useRoot = UserInteraction.useRoot;
86
+ static setEcho = UserInteraction.setEcho;
87
+ // ===== CONSOLE OUTPUT UTILITIES =====
88
+ static warning = ConsoleOutput.warning;
89
+ static error = ConsoleOutput.error;
90
+ static titles = ConsoleOutput.titles;
91
+ static flag = ConsoleOutput.flag;
92
+ // ===== FORMATTERS UTILITIES =====
93
+ static sortObjectKeys = Formatters.sortObjectKeys;
94
+ static formatDate = Formatters.formatDate;
95
+ static formatBytes = Formatters.formatBytes;
96
+ // ===== KERNEL UTILITIES (already existing) =====
97
+ /**
98
+ * @deprecated Use Kernel.vmlinuz() instead
99
+ */
100
+ static vmlinuz(kernel = '') {
101
+ return Kernel.vmlinuz(kernel);
102
+ }
103
+ /**
104
+ * @deprecated Use Kernel.initramfs() instead
105
+ */
106
+ static initrdImg(kernel = '') {
107
+ return Kernel.initramfs(kernel);
1018
108
  }
1019
109
  }
110
+ // Export individual modules for direct access if needed
111
+ export { System, PackageInfo, Network, Filesystem, Snapshot, Architecture, UserInteraction, ConsoleOutput, Formatters, Kernel };