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.
 
 
 
 
 

535 lines
14 KiB

  1. /**
  2. * penguins-eggs: devuan.ts
  3. *
  4. * author: Piero Proietti
  5. * mail: piero.proietti@gmail.com
  6. * al momento escludo solo machineid
  7. */
  8. import fs = require('fs')
  9. import yaml = require('js-yaml')
  10. import { IRemix, IDistro } from '../../interfaces'
  11. const exec = require('../../lib/utils').exec
  12. /**
  13. *
  14. */
  15. export class Beowulf {
  16. verbose = false
  17. remix: IRemix
  18. distro: IDistro
  19. displaymanager = false
  20. user_opt: string
  21. dirGlobalModules = '/usr/lib/x86_64-linux-gnu/calamares/modules/'
  22. /**
  23. * @param remix
  24. * @param distro
  25. * @param displaymanager
  26. * @param verbose
  27. */
  28. constructor(remix: IRemix, distro: IDistro, displaymanager: boolean, user_opt: string, verbose = false) {
  29. this.remix = remix
  30. this.distro = distro
  31. this.user_opt = user_opt
  32. this.verbose = verbose
  33. this.displaymanager = displaymanager
  34. if (process.arch === 'ia32') {
  35. this.dirGlobalModules = '/usr/lib/calamares/modules/'
  36. }
  37. }
  38. /**
  39. * write setting
  40. */
  41. settings() {
  42. const dir = '/etc/calamares/'
  43. const file = dir + 'settings.conf'
  44. write(file, this.getSettings(), this.verbose)
  45. }
  46. /**
  47. *
  48. */
  49. private getSettings(): string {
  50. // path di ricerca dei moduli
  51. const modulesSearch = ['local', '/usr/lib/calamares/modules']
  52. // moduli da mostrare a video
  53. const show = ['welcome', 'locale', 'keyboard', 'partition', 'users', 'summary']
  54. // moduli da eseguire
  55. let exec: string[] = []
  56. exec.push('partition')
  57. exec.push('mount')
  58. exec.push('unpackfs')
  59. exec.push('sources-trusted')
  60. //exec.push('machineid')
  61. exec.push('fstab')
  62. exec.push('locale')
  63. exec.push('keyboard')
  64. exec.push('localecfg')
  65. exec.push('users')
  66. if (this.displaymanager) {
  67. exec.push('displaymanager')
  68. }
  69. exec.push('networkcfg')
  70. exec.push('hwclock')
  71. exec.push('services-systemd')
  72. exec.push('create-tmp')
  73. exec.push('bootloader-config')
  74. exec.push('grubcfg')
  75. exec.push('bootloader')
  76. exec.push('luksbootkeyfile')
  77. exec.push('plymouthcfg')
  78. exec.push('initramfscfg')
  79. exec.push('initramfs')
  80. exec.push('removeuser')
  81. exec.push('sources-trusted-unmount')
  82. exec.push('sources-final')
  83. exec.push('umount')
  84. const settings = {
  85. 'modules-search': modulesSearch,
  86. sequence: [{ show: show }, { exec: exec }, { show: ['finished'] }],
  87. branding: this.remix.branding,
  88. 'prompt-install': false,
  89. 'dont-chroot': false
  90. }
  91. let title = `# calamares settings, id: ${this.distro.distroId}/${this.distro.versionId} like: ${this.distro.distroLike}/${this.distro.versionLike}\n`
  92. return title + yaml.safeDump(settings)
  93. }
  94. /**
  95. *
  96. */
  97. modules() {
  98. this.modulePartition()
  99. this.moduleMount()
  100. this.moduleUnpackfs()
  101. this.moduleSourcesTrusted()
  102. //this.moduleMachineid()
  103. this.moduleFstab()
  104. this.moduleLocale()
  105. this.moduleKeyboard()
  106. this.moduleLocalecfg()
  107. this.moduleUsers()
  108. if (this.displaymanager) {
  109. this.moduleDisplaymanager()
  110. }
  111. this.moduleNetworkcfg()
  112. this.moduleHwclock()
  113. this.moduleServicesSystemd()
  114. this.moduleCreateTmp()
  115. this.moduleBootloaderConfig()
  116. this.moduleGrubcfg()
  117. this.moduleBootloader()
  118. this.modulePackages()
  119. this.moduleLuksbootkeyfile()
  120. this.moduleLuksopenswaphookcfg()
  121. this.modulePlymouthcfg()
  122. this.moduleInitramfscfg()
  123. this.moduleInitramfs()
  124. this.moduleRemoveuser()
  125. this.moduleSourcesTrustedUnmount()
  126. this.moduleSourcesFinal()
  127. this.moduleUmount()
  128. }
  129. /**
  130. * ========================================================================
  131. * module = name + '.conf'
  132. * shellprocess = 'shellprocess_' + name + '.conf'
  133. * contextualprocess = name + '_context.conf'
  134. *
  135. * module_calamares
  136. * dir = '/usr/lib/calamares/modules/' + name
  137. * name = module.desc
  138. * script =
  139. * ========================================================================
  140. */
  141. /**
  142. * write module
  143. * @param name
  144. * @param content
  145. */
  146. private module(name: string, content: string) {
  147. const dir = `/etc/calamares/modules/`
  148. const file = dir + name + '.conf'
  149. write(file, content, this.verbose)
  150. }
  151. /**
  152. * write shellprocess
  153. * @param name
  154. */
  155. private shellprocess(name: string) {
  156. let content = ''
  157. const dir = `/etc/calamares/modules/`
  158. let file = dir + 'shellprocess_' + name + '.conf'
  159. write(file, content, this.verbose)
  160. }
  161. /**
  162. * write contextualprocess
  163. * @param process
  164. */
  165. private contextualprocess(name: string) {
  166. let content = ''
  167. const dir = `/etc/calamares/modules/`
  168. let file = dir + name + '_context' + '.conf'
  169. write(file, content, this.verbose)
  170. }
  171. /**
  172. * ====================================================================================
  173. * M O D U L E S
  174. * ====================================================================================
  175. */
  176. /**
  177. *
  178. */
  179. private modulePartition() {
  180. if (this.verbose) {
  181. console.log(`calamares: module partition. Nothing to do!`)
  182. }
  183. }
  184. /**
  185. *
  186. */
  187. private moduleMount() {
  188. const mount = yaml.safeDump({
  189. extraMounts: [
  190. {
  191. device: 'proc',
  192. fs: 'proc',
  193. mountPoint: '/proc'
  194. },
  195. {
  196. device: 'sys',
  197. fs: 'sysfs',
  198. mountPoint: '/sys'
  199. },
  200. {
  201. device: '/dev',
  202. mountPoint: '/dev',
  203. options: 'bind'
  204. },
  205. {
  206. device: '/dev/pts',
  207. fs: 'devpts',
  208. mountPoint: '/dev/pts'
  209. },
  210. {
  211. device: 'tmpfs',
  212. fs: 'tmpfs',
  213. mountPoint: '/run'
  214. },
  215. {
  216. device: '/run/udev',
  217. mountPoint: '/run/udev',
  218. options: 'bind'
  219. }
  220. ],
  221. extraMountsEfi: [
  222. {
  223. device: 'efivarfs',
  224. fs: 'tmpefivarfsfs',
  225. mountPoint: '/sys/firmware/efi/efivars'
  226. }
  227. ]
  228. })
  229. this.module('mount', mount)
  230. }
  231. /**
  232. *
  233. */
  234. private moduleUnpackfs() {
  235. const unpack = yaml.safeDump({
  236. unpack: [
  237. {
  238. source: this.distro.mountpointSquashFs,
  239. sourcefs: 'squashfs',
  240. destination: ''
  241. }
  242. ]
  243. })
  244. this.module('unpackfs', unpack)
  245. }
  246. /**
  247. *
  248. */
  249. private moduleMachineid() {
  250. const machineid = yaml.safeDump({
  251. systemd: true,
  252. dbus: true,
  253. symlink: true
  254. })
  255. this.module('machineid', machineid)
  256. }
  257. /**
  258. *
  259. */
  260. private moduleFstab() {
  261. const fstab = yaml.safeDump({
  262. mountOptions: {
  263. default: 'defaults,noatime',
  264. btrfs: 'defaults,noatime,space_cache,autodefrag'
  265. },
  266. ssdExtraMountOptions: {
  267. ext4: 'discard',
  268. jfs: 'discard',
  269. xfs: 'discard',
  270. swap: 'discard',
  271. btrfs: 'discard,compress=lzo'
  272. },
  273. crypttabOptions: 'luks,keyscript=/bin/cat'
  274. })
  275. this.module('fstab', fstab)
  276. }
  277. private moduleLocale() {
  278. if (this.verbose) console.log(`calamares: module locale. Nothing to do!`)
  279. }
  280. private moduleKeyboard() {
  281. if (this.verbose) console.log(`calamares: module keyboard. Nothing to do!`)
  282. }
  283. private moduleLocalecfg() {
  284. if (this.verbose) console.log(`calamares: module localecfg. Nothing to do!`)
  285. }
  286. /**
  287. *
  288. */
  289. private moduleUsers() {
  290. const users = yaml.safeDump({
  291. userGroup: 'users',
  292. defaultGroups: ['cdrom', 'floppy', 'sudo', 'audio', 'dip', 'video', 'plugdev', 'netdev', 'lpadmin', 'scanner', 'bluetooth'],
  293. autologinGroup: 'autologin',
  294. sudoersGroup: 'sudo',
  295. setRootPassword: false
  296. })
  297. this.module('users', users)
  298. }
  299. /**
  300. *
  301. */
  302. private moduleDisplaymanager() {
  303. const displaymanager = require('./modules/displaymanager').displaymanager
  304. this.module('displaymanager', displaymanager())
  305. }
  306. private moduleNetworkcfg() {
  307. if (this.verbose) console.log(`calamares: module networkcfg. Nothing to do!`)
  308. }
  309. private moduleHwclock() {
  310. if (this.verbose) console.log(`calamares: module hwclock. Nothing to do!`)
  311. }
  312. private moduleServicesSystemd() {
  313. if (this.verbose) console.log(`calamares: module servives-systemd. Nothing to do!`)
  314. }
  315. private moduleGrubcfg() {
  316. if (this.verbose) console.log(`calamares: module grubcfg. Nothing to do!`)
  317. }
  318. /**
  319. *
  320. */
  321. private moduleBootloader() {
  322. const bootloader = yaml.safeDump({
  323. efiBootLoader: 'grub',
  324. kernel: '/vmlinuz-linux',
  325. img: '/initramfs-linux.img',
  326. fallback: '/initramfs-linux-fallback.img',
  327. timeout: 10,
  328. grubInstall: 'grub-install',
  329. grubMkconfig: 'grub-mkconfig',
  330. grubCfg: '/boot/grub/grub.cfg',
  331. grubProbe: 'grub-probe',
  332. efiBootMgr: 'efibootmgr',
  333. installEFIFallback: false
  334. })
  335. this.module('bootloader', bootloader)
  336. }
  337. /**
  338. * create module packages.conf
  339. */
  340. private modulePackages() {
  341. const packages = require('./modules/packages').packages
  342. this.module('packages', packages())
  343. }
  344. /**
  345. *
  346. */
  347. private moduleLuksbootkeyfile() {
  348. if (this.verbose) console.log(`calamares: module luksbootkeyfile. Nothing to do!`)
  349. }
  350. /**
  351. *
  352. */
  353. private moduleLuksopenswaphookcfg() {
  354. const lksopenswaphookcfg = yaml.safeDump({
  355. configFilePath: '/etc/openswap.conf'
  356. })
  357. this.module('lksopenswaphookcfg', lksopenswaphookcfg)
  358. }
  359. private modulePlymouthcfg() {
  360. if (this.verbose) console.log(`calamares: module plymouthcfg. Nothing to do!`)
  361. }
  362. private moduleInitramfscfg() {
  363. if (this.verbose) console.log(`calamares: module initramfscfg. Nothing to do!`)
  364. }
  365. /**
  366. *
  367. */
  368. private moduleRemoveuser() {
  369. const removeuser = yaml.safeDump({ username: this.user_opt })
  370. this.module('removeuser', removeuser)
  371. }
  372. private moduleInitramfs() {
  373. if (this.verbose) console.log(`calamares: module initramfs. Nothing to do!`)
  374. }
  375. private moduleUmount() {
  376. if (this.verbose) console.log(`calamares: module unmount. Nothing to do!`)
  377. }
  378. /**
  379. * ====================================================================================
  380. * M O D U L E S C A L A M A R E S
  381. * ====================================================================================
  382. */
  383. /**
  384. *
  385. */
  386. private async moduleSourcesTrusted() {
  387. const name = 'sources-trusted'
  388. const dir = this.dirGlobalModules + name + `/`
  389. if (!fs.existsSync(dir)) {
  390. fs.mkdirSync(dir)
  391. }
  392. const descSourcesTrusted = require(`./calamares-modules/desc/${name}`).sourcesTrusted
  393. write(dir + 'module.desc', descSourcesTrusted(), this.verbose)
  394. const bashSourcesTrusted = require(`./calamares-modules/scripts/${name}`).sourcesTrusted
  395. const bashFile = `/usr/sbin/${name}`
  396. write(bashFile, bashSourcesTrusted(), this.verbose)
  397. await exec(`chmod +x ${bashFile}`)
  398. }
  399. /**
  400. *
  401. */
  402. private async moduleCreateTmp() {
  403. const name = 'create-tmp'
  404. const dir = this.dirGlobalModules + name + `/`
  405. if (!fs.existsSync(dir)) {
  406. fs.mkdirSync(dir)
  407. }
  408. const descCreateTmp = require(`./calamares-modules/desc/${name}`).createTmp
  409. write(dir + 'module.desc', descCreateTmp(), this.verbose)
  410. const bashCreateTmp = require(`./calamares-modules/scripts/${name}`).createTmp
  411. const scriptFile = `/usr/sbin/${name}`
  412. write(scriptFile, bashCreateTmp(), this.verbose)
  413. await exec(`chmod +x ${scriptFile}`)
  414. }
  415. /**
  416. *
  417. */
  418. private async moduleBootloaderConfig() {
  419. const name = 'bootloader-config'
  420. const dir = this.dirGlobalModules + name + `/`
  421. if (!fs.existsSync(dir)) {
  422. fs.mkdirSync(dir)
  423. }
  424. const descBootloaderConfig = require('./calamares-modules/desc/bootloader-config').bootloaderConfig
  425. write(dir + 'module.desc', descBootloaderConfig(), this.verbose)
  426. const bashBootloaderConfig = require(`./calamares-modules/scripts/${name}`).bootloaderConfig
  427. const scriptFile = `/usr/sbin/${name}`
  428. write(scriptFile, bashBootloaderConfig(), this.verbose)
  429. await exec(`chmod +x ${scriptFile}`)
  430. }
  431. /**
  432. *
  433. */
  434. private moduleSourcesTrustedUnmount() {
  435. const name = 'sources-trusted-unmount'
  436. const dir = this.dirGlobalModules + name + `/`
  437. if (!fs.existsSync(dir)) {
  438. fs.mkdirSync(dir)
  439. }
  440. const descSourcesTrustedUnmount = require(`./calamares-modules/desc/${name}`).sourcesTrustedUnmount
  441. write(dir + 'module.desc', descSourcesTrustedUnmount(), this.verbose)
  442. if (this.verbose) {
  443. console.log(`calamares: module ${name} use the same script of source-trusted`)
  444. }
  445. }
  446. /**
  447. *
  448. */
  449. private async moduleSourcesFinal() {
  450. const name = 'sources-final'
  451. const dir = this.dirGlobalModules + name + `/`
  452. if (!fs.existsSync(dir)) {
  453. fs.mkdirSync(dir)
  454. }
  455. const descSourcesFinal = require(`./calamares-modules/desc/${name}`).sourcesFinal
  456. write(dir + 'module.desc', descSourcesFinal(), this.verbose)
  457. const bashSourcesFinal = require(`./calamares-modules/scripts/${name}`).sourcesFinal
  458. const bashFile = `/usr/sbin/${name}`
  459. write(bashFile, bashSourcesFinal(), this.verbose)
  460. await exec(`chmod +x ${bashFile}`)
  461. }
  462. }
  463. /**
  464. *
  465. * @param file
  466. * @param content
  467. * @param verbose
  468. */
  469. function write(file: string, content: string, verbose = false) {
  470. if (verbose) {
  471. console.log(`calamares: create ${file}`)
  472. }
  473. fs.writeFileSync(file, content, 'utf8')
  474. }