penguins-eggs 10.0.53 → 10.0.54

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