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.
 
 
 
 
 

634 lines
17 KiB

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