Penguin's eggs are generated and new birds are ready to fly... https://penguins-eggs.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

626 lines
18 KiB

  1. /**
  2. * penguins-eggs: focal.ts
  3. *
  4. * author: Piero Proietti
  5. * mail: piero.proietti@gmail.com
  6. */
  7. import fs = require('fs')
  8. import yaml = require('js-yaml')
  9. import { IRemix, IDistro } from '../../interfaces'
  10. import { up } from 'inquirer/lib/utils/readline'
  11. const exec = require('../../lib/utils').exec
  12. /**
  13. *
  14. */
  15. export class Focal {
  16. verbose = false
  17. remix: IRemix
  18. user_opt: string
  19. distro: IDistro
  20. displaymanager = false
  21. sourcesTrusted = true
  22. dir = '/etc/calamares/'
  23. dirLocalModules = '/etc/calamares/modules/'
  24. dirGlobalModules = '/usr/lib/x86_64-linux-gnu/calamares/modules/'
  25. constructor(remix: IRemix, distro: IDistro, displaymanager: boolean, user_opt: string, verbose = false) {
  26. this.remix = remix
  27. this.distro = distro
  28. this.user_opt = user_opt
  29. this.verbose = verbose
  30. this.displaymanager = displaymanager
  31. if (process.arch === 'ia32') {
  32. this.dirGlobalModules = '/usr/lib/calamares/modules/'
  33. }
  34. }
  35. /**
  36. *
  37. */
  38. settings() {
  39. const file = this.dir + 'settings.conf'
  40. const content = this.getSettings()
  41. write(file, content, this.verbose)
  42. }
  43. /**
  44. *
  45. */
  46. private getSettings(): string {
  47. // path di ricerca dei moduli
  48. const modulesSearch: string[] = ['local']
  49. // ,'/usr/lib/x86_64-linux-gnu/calamares/modules/'
  50. // Istanze
  51. const instances = [
  52. {
  53. id: 'before_bootloader_mkdirs',
  54. module: 'contextualprocess',
  55. config: 'before_bootloader_mkdirs_context.conf'
  56. },
  57. {
  58. id: 'before_bootloader',
  59. module: 'contextualprocess',
  60. config: 'before_bootloader_context.conf'
  61. },
  62. {
  63. id: 'after_bootloader',
  64. module: 'contextualprocess',
  65. config: 'after_bootloader_context.conf'
  66. },
  67. {
  68. id: 'logs',
  69. module: 'shellprocess',
  70. config: 'shellprocess_logs.conf'
  71. },
  72. {
  73. id: 'bug-LP#1829805',
  74. module: 'shellprocess',
  75. config: 'shellprocess_bug-LP#1829805.conf'
  76. },
  77. {
  78. id: 'add386arch',
  79. module: 'shellprocess',
  80. config: 'shellprocess_add386arch.conf'
  81. }
  82. ]
  83. // moduli da mostrare a video
  84. const show: string[] = ['welcome', 'locale', 'keyboard', 'partition', 'users', 'summary']
  85. // moduli da eseguire
  86. const exec: string[] = []
  87. exec.push('partition')
  88. exec.push('mount')
  89. exec.push('unpackfs')
  90. exec.push('machineid')
  91. exec.push('fstab')
  92. exec.push('locale')
  93. exec.push('keyboard')
  94. exec.push('localecfg')
  95. exec.push('luksbootkeyfile')
  96. exec.push('users')
  97. if (this.displaymanager) {
  98. exec.push('displaymanager')
  99. }
  100. exec.push('networkcfg')
  101. exec.push('hwclock')
  102. exec.push('contextualprocess@before_bootloader_mkdirs')
  103. exec.push('shellprocess@bug-LP#1829805')
  104. exec.push('initramfscfg')
  105. exec.push('initramfs')
  106. exec.push('grubcfg')
  107. exec.push('contextualprocess@before_bootloader')
  108. exec.push('bootloader')
  109. exec.push('contextualprocess@after_bootloader')
  110. exec.push('automirror')
  111. exec.push('shellprocess@add386arch')
  112. exec.push('packages')
  113. exec.push('removeuser')
  114. // exec.push("shellprocess@logs")
  115. exec.push('umount')
  116. const settings = {
  117. 'modules-search': modulesSearch,
  118. instances: instances,
  119. sequence: [{ show: show }, { exec: exec }, { show: ['finished'] }],
  120. branding: this.remix.branding,
  121. 'prompt-install': true,
  122. 'dont-chroot': false,
  123. 'oem-setup': false,
  124. 'disable-cancel': false,
  125. 'disable-cancel-during-exec': false
  126. }
  127. return yaml.safeDump(settings)
  128. }
  129. /**
  130. *
  131. */
  132. modules() {
  133. this.modulePartition()
  134. this.moduleMount()
  135. this.moduleUnpackfs()
  136. this.moduleMachineid()
  137. this.moduleFstab()
  138. this.moduleLocale()
  139. this.moduleKeyboard()
  140. this.moduleLocalecfg()
  141. this.moduleLuksbootkeyfile()
  142. this.moduleUsers()
  143. this.moduleDisplaymanager()
  144. this.moduleNetworkcfg()
  145. this.moduleHwclock()
  146. this.contextualprocess('before_bootloader_mkdirs')
  147. this.shellprocess('bug-LP#1829805')
  148. this.moduleInitramfscfg()
  149. this.moduleInitramfs()
  150. this.moduleGrubcfg()
  151. this.contextualprocess('before_bootloader')
  152. this.moduleBootloader()
  153. this.contextualprocess('after_bootloader')
  154. this.moduleAutomirror()
  155. this.shellprocess('add386arch')
  156. this.modulePackages()
  157. this.moduleRemoveuser()
  158. //this.shellprocess("logs")
  159. this.moduleUmount()
  160. }
  161. /**
  162. * module = name + '.conf0
  163. * shellprocess = 'shellprocess_' + name + '.conf'
  164. * contextualprocess = name + '_context.conf'
  165. *
  166. * module_calamares
  167. * dir = '/usr/lib/calamares/modules/' + name
  168. * name = module.desc
  169. * script =
  170. * @param name
  171. */
  172. private module(name: string, content: string) {
  173. const file = this.dirLocalModules + name + '.conf'
  174. write(file, content, this.verbose)
  175. }
  176. /**
  177. *
  178. * @param process
  179. */
  180. private shellprocess(name: string) {
  181. let text = ''
  182. if (name === 'bug-LP#1829805') {
  183. text += '---\n'
  184. text += 'dontChroot: false\n'
  185. text += 'timeout: 30\n'
  186. text += 'script:\n'
  187. text += '- "touch @@ROOT@@/boot/initrd.img-$(uname -r)"\n'
  188. } else if (name === 'add386arch') {
  189. text += '---\n'
  190. text += 'dontChroot: false\n'
  191. text += 'timeout: 30\n'
  192. text += 'script:\n'
  193. text += '- command: "/usr/bin/dpkg --add-architecture i386"\n'
  194. } else if (name === 'logs') {
  195. text += '---\n'
  196. text += 'dontChroot: true\n'
  197. text += 'timeout: 30\n'
  198. text += 'script:\n'
  199. text += ' - calamares-logs-helper @@ROOT@@\n'
  200. }
  201. let file = this.dirLocalModules + 'shellprocess_' + name + '.conf'
  202. let content = text
  203. write(file, content, this.verbose)
  204. }
  205. /**
  206. *
  207. * @param process
  208. */
  209. private contextualprocess(name: string) {
  210. let text = ''
  211. if (name === 'before_bootloader_mkdirs') {
  212. text += '---\n'
  213. text += 'dontChroot: true\n'
  214. text += 'timeout: 10\n'
  215. text += 'firmwareType:\n'
  216. text += ' efi:\n'
  217. text += ' - -cp /cdrom/casper/vmlinuz @@ROOT@@/boot/vmlinuz-$(uname -r)\n'
  218. text += ' - -mkdir -pv @@ROOT@@/media/cdrom\n'
  219. text += ' - -mount --bind /cdrom @@ROOT@@/media/cdrom\n'
  220. text += ' bios:\n'
  221. text += ' - -cp /cdrom/casper/vmlinuz @@ROOT@@/boot/vmlinuz-$(uname -r)\n'
  222. } else if (name === 'before_bootloader') {
  223. text += '# Make sure the correct bootloader package is installed for EFI.\n'
  224. text += '# Also pull in shim so secureboot has a chance at working.\n'
  225. text += '# Because of edge cases, we ignore BIOS, and do the same\n'
  226. text += '# procedure for all EFI types.\n'
  227. text += '---\n'
  228. text += 'firmwareType:\n'
  229. text += ' bios: "-/bin/true"\n'
  230. text += ' "*":\n'
  231. /**
  232. * modifica per installazione UEFI
  233. */
  234. //text += ' - command: apt-cdrom add -m -d=/media/cdrom/\n'
  235. //text += ' timeout: 10\n'
  236. //text += ' - command: sed -i \' / deb http / d\' /etc/apt/sources.list\n'
  237. //text += ' timeout: 10\n'
  238. /**
  239. * grub-efi-amd64-signed esiste ed è OK
  240. * quello che serve è di montare i vari fsvirtuali e la partizione efi in boot/efi
  241. * quindi:
  242. * grub-install
  243. * grub-update
  244. * e parte
  245. */
  246. text += ' - command: apt-get update\n'
  247. text += ' timeout: 120\n'
  248. text += ' - command: apt install -y --no-upgrade -o Acquire::gpgv::Options::=--ignore-time-conflict grub-efi-$(if grep -q 64 /sys/firmware/efi/fw_platform_size; then echo amd64-signed; else echo ia32; fi)\n'
  249. text += ' timeout: 300\n'
  250. text += ' - command: apt install -y --no-upgrade -o Acquire::gpgv::Options::=--ignore-time-conflict shim-signed\n'
  251. text += ' timeout: 300\n'
  252. } else if (name === 'after_bootloader') {
  253. text += "# Workaround from ubiquity. Ubuntu's grub will want to look in EFI / ubuntu, so\n"
  254. text += "# let's make sure it can find something there.\n"
  255. text += "# This only copies the cfg and doesn't overwrite, this is specifically so\n"
  256. text += "# this doesn't interfere with an Ubuntu installed on the system already.\n"
  257. text += '---\n'
  258. text += 'dontChroot: false\n'
  259. text += 'timeout: 120\n'
  260. text += 'firmwareType:\n'
  261. text += '"*": "-for i in `ls @@ROOT@@/home/`; do rm @@ROOT@@/home/$i/Desktop/lubuntu-calamares.desktop || exit 0; done"\n'
  262. }
  263. let content = text
  264. let file = this.dirLocalModules + name + '_context' + '.conf'
  265. write(file, content, this.verbose)
  266. }
  267. /**
  268. *
  269. */
  270. private modulePartition() {
  271. const partition = yaml.safeDump({
  272. efiSystemPartition: '/boot/efi',
  273. enableLuksAutomatedPartitioning: true,
  274. userSwapChoices: 'none',
  275. drawNestedPartitions: true,
  276. defaultFileSystemType: 'ext4'
  277. })
  278. this.module('partition', partition)
  279. }
  280. /**
  281. *
  282. */
  283. private moduleMount() {
  284. const mount = yaml.safeDump({
  285. extraMounts: [
  286. {
  287. device: 'proc',
  288. fs: 'proc',
  289. mountPoint: '/proc'
  290. },
  291. {
  292. device: 'sys',
  293. fs: 'sysfs',
  294. mountPoint: '/sys'
  295. },
  296. {
  297. device: '/dev',
  298. mountPoint: '/dev',
  299. options: 'bind'
  300. },
  301. {
  302. device: '/dev/pts',
  303. fs: 'devpts',
  304. mountPoint: '/dev/pts'
  305. },
  306. {
  307. device: 'tmpfs',
  308. fs: 'tmpfs',
  309. mountPoint: '/run'
  310. },
  311. {
  312. device: '/run/udev',
  313. mountPoint: '/run/udev',
  314. options: 'bind'
  315. }
  316. ],
  317. extraMountsEfi: [
  318. {
  319. device: 'efivarfs',
  320. fs: 'tmpefivarfsfs',
  321. mountPoint: '/sys/firmware/efi/efivars'
  322. }
  323. ]
  324. })
  325. this.module('mount', mount)
  326. }
  327. /**
  328. *
  329. */
  330. private moduleUnpackfs() {
  331. const unpack = yaml.safeDump({
  332. unpack: [
  333. {
  334. source: this.distro.mountpointSquashFs,
  335. sourcefs: 'squashfs',
  336. destination: ''
  337. }
  338. ]
  339. })
  340. this.module('unpackfs', unpack)
  341. }
  342. /**
  343. *
  344. */
  345. private moduleMachineid() {
  346. const machineid = yaml.safeDump({
  347. systemd: true,
  348. dbus: true,
  349. 'dbus-symlink': true
  350. })
  351. this.module('machineid', machineid)
  352. }
  353. /**
  354. *
  355. */
  356. private moduleFstab() {
  357. const fstab = yaml.safeDump({
  358. mountOptions: {
  359. default: 'defaults,noatime',
  360. btrfs: 'defaults,noatime,space_cache,autodefrag'
  361. },
  362. ssdExtraMountOptions: {
  363. ext4: 'discard',
  364. jfs: 'discard',
  365. xfs: 'discard',
  366. swap: 'discard',
  367. btrfs: 'discard,compress=lzo'
  368. },
  369. crypttabOptions: 'luks,keyscript=/bin/cat'
  370. })
  371. this.module('fstab', fstab)
  372. }
  373. private moduleLocale() {
  374. if (this.verbose) console.log(`calamares: module locale. Nothing to do!`)
  375. }
  376. private moduleKeyboard() {
  377. if (this.verbose) console.log(`calamares: module keyboard. Nothing to do!`)
  378. }
  379. private moduleLocalecfg() {
  380. if (this.verbose) console.log(`calamares: module localecfg. Nothing to do!`)
  381. }
  382. /**
  383. *
  384. */
  385. private moduleUsers() {
  386. const users = yaml.safeDump({
  387. userGroup: 'users',
  388. defaultGroups: ['cdrom', 'floppy', 'sudo', 'audio', 'dip', 'video', 'plugdev', 'netdev', 'lpadmin', 'scanner', 'bluetooth'],
  389. autologinGroup: 'autologin',
  390. sudoersGroup: 'sudo',
  391. setRootPassword: false
  392. })
  393. this.module('users', users)
  394. }
  395. /**
  396. *
  397. */
  398. private moduleDisplaymanager() {
  399. const displaymanager_not_used = yaml.safeDump({
  400. displaymanager: 'lightdm',
  401. basicSetup: false,
  402. sysconfigSetup: false
  403. })
  404. const displaymanager = require('./modules/displaymanager').displaymanager
  405. this.module('displaymanager', displaymanager())
  406. }
  407. private moduleNetworkcfg() {
  408. if (this.verbose) console.log(`calamares: module networkcfg. Nothing to do!`)
  409. }
  410. private moduleHwclock() {
  411. if (this.verbose) console.log(`calamares: module hwclock. Nothing to do!`)
  412. }
  413. private moduleServicesSystemd() {
  414. if (this.verbose) console.log(`calamares: module servives-systemd. Nothing to do!`)
  415. }
  416. private moduleGrubcfg() {
  417. if (this.verbose) console.log(`calamares: module grubcfg. Nothing to do!`)
  418. }
  419. /**
  420. *
  421. */
  422. private moduleBootloader() {
  423. const bootloader = yaml.safeDump({
  424. efiBootLoader: 'grub',
  425. kernel: '/vmlinuz-linux',
  426. img: '/initramfs-linux.img',
  427. fallback: '/initramfs-linux-fallback.img',
  428. timeout: 10,
  429. grubInstall: 'grub-install',
  430. grubMkconfig: 'grub-mkconfig',
  431. grubCfg: '/boot/grub/grub.cfg',
  432. grubProbe: 'grub-probe',
  433. efiBootMgr: 'efibootmgr',
  434. installEFIFallback: false
  435. })
  436. this.module('bootloader', bootloader)
  437. }
  438. /**
  439. * create module packages.conf
  440. */
  441. private modulePackages() {
  442. const packages = require('./modules/packages').packages
  443. this.module('packages', packages())
  444. }
  445. private moduleLuksbootkeyfile() {
  446. if (this.verbose) console.log(`calamares: module luksbootkeyfile. Nothing to do!`)
  447. }
  448. /**
  449. *
  450. */
  451. private module_luksopenswaphookcfg() {
  452. const lksopenswaphookcfg = yaml.safeDump({
  453. configFilePath: '/etc/openswap.conf'
  454. })
  455. this.module('lksopenswaphookcfg', lksopenswaphookcfg)
  456. }
  457. private modulePlymouthcfg() {
  458. if (this.verbose) console.log(`calamares: module plymouthcfg. Nothing to do!`)
  459. }
  460. private moduleInitramfscfg() {
  461. if (this.verbose) console.log(`calamares: module initramfscfg. Nothing to do!`)
  462. }
  463. /**
  464. *
  465. */
  466. private moduleRemoveuser() {
  467. const removeuser = yaml.safeDump({ username: this.user_opt })
  468. this.module('removeuser', removeuser)
  469. }
  470. private moduleInitramfs() {
  471. if (this.verbose) console.log(`calamares: module initramfs. Nothing to do!`)
  472. }
  473. private moduleUmount() {
  474. if (this.verbose) console.log(`calamares: module unmount. Nothing to do!`)
  475. }
  476. /**
  477. * ====================================================================================
  478. * M O D U L E S C A L A M A R E S
  479. * ====================================================================================
  480. */
  481. /**
  482. * Automirror
  483. * Pythonm
  484. */
  485. private async moduleAutomirror() {
  486. const name = 'automirror'
  487. const dirModule = this.dirGlobalModules + name + '/'
  488. if (!fs.existsSync(dirModule)) {
  489. fs.mkdirSync(dirModule)
  490. }
  491. const automirror = yaml.safeDump({
  492. baseUrl: 'archive.ubuntu.com',
  493. distribution: 'Ubuntu',
  494. geoip: {
  495. style: 'json',
  496. url: 'http s://ipapi.co/json'
  497. }
  498. })
  499. write(dirModule + 'automirror.conf', automirror, this.verbose)
  500. // Creo anche un config in local con la distro particolare, esempio: lubuntu, ulyana
  501. const automirrorModules = yaml.safeDump({
  502. baseUrl: 'archive.ubuntu.com',
  503. distribution: 'Lubuntu',
  504. geoip: {
  505. style: 'json',
  506. url: 'https://ipapi.co/json'
  507. }
  508. })
  509. write('/etc/calamares/modules/' + 'automirror.conf', automirrorModules)
  510. // desc
  511. const desc = yaml.safeDump({
  512. type: 'job',
  513. name: 'automirror',
  514. interface: 'python',
  515. script: 'main.py'
  516. })
  517. write(dirModule + 'module.desc', desc, this.verbose)
  518. // py
  519. const scriptAutomirror = require('./calamares-modules/scripts/automirror').automirror
  520. const scriptFile = dirModule + 'main.py'
  521. write(scriptFile, scriptAutomirror(this.distro.versionId), this.verbose)
  522. await exec(`chmod +x ${scriptFile}`)
  523. }
  524. private async moduleCreatetmp() {
  525. const name = 'create-tmp'
  526. const dirModule = this.dirGlobalModules + name + '/'
  527. if (!fs.existsSync(dirModule)) {
  528. fs.mkdirSync(dirModule)
  529. }
  530. const createTmp = require('./calamares-modules/desc/create-tmp').createTmp
  531. write(dirModule + 'module.desc', createTmp(), this.verbose)
  532. const scriptcreateTmp = require('./calamares-modules/scripts/create-tmp').createTmp
  533. const scriptFile = `/usr/sbin/${name}`
  534. write(scriptFile, scriptcreateTmp(), this.verbose)
  535. await exec(`chmod +x ${scriptFile}`)
  536. }
  537. /**
  538. *
  539. */
  540. private async moduleBootloaderconfig() {
  541. const name = 'bootloader-config'
  542. const dirModule = this.dirGlobalModules + name
  543. if (!fs.existsSync(dirModule)) {
  544. fs.mkdirSync(dirModule)
  545. }
  546. const bootloaderConfig = require('./calamares-modules/desc/bootloader-config').bootloaderConfig
  547. write(dirModule + 'module.desc', bootloaderConfig(), this.verbose)
  548. const scriptBootloaderConfig = require('./calamares-modules/scripts/bootloader-config').bootloaderConfig
  549. const scriptFile = `/usr/sbin/` + 'bootloader-config'
  550. write(scriptFile, scriptBootloaderConfig(), this.verbose)
  551. await exec(`chmod +x ${scriptFile}`)
  552. }
  553. }
  554. /**
  555. *
  556. * @param file
  557. * @param content
  558. * @param verbose
  559. */
  560. function write(file: string, content: string, verbose = false) {
  561. if (verbose) {
  562. console.log(`calamares: create ${file}`)
  563. }
  564. // console.log(content)
  565. fs.writeFileSync(file, content, 'utf8')
  566. }