penguins-eggs 10.0.28 → 10.0.31

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